From 3aaff1911ba384ed85d1e9457dfb5fbcd4889a3c Mon Sep 17 00:00:00 2001 From: nossr50 Date: Sun, 3 Nov 2024 17:10:49 -0800 Subject: [PATCH] huge optimizations --- Changelog.txt | 8 +++++++- .../util/blockmeta/HashChunkManager.java | 20 ++++++------------- .../util/blockmeta/NullChunkManager.java | 4 ++-- .../util/blockmeta/UserBlockTrackerTest.java | 1 - 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index cce8d7766..7c2633564 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,6 +1,12 @@ Version 2.2.024 Fixed a bug where Giga Drill breaker was giving out more drop chance than intended - Large optimizations to most block interactions in mcMMO code + Significant optimizations made to reading new chunks for mcMMO + Significant optimizations to most block interactions in mcMMO code + + Notes: + Got a bit carried away and started to optimize stuff. + I was able to make Tree Feller way faster with optimizations in this update, I tested with a custom gigantic tree that had over 200,000 blocks felled (huge) and it only took 4 seconds total, in the previous version of mcMMO this would take over 2-3 minutes. + Version 2.2.023 Compatibility with Minecraft 1.21.3 diff --git a/src/main/java/com/gmail/nossr50/util/blockmeta/HashChunkManager.java b/src/main/java/com/gmail/nossr50/util/blockmeta/HashChunkManager.java index 203c71e71..aa5d9da2f 100644 --- a/src/main/java/com/gmail/nossr50/util/blockmeta/HashChunkManager.java +++ b/src/main/java/com/gmail/nossr50/util/blockmeta/HashChunkManager.java @@ -159,17 +159,16 @@ public class HashChunkManager implements ChunkManager { ChunkStore check = chunkMap.computeIfAbsent(chunkKey, k -> { // Load from file ChunkStore loaded = loadChunk(chunkKey.x, chunkKey.z, world); - if (loaded == null) - return null; + if (loaded != null) { + chunkUsageMap.computeIfAbsent(toRegionKey(chunkKey.worldID, chunkKey.x, chunkKey.z), j -> new HashSet<>()).add(chunkKey); + return loaded; + } // Mark chunk in-use for region tracking chunkUsageMap.computeIfAbsent(toRegionKey(chunkKey.worldID, chunkKey.x, chunkKey.z), j -> new HashSet<>()).add(chunkKey); - return loaded; + // Create a new chunkstore + return new BitSetChunkStore(world, chunkKey.x, chunkKey.z); }); - // No chunk, return false - if (check == null) - return false; - int ix = Math.abs(x) % 16; int iz = Math.abs(z) % 16; @@ -227,19 +226,12 @@ public class HashChunkManager implements ChunkManager { chunkUsageMap.computeIfAbsent(toRegionKey(chunkKey.worldID, chunkKey.x, chunkKey.z), j -> new HashSet<>()).add(chunkKey); return loaded; } - // If setting to false, no need to create an empty chunkstore - if (!value) - return null; // Mark chunk in-use for region tracking chunkUsageMap.computeIfAbsent(toRegionKey(chunkKey.worldID, chunkKey.x, chunkKey.z), j -> new HashSet<>()).add(chunkKey); // Create a new chunkstore return new BitSetChunkStore(world, chunkKey.x, chunkKey.z); }); - // Indicates setting false on empty chunkstore - if (cStore == null) - return; - // Get block offset (offset from chunk corner) int ix = Math.abs(x) % 16; int iz = Math.abs(z) % 16; diff --git a/src/main/java/com/gmail/nossr50/util/blockmeta/NullChunkManager.java b/src/main/java/com/gmail/nossr50/util/blockmeta/NullChunkManager.java index bc700b6e4..f972b934a 100644 --- a/src/main/java/com/gmail/nossr50/util/blockmeta/NullChunkManager.java +++ b/src/main/java/com/gmail/nossr50/util/blockmeta/NullChunkManager.java @@ -28,12 +28,12 @@ public class NullChunkManager implements ChunkManager { @Override public boolean isEligible(@NotNull Block block) { - return false; + return true; } @Override public boolean isEligible(@NotNull BlockState blockState) { - return false; + return true; } @Override diff --git a/src/test/java/com/gmail/nossr50/util/blockmeta/UserBlockTrackerTest.java b/src/test/java/com/gmail/nossr50/util/blockmeta/UserBlockTrackerTest.java index 89a2f63ff..5bdf5e485 100644 --- a/src/test/java/com/gmail/nossr50/util/blockmeta/UserBlockTrackerTest.java +++ b/src/test/java/com/gmail/nossr50/util/blockmeta/UserBlockTrackerTest.java @@ -75,7 +75,6 @@ class UserBlockTrackerTest { // Top Block final Block illegalHeightBlock = initMockBlock(1337, 256, -1337); - assertFalse(hashChunkManager.isIneligible(illegalHeightBlock)); Assertions.assertThrows(IndexOutOfBoundsException.class, () -> hashChunkManager.setIneligible(illegalHeightBlock)); }