Merge pull request #310 from babbaj/builder

make code easy to understand
This commit is contained in:
Leijurv 2019-01-11 10:00:43 -08:00
commit 56d109bf0a
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
1 changed files with 21 additions and 9 deletions

View File

@ -17,6 +17,8 @@
package baritone.utils; package baritone.utils;
import java.util.OptionalInt;
import java.util.function.Predicate;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -27,22 +29,32 @@ public class MapArtSchematic extends Schematic {
public MapArtSchematic(NBTTagCompound schematic) { public MapArtSchematic(NBTTagCompound schematic) {
super(schematic); super(schematic);
heightMap = new int[widthX][lengthZ]; heightMap = new int[widthX][lengthZ];
for (int x = 0; x < widthX; x++) { for (int x = 0; x < widthX; x++) {
https:
for (int z = 0; z < lengthZ; z++) { for (int z = 0; z < lengthZ; z++) {
IBlockState[] column = states[x][z]; IBlockState[] column = states[x][z];
for (int y = heightY - 1; y >= 0; y--) {
if (column[y].getBlock() != Blocks.AIR) { OptionalInt lowestBlockY = getLowest(column, block -> block != Blocks.AIR);
heightMap[x][z] = y; if (lowestBlockY.isPresent()) {
continue https; heightMap[x][z] = lowestBlockY.getAsInt();
} } else {
}
System.out.println("Column " + x + "," + z + " has no blocks, but it's apparently map art? wtf"); System.out.println("Column " + x + "," + z + " has no blocks, but it's apparently map art? wtf");
System.out.println("Letting it be whatever"); System.out.println("Letting it be whatever");
heightMap[x][z] = 256; heightMap[x][z] = 256;
} }
} }
} }
}
private static <T> OptionalInt getLowest(T[] arr, Predicate<T> predicate) {
for (int y = arr.length - 1; y >= 0; y--) {
if (predicate.test(arr[y])) {
return OptionalInt.of(y);
}
}
return OptionalInt.empty();
}
@Override @Override
public boolean inSchematic(int x, int y, int z) { public boolean inSchematic(int x, int y, int z) {