Skip to content

Commit

Permalink
cuboidtag cleanup/opti
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 16, 2019
1 parent 1a7c741 commit b22bf7d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 89 deletions.
Expand Up @@ -508,12 +508,15 @@ public ListTag getBlocks(List<MaterialTag> materials, Attribute attribute) {
List<LocationTag> locs = getBlocks_internal(materials, attribute);
ListTag list = new ListTag();
for (LocationTag loc : locs) {
list.add(loc.identify());
list.addObject(loc);
}
return list;
}

public List<LocationTag> getBlocks_internal(List<MaterialTag> materials, Attribute attribute) {
if (materials == null && filter.isEmpty()) {
return getBlockLocationsUnfiltered();
}
int max = Settings.blockTagsMaxBlocks();
LocationTag loc;
List<LocationTag> list = new ArrayList<>();
Expand Down Expand Up @@ -557,56 +560,9 @@ public List<LocationTag> getBlocks_internal(List<MaterialTag> materials, Attribu
}

}

return list;
}

public void setBlocks_internal(List<BlockData> materials) {
LocationTag loc;
int index = 0;
for (LocationPair pair : pairs) {
LocationTag loc_1 = pair.low;
int y_distance = pair.y_distance;
int z_distance = pair.z_distance;
int x_distance = pair.x_distance;

for (int x = 0; x != x_distance + 1; x++) {
for (int y = 0; y != y_distance + 1; y++) {
for (int z = 0; z != z_distance + 1; z++) {
if (loc_1.getY() + y >= 0 && loc_1.getY() + y < 256) {
materials.get(index).setBlock(loc_1.clone().add(x, y, z).getBlock(), false);
}
index++;
}
}
}
}
}

public BlockData getBlockAt(double nX, double nY, double nZ, List<BlockData> materials) {
LocationTag loc;
int index = 0;
// TODO: calculate rather than cheat
for (LocationPair pair : pairs) {
LocationTag loc_1 = pair.low;
int y_distance = pair.y_distance;
int z_distance = pair.z_distance;
int x_distance = pair.x_distance;

for (int x = 0; x != x_distance + 1; x++) {
for (int y = 0; y != y_distance + 1; y++) {
for (int z = 0; z != z_distance + 1; z++) {
if (x == nX && nY == y && z == nZ) {
return materials.get(index);
}
index++;
}
}
}
}
return null;
}

public List<LocationTag> getBlockLocationsUnfiltered() {
int max = Settings.blockTagsMaxBlocks();
LocationTag loc;
Expand All @@ -618,9 +574,9 @@ public List<LocationTag> getBlockLocationsUnfiltered() {
int y_distance = pair.y_distance;
int z_distance = pair.z_distance;
int x_distance = pair.x_distance;
for (int x = 0; x != x_distance + 1; x++) {
for (int z = 0; z != z_distance + 1; z++) {
for (int y = 0; y != y_distance + 1; y++) {
for (int x = 0; x <= x_distance; x++) {
for (int z = 0; z <= z_distance; z++) {
for (int y = 0; y <= y_distance; y++) {
loc = new LocationTag(loc_1.clone().add(x, y, z));
list.add(loc);
index++;
Expand All @@ -634,43 +590,6 @@ public List<LocationTag> getBlockLocationsUnfiltered() {
return list;
}

public List<LocationTag> getBlockLocations(Attribute attribute) {
int max = Settings.blockTagsMaxBlocks();
LocationTag loc;
List<LocationTag> list = new ArrayList<>();
int index = 0;

for (LocationPair pair : pairs) {
LocationTag loc_1 = pair.low;
int y_distance = pair.y_distance;
int z_distance = pair.z_distance;
int x_distance = pair.x_distance;
for (int x = 0; x != x_distance + 1; x++) {
for (int z = 0; z != z_distance + 1; z++) {
for (int y = 0; y != y_distance + 1; y++) {
loc = new LocationTag(loc_1.clone().add(x, y, z));
if (!filter.isEmpty()) {
// Check filter
for (ObjectTag material : filter) {
if (loc.getBlockTypeForTag(attribute).name().equalsIgnoreCase(((MaterialTag) material).getMaterial().name())) {
list.add(loc);
}
}
}
else {
list.add(loc);
}
index++;
if (index > max) {
return list;
}
}
}
}
}
return list;
}


public ListTag getSpawnableBlocks(Attribute attribute) {
return getSpawnableBlocks(null, attribute);
Expand Down
Expand Up @@ -143,7 +143,7 @@ public ListTag getBlocks(List<MaterialTag> materials, Attribute attribute) {
ListTag list = new ListTag();
for (LocationTag loc : initial) {
if (contains(loc)) {
list.add(loc.identify());
list.addObject(loc);
}
}
return list;
Expand Down

0 comments on commit b22bf7d

Please sign in to comment.