diff --git a/src/main/java/tconstruct/items/tools/LumberAxe.java b/src/main/java/tconstruct/items/tools/LumberAxe.java index e3e2a194cdd..74e77dc8391 100644 --- a/src/main/java/tconstruct/items/tools/LumberAxe.java +++ b/src/main/java/tconstruct/items/tools/LumberAxe.java @@ -1,11 +1,11 @@ package tconstruct.items.tools; +import java.util.Collections; import java.util.Comparator; +import java.util.HashSet; import java.util.Queue; import java.util.Set; -import java.util.SortedSet; import java.util.Stack; -import java.util.TreeSet; import net.minecraft.block.Block; import net.minecraft.block.material.Material; @@ -118,41 +118,48 @@ public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPla public static boolean detectTree(World world, int pX, int pY, int pZ) { Stack candidates = new Stack<>(); - SortedSet visited = new TreeSet<>(Comparator.comparingInt((ChunkPosition a) -> a.chunkPosY)); + Set wood = new HashSet<>(); + Set nonWood = new HashSet<>(); candidates.add(new ChunkPosition(pX, pY, pZ)); while (!candidates.isEmpty()) { ChunkPosition candidate = candidates.pop(); - int curX = candidate.chunkPosX, curY = candidate.chunkPosY, curZ = candidate.chunkPosZ; - Block block = world.getBlock(curX, curY, curZ); - if (!block.isWood(world, curX, curY, curZ)) { - continue; - } - if (!visited.add(candidate)) { + if (wood.contains(candidate) || nonWood.contains(candidate)) { continue; } - // add the current layer and above - for (int offX = 0; offX < 3; offX++) { - for (int offY = 0; offY < 2; offY++) { - for (int offZ = 0; offZ < 3; offZ++) { - ChunkPosition newCandidate = new ChunkPosition(curX - 1 + offX, curY + offY, curZ - 1 + offZ); - if (!visited.contains(newCandidate)) { - candidates.add(newCandidate); + int curX = candidate.chunkPosX, curY = candidate.chunkPosY, curZ = candidate.chunkPosZ; + + Block block = world.getBlock(curX, curY, curZ); + if (block.isWood(world, curX, curY, curZ)) { + for (int offX = 0; offX < 3; offX++) { + for (int offY = 0; offY < 2; offY++) { + for (int offZ = 0; offZ < 3; offZ++) { + ChunkPosition newCandidate = new ChunkPosition( + curX - 1 + offX, + curY + offY, + curZ - 1 + offZ); + if (!(wood.contains(newCandidate) || nonWood.contains(newCandidate))) { + candidates.add(newCandidate); + } } } } + wood.add(candidate); + } else { + nonWood.add(candidate); } + } // not even one match, so there were no logs. - if (visited.isEmpty()) { + if (wood.isEmpty()) { return false; } - ChunkPosition topmost = visited.last(); + ChunkPosition topmost = Collections.max(wood, Comparator.comparingInt((ChunkPosition a) -> a.chunkPosY)); // check if there were enough leaves around the last position // pos now contains the block above the topmost log