Replace ClientsideFixes#ATTRIBUTE_FIX_KEY with ItemRewriter API

This commit is contained in:
FlorianMichael 2024-06-10 10:59:42 +02:00
parent 4bb0057ced
commit 3984f6a12d
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
2 changed files with 12 additions and 9 deletions

View File

@ -68,11 +68,6 @@ public class ClientsideFixes {
*/
public static final String PACKET_SYNC_IDENTIFIER = UUID.randomUUID() + ":" + UUID.randomUUID();
/**
* This identifier is used to store attributes in legacy versions were we replace them using data components
*/
public static final String ATTRIBUTE_FIX_KEY = "VFP|AttributeFix";
/**
* This is an incremental index used for tablist entries to implement FIFO behavior <= 1.7
*/

View File

@ -21,15 +21,19 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.viaversion;
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.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.ListTag;
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 de.florianmichael.viafabricplus.fixes.ClientsideFixes;
import de.florianmichael.viafabricplus.protocoltranslator.impl.ViaFabricPlusMappingDataLoader;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
@ -43,7 +47,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> viaFabricPlus$itemIdentifiers = new Int2ObjectOpenHashMap<>();
@ -51,6 +55,10 @@ public abstract class MixinItemPacketRewriter1_9 {
@Unique
private final Map<String, Map<String, Pair<String, ModifierData>>> viaFabricPlus$itemAttributes = new HashMap<>();
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) {
final JsonObject itemIdentifiers = ViaFabricPlusMappingDataLoader.INSTANCE.loadData("item-identifiers-1.8.json");
@ -88,7 +96,7 @@ public abstract class MixinItemPacketRewriter1_9 {
item.setTag(tag);
attributeFixTag.putBoolean("RemoveTag", true);
}
tag.put(ClientsideFixes.ATTRIBUTE_FIX_KEY, attributeFixTag);
tag.put(nbtTagName("attributeFix"), attributeFixTag);
ListTag<CompoundTag> attributeModifiers = tag.getListTag("AttributeModifiers", CompoundTag.class);
if (attributeModifiers == null) {
@ -116,7 +124,7 @@ public abstract class MixinItemPacketRewriter1_9 {
if (item == null) return;
final CompoundTag tag = item.tag();
if (tag == null) return;
final CompoundTag attributeFixTag = tag.removeUnchecked(ClientsideFixes.ATTRIBUTE_FIX_KEY);
final CompoundTag attributeFixTag = tag.removeUnchecked(nbtTagName("attributeFix"));
if (attributeFixTag == null) return;
if (attributeFixTag.contains("RemoveAttributeModifiers")) {