capped tree detection search depth

This commit is contained in:
Frederik Palmø 2021-10-08 14:47:59 +02:00
parent cf2671380b
commit 4c269e6938

View file

@ -12,11 +12,14 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World; import net.minecraft.world.World;
public class Util { public class Util {
public static final int MAX_SEARCH_DEPTH = 100;
public static boolean isTreeNaturallyGrown(World world, BlockPos pos) { public static boolean isTreeNaturallyGrown(World world, BlockPos pos) {
LinkedList<BlockPos> queue = new LinkedList<BlockPos>(); LinkedList<BlockPos> queue = new LinkedList<BlockPos>();
queue.push(pos.up()); queue.push(pos.up());
int search_depth = 0;
while (!queue.isEmpty()) { while (!queue.isEmpty() && search_depth >= MAX_SEARCH_DEPTH) {
BlockPos nextPos = queue.pop(); BlockPos nextPos = queue.pop();
BlockPos[] dirs = { nextPos.north(), nextPos.east(), nextPos.south(), nextPos.west(), nextPos.up() }; BlockPos[] dirs = { nextPos.north(), nextPos.east(), nextPos.south(), nextPos.west(), nextPos.up() };
@ -30,6 +33,8 @@ public class Util {
queue.push(dir); queue.push(dir);
} }
} }
search_depth++;
} }
return false; return false;