From 659bee771bb4531c060a9a62aa3b9261ff5c315a Mon Sep 17 00:00:00 2001 From: EnZaXD <60033407+FlorianMichael@users.noreply.github.com> Date: Mon, 20 May 2024 19:08:10 +0200 Subject: [PATCH] Use mapped identifier getter when converting items in 1.20.3->.5 components (#3869) --- .../rewriter/ComponentRewriter1_20_5.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/ComponentRewriter1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/ComponentRewriter1_20_5.java index 74fed2253..eb71d036e 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/ComponentRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/ComponentRewriter1_20_5.java @@ -234,9 +234,9 @@ public class ComponentRewriter1_20_5 extends Co } if (structuredItem.identifier() != 0) { - final String itemName = Protocol1_20_3To1_20_5.MAPPINGS.getFullItemMappings().mappedIdentifier(structuredItem.identifier()); - if (itemName != null) { - contentsTag.putString("id", itemName); + final String identifier = mappedIdentifier(structuredItem.identifier()); + if (identifier != null) { + contentsTag.putString("id", identifier); } } else { // Cannot be air @@ -334,6 +334,10 @@ public class ComponentRewriter1_20_5 extends Co return StructuredData.of(key, converter.convert(tag), id); } + private String mappedIdentifier(final int id) { + return Protocol1_20_3To1_20_5.MAPPINGS.getFullItemMappings().mappedIdentifier(id); + } + // --------------------------------------------------------------------------------------- // Conversion methods, can be overridden in future protocols to handle new changes @@ -849,11 +853,11 @@ public class ComponentRewriter1_20_5 extends Co protected ListTag convertPotDecorations(final PotDecorations value) { final ListTag tag = new ListTag<>(StringTag.class); for (final int decoration : value.itemIds()) { - final String item = Protocol1_20_3To1_20_5.MAPPINGS.getFullItemMappings().identifier(decoration); - if (item == null) { + final String identifier = mappedIdentifier(decoration); + if (identifier == null) { throw new IllegalArgumentException("Unknown item: " + decoration); } - tag.add(new StringTag(item)); + tag.add(new StringTag(identifier)); } return tag; } @@ -957,11 +961,11 @@ public class ComponentRewriter1_20_5 extends Co } protected void convertItem(final CompoundTag tag, final Item item) { - final String name = Protocol1_20_3To1_20_5.MAPPINGS.getFullItemMappings().identifier(item.identifier()); - if (name == null) { + final String identifier = mappedIdentifier(item.identifier()); + if (identifier == null) { throw new IllegalArgumentException("Unknown item: " + item.identifier()); } - tag.putString("id", name); + tag.putString("id", identifier); try { tag.put("count", convertPositiveInt(item.amount())); } catch (IllegalArgumentException ignored) { // Fallback value