From 45e4b9599f5c2a2650fb03a2bc1f66947bb5d67b Mon Sep 17 00:00:00 2001 From: layue13 Date: Mon, 16 Nov 2026 00:39:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=90=9C=E7=B4=A2=E4=B8=8D=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E5=8C=BA=E5=9D=97=EF=BC=9B=E8=83=8C=E5=8C=85=E5=B5=8C?= =?UTF-8?q?=E5=A5=97=E6=B7=B1=E5=BA=A6=E6=9C=89=E7=95=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #2 #3 Co-authored-by: Cursor --- patches/.gitkeep | 0 ...-load-chunks-bound-nested-inventory-.patch | 125 ++++++++++++++++++ 2 files changed, 125 insertions(+) delete mode 100644 patches/.gitkeep create mode 100644 patches/0002-fix-do-not-force-load-chunks-bound-nested-inventory-.patch diff --git a/patches/.gitkeep b/patches/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/patches/0002-fix-do-not-force-load-chunks-bound-nested-inventory-.patch b/patches/0002-fix-do-not-force-load-chunks-bound-nested-inventory-.patch new file mode 100644 index 0000000..8cf6532 --- /dev/null +++ b/patches/0002-fix-do-not-force-load-chunks-bound-nested-inventory-.patch @@ -0,0 +1,125 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Stratum +Date: Mon, 16 Nov 2026 00:39:58 +0800 +Subject: [PATCH] fix: do not force-load chunks; bound nested inventory search + +Search is QoL: skip missing chunks, hard-cap radius at 64, and limit backpack nesting depth. + +Co-authored-by: Cursor +--- + .../java/com/gtnh/findit/FindItConfig.java | 7 +++-- + .../service/itemfinder/FindItemRequest.java | 29 +++++++++++++++---- + .../java/com/gtnh/findit/util/WorldUtils.java | 16 +++++++++- + 3 files changed, 43 insertions(+), 9 deletions(-) + +diff --git a/src/main/java/com/gtnh/findit/FindItConfig.java b/src/main/java/com/gtnh/findit/FindItConfig.java +index 9527ab7..a9bb107 100644 +--- a/src/main/java/com/gtnh/findit/FindItConfig.java ++++ b/src/main/java/com/gtnh/findit/FindItConfig.java +@@ -5,12 +5,15 @@ import com.gtnewhorizon.gtnhlib.config.Config; + @Config(modid = "findit") + public class FindItConfig { + +- @Config.Comment("Radius to search within") ++ @Config.Comment("Radius to search within. Hard-capped so search cannot force-load distant chunks.") + @Config.DefaultInt(16) +- @Config.RangeInt(min = 1) ++ @Config.RangeInt(min = 1, max = 64) + @Config.Name("SearchRadius") + public static int SEARCH_RADIUS; + ++ /** Absolute ceiling even if the config file is hand-edited past {@link #SEARCH_RADIUS}'s RangeInt. */ ++ public static final int SEARCH_RADIUS_HARD_MAX = 64; ++ + @Config.Comment("Search cooldown in ticks") + @Config.DefaultInt(10) + @Config.RangeInt(min = 0) +diff --git a/src/main/java/com/gtnh/findit/service/itemfinder/FindItemRequest.java b/src/main/java/com/gtnh/findit/service/itemfinder/FindItemRequest.java +index 882c826..c3d25dc 100644 +--- a/src/main/java/com/gtnh/findit/service/itemfinder/FindItemRequest.java ++++ b/src/main/java/com/gtnh/findit/service/itemfinder/FindItemRequest.java +@@ -23,6 +23,10 @@ import io.netty.buffer.ByteBuf; + + public class FindItemRequest implements IMessage { + ++ /** Nested backpack / cover inventories: bound depth so a cycle cannot StackOverflow. */ ++ private static final int MAX_NESTED_INVENTORY_DEPTH = 8; ++ private static final ThreadLocal NEST_DEPTH = new ThreadLocal<>(); ++ + private ItemStack targetStack; + private FluidStack targetFluidStack; + private boolean highlightingEmptyItemStacks; +@@ -75,14 +79,27 @@ public class FindItemRequest implements IMessage { + public boolean isStackSatisfies(EntityPlayer player, ItemStack stack) { + if (stack == null || !this.highlightingEmptyItemStacks && stack.stackSize == 0) return false; + +- for (IStackFilterProvider provider : FindIt.INSTANCE.pluginsList) { +- IStackFilter filter = provider.getFilter(player, stack); +- if (filter != null && filter.matches(this)) { +- return true; ++ Integer depthBox = NEST_DEPTH.get(); ++ int depth = depthBox == null ? 0 : depthBox; ++ if (depth >= MAX_NESTED_INVENTORY_DEPTH) { ++ return false; ++ } ++ NEST_DEPTH.set(depth + 1); ++ try { ++ for (IStackFilterProvider provider : FindIt.INSTANCE.pluginsList) { ++ IStackFilter filter = provider.getFilter(player, stack); ++ if (filter != null && filter.matches(this)) { ++ return true; ++ } ++ } ++ return false; ++ } finally { ++ if (depth == 0) { ++ NEST_DEPTH.remove(); ++ } else { ++ NEST_DEPTH.set(depth); + } + } +- +- return false; + } + + public boolean isTileSatisfies(EntityPlayer player, TileEntity tileEntity) { +diff --git a/src/main/java/com/gtnh/findit/util/WorldUtils.java b/src/main/java/com/gtnh/findit/util/WorldUtils.java +index 0be8bd8..c48f905 100644 +--- a/src/main/java/com/gtnh/findit/util/WorldUtils.java ++++ b/src/main/java/com/gtnh/findit/util/WorldUtils.java +@@ -10,13 +10,23 @@ import net.minecraft.world.ChunkPosition; + import net.minecraft.world.World; + import net.minecraft.world.chunk.Chunk; + ++import com.gtnh.findit.FindItConfig; ++ + public class WorldUtils { + + public static List getTileEntitiesAround(Entity entity, int r) { ++ int radius = Math.min(Math.max(r, 1), FindItConfig.SEARCH_RADIUS_HARD_MAX); + int x = (int) Math.floor(entity.posX); + int y = (int) entity.posY; + int z = (int) Math.floor(entity.posZ); +- return getTileEntitiesInRegion(entity.worldObj, x - r, y - r, z - r, x + r + 1, y + r + 1, z + r + 1); ++ return getTileEntitiesInRegion( ++ entity.worldObj, ++ x - radius, ++ y - radius, ++ z - radius, ++ x + radius + 1, ++ y + radius + 1, ++ z + radius + 1); + } + + /** +@@ -31,6 +41,10 @@ public class WorldUtils { + + for (int cx = x1 >> 4; cx <= cx1; cx++) { + for (int cz = z1 >> 4; cz <= cz1; cz++) { ++ // QoL search must not provideChunk / force-load. ++ if (!world.getChunkProvider().chunkExists(cx, cz)) { ++ continue; ++ } + Chunk chunk = world.getChunkFromChunkCoords(cx, cz); + if (chunk != null) { + @SuppressWarnings("unchecked")