From da5d8006ad182b550392393bb68187677be36c30 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Thu, 30 May 2024 22:29:00 -0400 Subject: [PATCH] Add native offhand support for *some* items About 46 items are data-driven enough where we can tell Bedrock these items are permitted in the offhand. --- .../populator/ItemRegistryPopulator.java | 27 +++++++++++++++++++ core/src/main/resources/mappings | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/ItemRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/ItemRegistryPopulator.java index 5fcea504f..8f515c1cb 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/ItemRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/ItemRegistryPopulator.java @@ -38,6 +38,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.nbt.NbtMapBuilder; import org.cloudburstmc.nbt.NbtType; +import org.cloudburstmc.nbt.NbtUtils; import org.cloudburstmc.protocol.bedrock.codec.v671.Bedrock_v671; import org.cloudburstmc.protocol.bedrock.codec.v685.Bedrock_v685; import org.cloudburstmc.protocol.bedrock.data.SoundEvent; @@ -102,6 +103,13 @@ public class ItemRegistryPopulator { throw new AssertionError("Unable to load Java runtime item IDs", e); } + NbtMap vanillaComponents; + try (InputStream stream = bootstrap.getResourceOrThrow("mappings/item_components.nbt")) { + vanillaComponents = (NbtMap) NbtUtils.createGZIPReader(stream, true, true).readTag(); + } catch (Exception e) { + throw new AssertionError("Unable to load Bedrock item components", e); + } + boolean customItemsAllowed = GeyserImpl.getInstance().getConfig().isAddNonBedrockItems(); // List values here is important compared to HashSet - we need to preserve the order of what's given to us @@ -531,6 +539,25 @@ public class ItemRegistryPopulator { } } + for (Map.Entry entry : vanillaComponents.entrySet()) { + String id = entry.getKey(); + ItemDefinition definition = definitions.get(id); + if (definition == null) { + // Newer item most likely + GeyserImpl.getInstance().getLogger().debug( + "Skipping vanilla component " + id + " for protocol " + palette.protocolVersion() + ); + continue; + } + + NbtMapBuilder root = NbtMap.builder() + .putString("name", id) + .putInt("id", definition.getRuntimeId()) + .putCompound("components", (NbtMap) entry.getValue()); + + componentItemData.add(new ComponentItemData(id, root.build())); + } + // Register the item forms of custom blocks if (BlockRegistries.CUSTOM_BLOCKS.get().length != 0) { for (CustomBlockData customBlock : BlockRegistries.CUSTOM_BLOCKS.get()) { diff --git a/core/src/main/resources/mappings b/core/src/main/resources/mappings index ec45f59c8..88e50df10 160000 --- a/core/src/main/resources/mappings +++ b/core/src/main/resources/mappings @@ -1 +1 @@ -Subproject commit ec45f59c8590945c9226921ef7e339f510983dc1 +Subproject commit 88e50df1008916c266428ac11f76f07dc24638c5