From 4c269e6938e85da65c8e6a5a7ac4bbb2a912e466 Mon Sep 17 00:00:00 2001 From: vodofrede Date: Fri, 8 Oct 2021 14:47:59 +0200 Subject: [PATCH] capped tree detection search depth --- src/main/java/dk/palmoe/immersivexp/Util.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/dk/palmoe/immersivexp/Util.java b/src/main/java/dk/palmoe/immersivexp/Util.java index 3ed0ddb..0eff101 100644 --- a/src/main/java/dk/palmoe/immersivexp/Util.java +++ b/src/main/java/dk/palmoe/immersivexp/Util.java @@ -12,11 +12,14 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; public class Util { + public static final int MAX_SEARCH_DEPTH = 100; + public static boolean isTreeNaturallyGrown(World world, BlockPos pos) { LinkedList queue = new LinkedList(); queue.push(pos.up()); + int search_depth = 0; - while (!queue.isEmpty()) { + while (!queue.isEmpty() && search_depth >= MAX_SEARCH_DEPTH) { BlockPos nextPos = queue.pop(); BlockPos[] dirs = { nextPos.north(), nextPos.east(), nextPos.south(), nextPos.west(), nextPos.up() }; @@ -30,6 +33,8 @@ public class Util { queue.push(dir); } } + + search_depth++; } return false;