Use Via API for attribute fix in 1.8->1.9

See 3984f6a12d
This commit is contained in:
FlorianMichael 2024-06-10 11:05:29 +02:00
parent 57ba542470
commit a15b2f586f
No known key found for this signature in database
GPG key ID: C2FB87E71C425126

View file

@ -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<ClientboundPackets1_8, ServerboundPackets1_9, Protocol1_8To1_9> {
@Unique
private final Int2ObjectMap<String> itemIdentifiers = new Int2ObjectOpenHashMap<>();
@ -49,8 +54,9 @@ public abstract class MixinItemPacketRewriter1_9 {
@Unique
private final Map<String, Map<String, Pair<String, ModifierData>>> itemAttributes = new HashMap<>();
@Unique
private final String attributeFixTagName = "VV|AttributeFix";
public MixinItemPacketRewriter1_9(Protocol1_8To1_9 protocol, Type<Item> itemType, Type<Item[]> itemArrayType, Type<Item> mappedItemType, Type<Item[]> mappedItemArrayType) {
super(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType);
}
@Inject(method = "<init>", 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<CompoundTag> 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")) {