From 9808428087a2c2d90859adc201429308d0a0bec2 Mon Sep 17 00:00:00 2001 From: boubou19 Date: Sun, 30 Aug 2026 20:57:26 +0200 Subject: [PATCH 1/2] Avoid chunk key allocations --- .../guide/scene/level/GuidebookLevel.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/hfstudio/guidenh/guide/scene/level/GuidebookLevel.java b/src/main/java/com/hfstudio/guidenh/guide/scene/level/GuidebookLevel.java index 0133052e..a638f353 100644 --- a/src/main/java/com/hfstudio/guidenh/guide/scene/level/GuidebookLevel.java +++ b/src/main/java/com/hfstudio/guidenh/guide/scene/level/GuidebookLevel.java @@ -36,10 +36,11 @@ import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap; public class GuidebookLevel implements IBlockAccess, GuidebookChunkSource { - private final LinkedHashMap chunks = new LinkedHashMap<>(); + private final Long2ObjectLinkedOpenHashMap chunks = new Long2ObjectLinkedOpenHashMap<>(); private final HashMap tileEntities = new HashMap<>(); private final LinkedHashMap entities = new LinkedHashMap<>(); @@ -142,12 +143,12 @@ public void setBlock(int x, int y, int z, @Nullable Block block, int meta, @Null if (y < 0 || y >= 256) return; boolean isAir = block == null || block == Blocks.air; - var pair = new ChunkCoordIntPair(x >> 4, z >> 4); - GuidebookChunk chunk = chunks.get(pair); + long chunkKey = ChunkCoordIntPair.chunkXZ2Int(x >> 4, z >> 4); + GuidebookChunk chunk = chunks.get(chunkKey); if (chunk == null) { if (isAir) return; chunk = new GuidebookChunk(x >> 4, z >> 4); - chunks.put(pair, chunk); + chunks.put(chunkKey, chunk); } chunk.setBlock(x, y, z, isAir ? null : block, meta); @@ -199,14 +200,14 @@ public void restoreBlockFast(int x, int y, int z, @Nullable Block block, int met } boolean isAir = block == null || block == Blocks.air; - ChunkCoordIntPair pair = new ChunkCoordIntPair(x >> 4, z >> 4); - GuidebookChunk chunk = chunks.get(pair); + long chunkKey = ChunkCoordIntPair.chunkXZ2Int(x >> 4, z >> 4); + GuidebookChunk chunk = chunks.get(chunkKey); if (chunk == null) { if (isAir) { return; } chunk = new GuidebookChunk(x >> 4, z >> 4); - chunks.put(pair, chunk); + chunks.put(chunkKey, chunk); } chunk.setBlock(x, y, z, isAir ? null : block, meta); @@ -703,11 +704,11 @@ public GuidebookLevel withSampleChest() { @Override @Nullable public GuidebookChunk getChunk(int chunkX, int chunkZ, boolean create) { - var pair = new ChunkCoordIntPair(chunkX, chunkZ); - var chunk = chunks.get(pair); + long chunkKey = ChunkCoordIntPair.chunkXZ2Int(chunkX, chunkZ); + var chunk = chunks.get(chunkKey); if (chunk == null && create) { chunk = new GuidebookChunk(chunkX, chunkZ); - chunks.put(pair, chunk); + chunks.put(chunkKey, chunk); } return chunk; } From daaffe25719816748af0649c01777f0d72ded2e5 Mon Sep 17 00:00:00 2001 From: boubou19 Date: Sun, 30 Aug 2026 22:38:11 +0200 Subject: [PATCH 2/2] Avoid tile entity key allocations --- .../com/hfstudio/guidenh/guide/scene/level/GuidebookLevel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/hfstudio/guidenh/guide/scene/level/GuidebookLevel.java b/src/main/java/com/hfstudio/guidenh/guide/scene/level/GuidebookLevel.java index a638f353..5eb2f887 100644 --- a/src/main/java/com/hfstudio/guidenh/guide/scene/level/GuidebookLevel.java +++ b/src/main/java/com/hfstudio/guidenh/guide/scene/level/GuidebookLevel.java @@ -42,7 +42,7 @@ public class GuidebookLevel implements IBlockAccess, GuidebookChunkSource { private final Long2ObjectLinkedOpenHashMap chunks = new Long2ObjectLinkedOpenHashMap<>(); - private final HashMap tileEntities = new HashMap<>(); + private final Long2ObjectLinkedOpenHashMap tileEntities = new Long2ObjectLinkedOpenHashMap<>(); private final LinkedHashMap entities = new LinkedHashMap<>(); private final LinkedHashMap> sceneEntityIds = new LinkedHashMap<>(); private final HashMap entitySceneIds = new HashMap<>();