Port pre 1.11 negative item count fix

This commit is contained in:
FlorianMichael 2024-04-28 12:39:16 +02:00
parent ff942ccf09
commit 8b26d75717
4 changed files with 55 additions and 33 deletions

View File

@ -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 {

View File

@ -1,30 +0,0 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> 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 <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.access;
public interface IItemStack {
boolean viaFabricPlus$has1_10Tag();
int viaFabricPlus$get1_10Count();
void viaFabricPlus$set1_10Count(final int count);
}

View File

@ -0,0 +1,54 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> 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 <http://www.gnu.org/licenses/>.
*/
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);
}
}
}

View File

@ -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",