From bc4ad7faa36259e0dded78cb5735ec0b09d0f3de Mon Sep 17 00:00:00 2001 From: Valaphee The Meerkat <32491319+valaphee@users.noreply.github.com> Date: Thu, 31 Oct 2024 19:27:49 +0100 Subject: [PATCH] Remove empty lock item components in 1.21->1.21.2 (#4228) * Fix protocol error when an empty lock is sent * Cleanup code --------- Co-authored-by: FlorianMichael --- .../rewriter/BlockItemPacketRewriter1_21_2.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/BlockItemPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/BlockItemPacketRewriter1_21_2.java index 02a75c90c..7d053a49c 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/BlockItemPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/BlockItemPacketRewriter1_21_2.java @@ -563,11 +563,17 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter< dataContainer.replaceKey(StructuredDataKey.BUNDLE_CONTENTS1_21, StructuredDataKey.BUNDLE_CONTENTS1_21_2); dataContainer.replaceKey(StructuredDataKey.POTION_CONTENTS1_20_5, StructuredDataKey.POTION_CONTENTS1_21_2); dataContainer.replace(StructuredDataKey.FIRE_RESISTANT, StructuredDataKey.DAMAGE_RESISTANT, fireResistant -> new DamageResistant("minecraft:is_fire")); - dataContainer.replace(StructuredDataKey.LOCK, lock -> { + dataContainer.replace(StructuredDataKey.LOCK, tag -> { + final String lock = ((StringTag) tag).getValue(); + if (lock.isEmpty()) { + // Previously ignored empty values since the data was arbitrary, custom_name doesn't accept empty values + return null; + } + final CompoundTag predicateTag = new CompoundTag(); final CompoundTag itemComponentsTag = new CompoundTag(); predicateTag.put("components", itemComponentsTag); - itemComponentsTag.put("custom_name", lock); + itemComponentsTag.put("custom_name", tag); return predicateTag; }); }