This commit is contained in:
Leijurv 2019-01-11 10:02:21 -08:00
parent 56d109bf0a
commit 14bc65468a
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
1 changed files with 5 additions and 4 deletions

View File

@ -17,12 +17,13 @@
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;
import java.util.OptionalInt;
import java.util.function.Predicate;
public class MapArtSchematic extends Schematic { public class MapArtSchematic extends Schematic {
private final int[][] heightMap; private final int[][] heightMap;
@ -34,7 +35,7 @@ public class MapArtSchematic extends Schematic {
for (int z = 0; z < lengthZ; z++) { for (int z = 0; z < lengthZ; z++) {
IBlockState[] column = states[x][z]; IBlockState[] column = states[x][z];
OptionalInt lowestBlockY = getLowest(column, block -> block != Blocks.AIR); OptionalInt lowestBlockY = lastIndexMatching(column, block -> block != Blocks.AIR);
if (lowestBlockY.isPresent()) { if (lowestBlockY.isPresent()) {
heightMap[x][z] = lowestBlockY.getAsInt(); heightMap[x][z] = lowestBlockY.getAsInt();
} else { } else {
@ -47,7 +48,7 @@ public class MapArtSchematic extends Schematic {
} }
} }
private static <T> OptionalInt getLowest(T[] arr, Predicate<T> predicate) { private static <T> OptionalInt lastIndexMatching(T[] arr, Predicate<T> predicate) {
for (int y = arr.length - 1; y >= 0; y--) { for (int y = arr.length - 1; y >= 0; y--) {
if (predicate.test(arr[y])) { if (predicate.test(arr[y])) {
return OptionalInt.of(y); return OptionalInt.of(y);