mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-11-25 12:25:22 +01:00
Add method to get real item count
This commit is contained in:
parent
22c01812a8
commit
d370e8bc41
@ -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))
|
||||
|
@ -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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user