From 4b1ffa3d2af39e780764971ad5339e14b1d2b56c Mon Sep 17 00:00:00 2001 From: davchoo <4722249+davchoo@users.noreply.github.com> Date: Wed, 21 Dec 2022 15:39:11 -0500 Subject: [PATCH] Remove name_hash from blocksTag/vanillaBlockStates Fixes creative inventory contents with custom blocks registered --- .../populator/BlockRegistryPopulator.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java index 71d35ebf7..b73ec8c27 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java @@ -81,17 +81,24 @@ public final class BlockRegistryPopulator { for (Map.Entry, BiFunction> palette : blockMappers.entrySet()) { int protocolVersion = palette.getKey().valueInt(); - NbtList blocksTag; + List vanillaBlockStates; List blockStates; try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource(String.format("bedrock/block_palette.%s.nbt", palette.getKey().key())); NBTInputStream nbtInputStream = new NBTInputStream(new DataInputStream(new GZIPInputStream(stream)), true, true)) { NbtMap blockPalette = (NbtMap) nbtInputStream.readTag(); - blocksTag = (NbtList) blockPalette.getList("blocks", NbtType.COMPOUND); - blockStates = new ArrayList<>(blocksTag); + + vanillaBlockStates = new ArrayList<>(blockPalette.getList("blocks", NbtType.COMPOUND)); + for (int i = 0; i < vanillaBlockStates.size(); i++) { + NbtMapBuilder builder = vanillaBlockStates.get(i).toBuilder(); + builder.remove("name_hash"); // Quick workaround - was added in 1.19.20 + vanillaBlockStates.set(i, builder.build()); + } + + blockStates = new ArrayList<>(vanillaBlockStates); } catch (Exception e) { throw new AssertionError("Unable to get blocks from runtime block states", e); } - int stateVersion = blocksTag.get(0).getInt("version"); + int stateVersion = vanillaBlockStates.get(0).getInt("version"); List customBlockProperties = new ArrayList<>(); List customBlockStates = new ArrayList<>(); @@ -113,9 +120,7 @@ public final class BlockRegistryPopulator { // as we no longer send a block palette Object2IntMap blockStateOrderedMap = new Object2IntOpenHashMap<>(blockStates.size()); for (int i = 0; i < blockStates.size(); i++) { - NbtMapBuilder builder = blockStates.get(i).toBuilder(); - builder.remove("name_hash"); // Quick workaround - was added in 1.19.20 - NbtMap tag = builder.build(); + NbtMap tag = blockStates.get(i); if (blockStateOrderedMap.containsKey(tag)) { throw new AssertionError("Duplicate block states in Bedrock palette: " + tag); } @@ -128,12 +133,12 @@ public final class BlockRegistryPopulator { for (int i = 0; i < customExtBlockStates.size(); i++) { NbtMap tag = customBlockStates.get(i); CustomBlockState blockState = customExtBlockStates.get(i); - customBlockStateIds.put(blockState, blockStateOrderedMap.getInt(tag)); + customBlockStateIds.put(blockState, blockStateOrderedMap.getOrDefault(tag, -1)); } - remappedVanillaIds = new int[blocksTag.size()]; - for (int i = 0; i < blocksTag.size(); i++) { - remappedVanillaIds[i] = blockStateOrderedMap.getInt(blocksTag.get(i)); + remappedVanillaIds = new int[vanillaBlockStates.size()]; + for (int i = 0; i < vanillaBlockStates.size(); i++) { + remappedVanillaIds[i] = blockStateOrderedMap.getOrDefault(vanillaBlockStates.get(i), -1); } }