From 8b26d7571780afb3e9670b1023276cad13f4d9c4 Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Sun, 28 Apr 2024 12:39:16 +0200 Subject: [PATCH] Port pre 1.11 negative item count fix --- .../viafabricplus/ViaFabricPlus.java | 3 -- .../injection/access/IItemStack.java | 30 ----------- .../minecraft/item/MixinDrawContext.java | 54 +++++++++++++++++++ src/main/resources/viafabricplus.mixins.json | 1 + 4 files changed, 55 insertions(+), 33 deletions(-) delete mode 100644 src/main/java/de/florianmichael/viafabricplus/injection/access/IItemStack.java create mode 100644 src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinDrawContext.java diff --git a/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java b/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java index 3e322990..a00b434b 100644 --- a/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java +++ b/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java @@ -47,9 +47,6 @@ import java.util.concurrent.CompletableFuture; * - Collision hit boxes has been changed (https://github.com/ViaVersion/ViaFabricPlus/issues/195) * - Blip-jumping is not supported in <= 1.13.2 (https://github.com/ViaVersion/ViaFabricPlus/issues/225) * - Older versions don't clamp positions when teleporting (Is this important?) - * - * TODO | Port - * - Readd item fixes: MixinItemStack, MixinDrawContext, MixinPacketByteBuf */ public class ViaFabricPlus { diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/access/IItemStack.java b/src/main/java/de/florianmichael/viafabricplus/injection/access/IItemStack.java deleted file mode 100644 index 5b870870..00000000 --- a/src/main/java/de/florianmichael/viafabricplus/injection/access/IItemStack.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus - * Copyright (C) 2021-2024 FlorianMichael/EnZaXD and RK_01/RaphiMC - * Copyright (C) 2023-2024 contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package de.florianmichael.viafabricplus.injection.access; - -public interface IItemStack { - - boolean viaFabricPlus$has1_10Tag(); - - int viaFabricPlus$get1_10Count(); - - void viaFabricPlus$set1_10Count(final int count); - -} 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 new file mode 100644 index 00000000..dba7cc02 --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinDrawContext.java @@ -0,0 +1,54 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus + * Copyright (C) 2021-2024 FlorianMichael/EnZaXD and RK_01/RaphiMC + * Copyright (C) 2023-2024 contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.item; + +import de.florianmichael.viafabricplus.fixes.ClientsideFixes; +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.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(DrawContext.class) +public abstract class MixinDrawContext { + + @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.getOrNull(instance); + if (tag != null && tag.contains(ClientsideFixes.ITEM_COUNT_NBT_TAG)) { + return tag.getInt(ClientsideFixes.ITEM_COUNT_NBT_TAG); + } else { + return instance.getCount(); + } + } + + @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)) + private String makeTextRed(int count) { + if (count <= 0) { + return Formatting.RED.toString() + count; + } else { + return String.valueOf(count); + } + } + +} diff --git a/src/main/resources/viafabricplus.mixins.json b/src/main/resources/viafabricplus.mixins.json index bfac46bd..ce29e837 100644 --- a/src/main/resources/viafabricplus.mixins.json +++ b/src/main/resources/viafabricplus.mixins.json @@ -115,6 +115,7 @@ "fixes.minecraft.item.MixinBlockItem", "fixes.minecraft.item.MixinBowItem", "fixes.minecraft.item.MixinBrushItem", + "fixes.minecraft.item.MixinDrawContext", "fixes.minecraft.item.MixinEnderPearlItem", "fixes.minecraft.item.MixinEquipment", "fixes.minecraft.item.MixinFireworkRocketItem",