Update VV usage

This commit is contained in:
FlorianMichael 2024-06-10 10:57:33 +02:00
parent 6fd7e3730e
commit 4bb0057ced
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
4 changed files with 7 additions and 68 deletions

View File

@ -68,11 +68,6 @@ public class ClientsideFixes {
*/
public static final String PACKET_SYNC_IDENTIFIER = UUID.randomUUID() + ":" + UUID.randomUUID();
/**
* This identifier is an internal identifier used to store the item count in <= 1.10 to implement negative item counts
*/
public static final String ITEM_COUNT_FIX_KEY = "VFP|ItemCountFix";
/**
* This identifier is used to store attributes in legacy versions were we replace them using data components
*/

View File

@ -19,24 +19,28 @@
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.item;
import de.florianmichael.viafabricplus.fixes.ClientsideFixes;
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(ClientsideFixes.ITEM_COUNT_FIX_KEY)) {
return tag.getInt(ClientsideFixes.ITEM_COUNT_FIX_KEY);
if (tag != null && tag.contains(viaFabricPlus$vvIdentifier)) {
return tag.getInt(viaFabricPlus$vvIdentifier);
} else {
return instance.getCount();
}

View File

@ -1,59 +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.mixin.fixes.viaversion;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.nbt.tag.ByteTag;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.protocols.v1_10to1_11.data.EntityMappings1_11;
import de.florianmichael.viafabricplus.fixes.ClientsideFixes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(value = EntityMappings1_11.class, remap = false)
public abstract class MixinEntityMappings1_11 {
@Inject(method = "toClientItem(Lcom/viaversion/viaversion/api/minecraft/item/Item;Z)V", at = @At("HEAD"))
private static void handleNegativeItemCountS2C(Item item, boolean backwards, CallbackInfo ci) {
if (item != null && item.amount() <= 0) {
CompoundTag tag = item.tag();
if (tag == null) {
tag = new CompoundTag();
item.setTag(tag);
}
tag.putByte(ClientsideFixes.ITEM_COUNT_FIX_KEY, (byte) item.amount());
item.setTag(tag);
}
}
@Inject(method = "toServerItem(Lcom/viaversion/viaversion/api/minecraft/item/Item;Z)V", at = @At("HEAD"))
private static void handleNegativeItemCountC2S(Item item, boolean backwards, CallbackInfo ci) {
if (item != null && item.tag() != null) {
if (item.tag().contains(ClientsideFixes.ITEM_COUNT_FIX_KEY)) {
item.setAmount(item.tag().<ByteTag>removeUnchecked(ClientsideFixes.ITEM_COUNT_FIX_KEY).asByte());
if (item.tag().isEmpty()) item.setTag(null);
}
}
}
}

View File

@ -171,7 +171,6 @@
"fixes.viaversion.MixinBlockItemPacketRewriter1_20_5",
"fixes.viaversion.MixinCommandBlockProvider",
"fixes.viaversion.MixinCommonBoss",
"fixes.viaversion.MixinEntityMappings1_11",
"fixes.viaversion.MixinEntityPacketRewriter1_15",
"fixes.viaversion.MixinEntityPacketRewriter1_17",
"fixes.viaversion.MixinEntityPacketRewriter1_19_4",