From 4a1ae7919d072d45c08604bba2b799ae25c56a42 Mon Sep 17 00:00:00 2001 From: Reider745 <70357814+Reider745@users.noreply.github.com> Date: Sun, 8 Feb 2026 07:07:34 +0300 Subject: [PATCH] feat: optimization search legacy id for runtime id --- .../java/com/reider745/hooks/block/BlockPalette.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/reider745/hooks/block/BlockPalette.java b/src/main/java/com/reider745/hooks/block/BlockPalette.java index e3badc20..3725c30d 100644 --- a/src/main/java/com/reider745/hooks/block/BlockPalette.java +++ b/src/main/java/com/reider745/hooks/block/BlockPalette.java @@ -42,7 +42,7 @@ public class BlockPalette { private static final int VERSION_STATE = 18168865; private static final MainLogger logger = Server.getInstance().getLogger(); private static final Int2IntMap legacyToRuntimeId = new Int2IntOpenHashMap(); - private static final Int2IntMap runtimeIdToLegacy = new Int2IntOpenHashMap(); + private static int[] runtimeIdToLegacy; private static final Int2IntMap stateCapacity = new Int2IntOpenHashMap(); private static final Map stateIdByName = new HashMap<>(); private static final Int2ObjectMap nameByStateId = new Int2ObjectOpenHashMap<>(); @@ -192,7 +192,6 @@ public class BlockPalette { CustomBlock.init(); legacyToRuntimeId.defaultReturnValue(-1); - runtimeIdToLegacy.defaultReturnValue(-1); final ArrayList sortStates = new ArrayList<>(); final ArrayList doors = new ArrayList<>(); @@ -296,6 +295,7 @@ public class BlockPalette { String[] wallConnectionType = new String[] {"none", "short", "tall"}; + runtimeIdToLegacy = new int[sortStates.size()]; for (int runtimeId = 0; runtimeId < sortStates.size(); runtimeId++) { final BlockDescription description = sortStates.get(runtimeId); final int blockMeta = description.data; @@ -377,7 +377,7 @@ public class BlockPalette { legacyToRuntimeId.put(legacyId, runtimeId); legacyToRuntimeId.putIfAbsent(legacyId, runtimeId); - runtimeIdToLegacy.put(runtimeId, legacyId); + runtimeIdToLegacy[runtimeId] = legacyId; BlockStateStorage.addState(description.states, runtimeId, description.id, blockMeta, description.newId); } else { @@ -418,7 +418,11 @@ public class BlockPalette { if(protocol == LevelDBConstants.PALETTE_VERSION) { return blockPalette.getLegacyFullId(runtimeId); } - return runtimeIdToLegacy.get(runtimeId); + + if(runtimeId >= 0 && runtimeId < runtimeIdToLegacy.length) { + return runtimeIdToLegacy[runtimeId]; + } + return -1; } @Inject