From f2456abd5b8ae9731bb94ad2d6f637259b25b2c6 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Tue, 10 Dec 2024 11:28:43 +0100 Subject: [PATCH] Handle supported/primary items in registry data Fixes ViaVersion/ViaBackwards#928 --- .../rewriter/RegistryDataRewriter.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/RegistryDataRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/RegistryDataRewriter.java index a364b349a..4dc02c2f7 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/RegistryDataRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/RegistryDataRewriter.java @@ -108,7 +108,13 @@ public class RegistryDataRewriter { continue; } - final CompoundTag effects = ((CompoundTag) entry.tag()).getCompoundTag("effects"); + final CompoundTag tag = (CompoundTag) entry.tag(); + if (protocol.getMappingData().getFullItemMappings() != null) { + updateItemList(tag.getListTag("supported_items", StringTag.class)); + updateItemList(tag.getListTag("primary_items", StringTag.class)); + } + + final CompoundTag effects = tag.getCompoundTag("effects"); if (effects == null) { continue; } @@ -118,8 +124,8 @@ public class RegistryDataRewriter { if (effectEntry.getValue() instanceof final CompoundTag compoundTag) { updateNestedEffect(compoundTag); } else if (effectEntry.getValue() instanceof final ListTag listTag && listTag.getElementType() == CompoundTag.class) { - for (final Tag tag : listTag) { - updateNestedEffect((CompoundTag) tag); + for (final Tag effectTag : listTag) { + updateNestedEffect((CompoundTag) effectTag); } } } @@ -210,4 +216,20 @@ public class RegistryDataRewriter { private boolean hasAttributeMappings() { return protocol.getMappingData() != null && protocol.getMappingData().getAttributeMappings() != null; } + + private void updateItemList(final ListTag listTag) { + if (listTag == null) { + return; + } + for (final StringTag tag : listTag) { + updateItem(tag); + } + } + + private void updateItem(final StringTag tag) { + final String mapped = protocol.getMappingData().getFullItemMappings().mappedIdentifier(tag.getValue()); + if (mapped != null) { + tag.setValue(mapped); + } + } }