Merge branch 'lumber-axe-fix' into dev

This commit is contained in:
Martin Robertz committed 2025-11-08 13:59:19 +01:00
commit f272be56bd
1 file changed
+26 -19
@@ -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 class LumberAxe extends AOEHarvestTool {
public static boolean detectTree(World world, int pX, int pY, int pZ) {
Stack<ChunkPosition> candidates = new Stack<>();
SortedSet<ChunkPosition> visited = new TreeSet<>(Comparator.comparingInt((ChunkPosition a) -> a.chunkPosY));
Set<ChunkPosition> wood = new HashSet<>();
Set<ChunkPosition> nonWood = new HashSet<>();
candidates.add(new ChunkPosition(pX, pY, pZ));
while (!candidates.isEmpty()) {
ChunkPosition candidate = candidates.pop();
if (wood.contains(candidate) || nonWood.contains(candidate)) {
continue;
}
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)) {
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);
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