diff --git a/gradle.properties b/gradle.properties index 5f249ec..fa750af 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,5 @@ # Fabric Properties +org.gradle.java.installations.paths=E:/Coding/Minecraft/tools/jdk-25.0.3+9 # check these on https://fabricmc.net/develop minecraft_version=26.2 loader_version=0.19.2 diff --git a/src/main/java/com/tick_ins/tick/TickThread.java b/src/main/java/com/tick_ins/tick/TickThread.java index 445aa1e..b0a68ac 100644 --- a/src/main/java/com/tick_ins/tick/TickThread.java +++ b/src/main/java/com/tick_ins/tick/TickThread.java @@ -36,8 +36,11 @@ public static void addTask(RunnableWithLast first, RunnableWithLast second) { runAfterTick(() -> { if (second != null) { runNow(() -> { - second.task().run(); - clearLookLock(); + try { + second.task().run(); + } finally { + clearLookLock(); + } }); } else { runNow(TickThread::clearLookLock); @@ -55,8 +58,11 @@ public static void addLastTask(RunnableWithLast task) { runNow(task.task()); runAfterTick(() -> { runNow(() -> { - task.cache().run(); - clearLookLock(); + try { + task.cache().run(); + } finally { + clearLookLock(); + } }); }, 1); } @@ -116,7 +122,6 @@ public static void clearLookLock() { public static void onClientDisconnected() { TASK_EPOCH.incrementAndGet(); clearLookLock(); - clientStopping = false; } public static void onClientShutdown() { diff --git a/src/main/java/org/uiop/easyplacefix/until/PlayerBlockAction.java b/src/main/java/org/uiop/easyplacefix/until/PlayerBlockAction.java index 2a6165a..9c1476d 100644 --- a/src/main/java/org/uiop/easyplacefix/until/PlayerBlockAction.java +++ b/src/main/java/org/uiop/easyplacefix/until/PlayerBlockAction.java @@ -41,6 +41,7 @@ public static class useItemOnAction { public static BlockState pistonBlockState = null; // Global placement rate limiter (anti-cheat protection) private static volatile long lastGlobalPlacementTime = 0; + private static volatile long lastPruneTime = 0; private static final long PLACEMENT_OVERRIDE_TTL_MS = 1200L; private static final int PLACEMENT_OVERRIDE_MAX_SIZE = 512; private static final int PLACEMENT_OVERRIDE_USES = 4; @@ -191,8 +192,9 @@ public static boolean isPlacementCooling(BlockPos pos) { long now = System.currentTimeMillis(); long threshold = Ping2Server.getRtt() + 100; - // Prune stale entries to prevent memory leak (entries older than 10 seconds) - if (lastPlacementTimeMap.size() > 256) { + // Prune stale entries periodically to prevent memory leak and CPU bottleneck + if (now - lastPruneTime > 5000L) { + lastPruneTime = now; lastPlacementTimeMap.entrySet().removeIf(e -> now - e.getValue() > 10_000L); } diff --git a/src/main/java/org/uiop/easyplacefix/until/doEasyPlace.java b/src/main/java/org/uiop/easyplacefix/until/doEasyPlace.java index f86b250..7978c91 100644 --- a/src/main/java/org/uiop/easyplacefix/until/doEasyPlace.java +++ b/src/main/java/org/uiop/easyplacefix/until/doEasyPlace.java @@ -106,8 +106,7 @@ else if (ReplacedBlock instanceof CoralFanBlock)//coral fans stack1 = findBlockInInventory(playerInventory, predicate); } if (stack1 == null) { - HashSet itemStackHashSet = LoosenModeData.loadFromFile(); - return loosenMode2(itemStackHashSet); + return loosenMode2(null); } return stack1;