From a965859095b71f312a051146e745c428bf53477a Mon Sep 17 00:00:00 2001 From: babbaj Date: Fri, 11 Jan 2019 01:13:14 -0500 Subject: [PATCH] make code easy to understand --- .../java/baritone/utils/MapArtSchematic.java | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/main/java/baritone/utils/MapArtSchematic.java b/src/main/java/baritone/utils/MapArtSchematic.java index 9813b6373..5ff16f3f0 100644 --- a/src/main/java/baritone/utils/MapArtSchematic.java +++ b/src/main/java/baritone/utils/MapArtSchematic.java @@ -17,6 +17,8 @@ package baritone.utils; +import java.util.OptionalInt; +import java.util.function.Predicate; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.nbt.NBTTagCompound; @@ -27,23 +29,33 @@ public class MapArtSchematic extends Schematic { public MapArtSchematic(NBTTagCompound schematic) { super(schematic); heightMap = new int[widthX][lengthZ]; + for (int x = 0; x < widthX; x++) { - https: for (int z = 0; z < lengthZ; z++) { IBlockState[] column = states[x][z]; - for (int y = heightY - 1; y >= 0; y--) { - if (column[y].getBlock() != Blocks.AIR) { - heightMap[x][z] = y; - continue https; - } + + OptionalInt lowestBlockY = getLowest(column, block -> block != Blocks.AIR); + if (lowestBlockY.isPresent()) { + 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("Letting it be whatever"); + heightMap[x][z] = 256; } - System.out.println("Column " + x + "," + z + " has no blocks, but it's apparently map art? wtf"); - System.out.println("Letting it be whatever"); - heightMap[x][z] = 256; + } } } + private static OptionalInt getLowest(T[] arr, Predicate predicate) { + for (int y = arr.length - 1; y >= 0; y--) { + if (predicate.test(arr[y])) { + return OptionalInt.of(y); + } + } + return OptionalInt.empty(); + } + @Override public boolean inSchematic(int x, int y, int z) { // in map art, we only care about coordinates in or above the art