From a15b2f586fa44167a27f589ab2d095b64365395a Mon Sep 17 00:00:00 2001 From: FlorianMichael Date: Mon, 10 Jun 2024 11:05:29 +0200 Subject: [PATCH] Use Via API for attribute fix in 1.8->1.9 See https://github.com/ViaVersion/ViaFabricPlus/commit/3984f6a12dcfaebb7df213f7617a3f1b0cce9f8d --- .../mixins/MixinItemPacketRewriter1_9.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/raphimc/viaproxy/injection/mixins/MixinItemPacketRewriter1_9.java b/src/main/java/net/raphimc/viaproxy/injection/mixins/MixinItemPacketRewriter1_9.java index e7eca13..12ca9b8 100644 --- a/src/main/java/net/raphimc/viaproxy/injection/mixins/MixinItemPacketRewriter1_9.java +++ b/src/main/java/net/raphimc/viaproxy/injection/mixins/MixinItemPacketRewriter1_9.java @@ -22,11 +22,16 @@ import com.viaversion.nbt.tag.CompoundTag; import com.viaversion.nbt.tag.ListTag; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.data.ModifierData; +import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap; import com.viaversion.viaversion.libs.gson.JsonElement; import com.viaversion.viaversion.libs.gson.JsonObject; +import com.viaversion.viaversion.protocols.v1_8to1_9.Protocol1_8To1_9; +import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_8; +import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ServerboundPackets1_9; import com.viaversion.viaversion.protocols.v1_8to1_9.rewriter.ItemPacketRewriter1_9; +import com.viaversion.viaversion.rewriter.ItemRewriter; import com.viaversion.viaversion.util.Pair; import net.raphimc.viaproxy.protocoltranslator.impl.ViaProxyMappingDataLoader; import org.spongepowered.asm.mixin.Mixin; @@ -41,7 +46,7 @@ import java.util.Map; import java.util.UUID; @Mixin(value = ItemPacketRewriter1_9.class, remap = false) -public abstract class MixinItemPacketRewriter1_9 { +public abstract class MixinItemPacketRewriter1_9 extends ItemRewriter { @Unique private final Int2ObjectMap itemIdentifiers = new Int2ObjectOpenHashMap<>(); @@ -49,8 +54,9 @@ public abstract class MixinItemPacketRewriter1_9 { @Unique private final Map>> itemAttributes = new HashMap<>(); - @Unique - private final String attributeFixTagName = "VV|AttributeFix"; + public MixinItemPacketRewriter1_9(Protocol1_8To1_9 protocol, Type itemType, Type itemArrayType, Type mappedItemType, Type mappedItemArrayType) { + super(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType); + } @Inject(method = "", at = @At("RETURN")) private void loadAdditionalData(CallbackInfo ci) { @@ -89,7 +95,7 @@ public abstract class MixinItemPacketRewriter1_9 { item.setTag(tag); attributeFixTag.putBoolean("RemoveTag", true); } - tag.put(this.attributeFixTagName, attributeFixTag); + tag.put(nbtTagName("attributeFix"), attributeFixTag); ListTag attributeModifiers = tag.getListTag("AttributeModifiers", CompoundTag.class); if (attributeModifiers == null) { @@ -117,7 +123,7 @@ public abstract class MixinItemPacketRewriter1_9 { if (item == null) return; final CompoundTag tag = item.tag(); if (tag == null) return; - final CompoundTag attributeFixTag = tag.removeUnchecked(attributeFixTagName); + final CompoundTag attributeFixTag = tag.removeUnchecked(nbtTagName("attributeFix")); if (attributeFixTag == null) return; if (attributeFixTag.contains("RemoveAttributeModifiers")) {