From 9f652ad24ac3731043dc754885cb07d20fca581a Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Fri, 5 Apr 2024 15:38:37 +0200 Subject: [PATCH] Update VV usage --- .../rewriters/BackwardsItemRewriterBase.java | 4 ++-- .../BackwardsStructuredItemRewriter.java | 8 ++++---- .../StructuredEnchantmentRewriter.java | 20 +++++++++---------- .../Protocol1_20_3To1_20_5.java | 1 - .../BlockItemPacketRewriter1_20_5.java | 6 +++--- .../BlockItemPacketRewriter1_20_2.java | 6 +++--- 6 files changed, 22 insertions(+), 23 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsItemRewriterBase.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsItemRewriterBase.java index 3099fe1f..81f8e689 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsItemRewriterBase.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsItemRewriterBase.java @@ -76,7 +76,7 @@ public abstract class BackwardsItemRewriterBase original, String name) { // List tags cannot contain tags of different types, so we have to store them a bit more awkwardly as an indexed compound tag - String backupName = getNbtTagName() + "|" + name; + String backupName = nbtTagName(name); if (!tag.contains(backupName)) { CompoundTag output = new CompoundTag(); for (int i = 0; i < original.size(); i++) { @@ -87,7 +87,7 @@ public abstract class BackwardsItemRewriterBase removeGenericTagList(CompoundTag tag, String name) { - String backupName = getNbtTagName() + "|" + name; + String backupName = nbtTagName(name); CompoundTag data = tag.getCompoundTag(backupName); if (data == null) { return null; diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java index c0de1282..9d15876a 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java @@ -101,7 +101,7 @@ public class BackwardsStructuredItemRewriter glintOverride = data.getNonEmpty(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE); if (glintOverride != null) { - tag.putBoolean(itemRewriter.getNbtTagName() + "|glint", glintOverride.value()); + tag.putBoolean(itemRewriter.nbtTagName("glint"), glintOverride.value()); } else { - tag.putBoolean(itemRewriter.getNbtTagName() + "|noglint", true); + tag.putBoolean(itemRewriter.nbtTagName("noglint"), true); } data.set(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE, true); } @@ -135,11 +135,11 @@ public class StructuredEnchantmentRewriter { itemRewriter.saveGenericTagList(tag, loreList, "lore"); loreToAdd.addAll(loreList); } else { - tag.putBoolean(itemRewriter.getNbtTagName() + "|nolore", true); + tag.putBoolean(itemRewriter.nbtTagName("nolore"), true); } if (enchantments.showInTooltip()) { - tag.putBoolean(itemRewriter.getNbtTagName() + "|show_" + key.identifier(), true); + tag.putBoolean(itemRewriter.nbtTagName("show_" + key.identifier()), true); } data.set(StructuredDataKey.LORE, loreToAdd.toArray(new Tag[0])); @@ -162,21 +162,21 @@ public class StructuredEnchantmentRewriter { return; } - final Tag glintTag = tag.remove(itemRewriter.getNbtTagName() + "|glint"); + final Tag glintTag = tag.remove(itemRewriter.nbtTagName("glint")); if (glintTag instanceof ByteTag) { data.set(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE, ((NumberTag) glintTag).asBoolean()); - } else if (tag.remove(itemRewriter.getNbtTagName() + "|noglint") != null) { + } else if (tag.remove(itemRewriter.nbtTagName("noglint")) != null) { data.remove(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE); } final List lore = itemRewriter.removeGenericTagList(tag, "lore"); if (lore != null) { data.set(StructuredDataKey.LORE, lore.toArray(new Tag[0])); - } else if (tag.remove(itemRewriter.getNbtTagName() + "|nolore") != null) { + } else if (tag.remove(itemRewriter.nbtTagName("nolore")) != null) { data.remove(StructuredDataKey.LORE); } - final Enchantments enchantments = new Enchantments(tag.remove(itemRewriter.getNbtTagName() + "|show_" + key.identifier()) != null); + final Enchantments enchantments = new Enchantments(tag.remove(itemRewriter.nbtTagName("show_" + key.identifier())) != null); for (final CompoundTag enchantment : enchantmentsTag) { enchantments.add(enchantment.getInt("id"), enchantment.getInt("lvl")); } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/Protocol1_20_3To1_20_5.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/Protocol1_20_3To1_20_5.java index 7d15aeca..94d952c6 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/Protocol1_20_3To1_20_5.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/Protocol1_20_3To1_20_5.java @@ -76,7 +76,6 @@ public final class Protocol1_20_3To1_20_5 extends BackwardsProtocol tagRewriter = new TagRewriter<>(this); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java index a9336dd1..a28c6851 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java @@ -18,8 +18,6 @@ package com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.rewriter; import com.viaversion.viabackwards.api.rewriters.BackwardsStructuredItemRewriter; -import com.viaversion.viabackwards.api.rewriters.EnchantmentRewriter; -import com.viaversion.viabackwards.api.rewriters.StructuredEnchantmentRewriter; import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.Protocol1_20_3To1_20_5; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.minecraft.Particle; @@ -34,12 +32,14 @@ import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.rewriter.Recip import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.Protocol1_20_5To1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundPacket1_20_5; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundPackets1_20_5; +import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.rewriter.StructuredDataConverter; import com.viaversion.viaversion.rewriter.BlockRewriter; import com.viaversion.viaversion.util.Key; import org.checkerframework.checker.nullness.qual.Nullable; public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItemRewriter { + private static final StructuredDataConverter DATA_CONVERTER = new StructuredDataConverter(true); private final Protocol1_20_5To1_20_3 vvProtocol = Via.getManager().getProtocolManager().getProtocol(Protocol1_20_5To1_20_3.class); public BlockItemPacketRewriter1_20_5(final Protocol1_20_3To1_20_5 protocol) { @@ -161,7 +161,7 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem if (item == null) return null; super.handleItemToClient(item); - return vvProtocol.getItemRewriter().toOldItem(item); + return vvProtocol.getItemRewriter().toOldItem(item, DATA_CONVERTER); } @Override diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/rewriter/BlockItemPacketRewriter1_20_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/rewriter/BlockItemPacketRewriter1_20_2.java index 107fd9c2..2124d949 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/rewriter/BlockItemPacketRewriter1_20_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/rewriter/BlockItemPacketRewriter1_20_2.java @@ -40,7 +40,7 @@ import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ServerboundPac import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundPackets1_20_2; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ServerboundPackets1_20_2; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.rewriter.RecipeRewriter1_20_2; -import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.util.PotionEffects; +import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.util.PotionEffects1_20_2; import com.viaversion.viaversion.rewriter.BlockRewriter; import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.MathUtil; @@ -402,13 +402,13 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter