diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinDrawContext.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinDrawContext.java index c373fba7..1d0f5a2f 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinDrawContext.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinDrawContext.java @@ -19,31 +19,20 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.item; -import com.viaversion.viaversion.protocols.v1_10to1_11.Protocol1_10To1_11; import de.florianmichael.viafabricplus.util.ItemUtil; import net.minecraft.client.gui.DrawContext; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; import net.minecraft.util.Formatting; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(DrawContext.class) public abstract class MixinDrawContext { - @Unique - private static final String viaFabricPlus$vvIdentifier = "VV|" + Protocol1_10To1_11.class.getSimpleName(); // ItemRewriter#nbtTagName - @Redirect(method = "drawItemInSlot(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getCount()I")) private int handleNegativeItemCount(ItemStack instance) { - final NbtCompound tag = ItemUtil.getTagOrNull(instance); - if (tag != null && tag.contains(viaFabricPlus$vvIdentifier)) { - return tag.getInt(viaFabricPlus$vvIdentifier); - } else { - return instance.getCount(); - } + return ItemUtil.getCount(instance); } @Redirect(method = "drawItemInSlot(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V", at = @At(value = "INVOKE", target = "Ljava/lang/String;valueOf(I)Ljava/lang/String;", remap = false)) diff --git a/src/main/java/de/florianmichael/viafabricplus/util/ItemUtil.java b/src/main/java/de/florianmichael/viafabricplus/util/ItemUtil.java index bc0bc07e..2f482cc0 100644 --- a/src/main/java/de/florianmichael/viafabricplus/util/ItemUtil.java +++ b/src/main/java/de/florianmichael/viafabricplus/util/ItemUtil.java @@ -19,12 +19,24 @@ package de.florianmichael.viafabricplus.util; +import com.viaversion.viaversion.protocols.v1_10to1_11.Protocol1_10To1_11; import net.minecraft.component.DataComponentTypes; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; public class ItemUtil { + private static final String VV_IDENTIFIER = "VV|" + Protocol1_10To1_11.class.getSimpleName(); // ItemRewriter#nbtTagName + + public static int getCount(final ItemStack stack) { + final NbtCompound tag = getTagOrNull(stack); + if (tag != null && tag.contains(VV_IDENTIFIER)) { + return tag.getInt(VV_IDENTIFIER); + } else { + return stack.getCount(); + } + } + // Via 1.20.5->.3 will always put the original item data into CUSTOM_DATA if it's not empty. public static NbtCompound getTagOrNull(final ItemStack stack) { if (!stack.contains(DataComponentTypes.CUSTOM_DATA)) {