Unify tracking tag names
This commit is contained in:
parent
8b26d75717
commit
38a900c78d
|
@ -70,7 +70,12 @@ public class ClientsideFixes {
|
|||
/**
|
||||
* 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_NBT_TAG = "VFP_1_10_ItemCount_" + System.currentTimeMillis();
|
||||
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
|
||||
*/
|
||||
public static final String ATTRIBUTE_FIX_KEY = "VFP|AttributeFix";
|
||||
|
||||
public static void init() {
|
||||
// Register additional CPE features
|
||||
|
|
|
@ -35,8 +35,8 @@ 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);
|
||||
if (tag != null && tag.contains(ClientsideFixes.ITEM_COUNT_FIX_KEY)) {
|
||||
return tag.getInt(ClientsideFixes.ITEM_COUNT_FIX_KEY);
|
||||
} else {
|
||||
return instance.getCount();
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public abstract class MixinEntityIdRewriter {
|
|||
item.setTag(tag);
|
||||
}
|
||||
|
||||
tag.putByte(ClientsideFixes.ITEM_COUNT_NBT_TAG, (byte) item.amount());
|
||||
tag.putByte(ClientsideFixes.ITEM_COUNT_FIX_KEY, (byte) item.amount());
|
||||
item.setTag(tag);
|
||||
}
|
||||
}
|
||||
|
@ -49,8 +49,8 @@ public abstract class MixinEntityIdRewriter {
|
|||
@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_NBT_TAG)) {
|
||||
item.setAmount(item.tag().<ByteTag>remove(ClientsideFixes.ITEM_COUNT_NBT_TAG).asByte());
|
||||
if (item.tag().contains(ClientsideFixes.ITEM_COUNT_FIX_KEY)) {
|
||||
item.setAmount(item.tag().<ByteTag>remove(ClientsideFixes.ITEM_COUNT_FIX_KEY).asByte());
|
||||
if (item.tag().isEmpty()) item.setTag(null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
|||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
import de.florianmichael.viafabricplus.fixes.ClientsideFixes;
|
||||
import de.florianmichael.viafabricplus.protocoltranslator.impl.ViaFabricPlusMappingDataLoader;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
|
@ -49,9 +50,6 @@ public abstract class MixinItemRewriter {
|
|||
@Unique
|
||||
private static final Map<String, Map<String, Pair<String, ModifierData>>> ITEM_ATTRIBUTES = new HashMap<>();
|
||||
|
||||
@Unique
|
||||
private static final String TAG_NAME = "VV|AttributeFix";
|
||||
|
||||
@Inject(method = "<clinit>", at = @At("RETURN"))
|
||||
private static void loadAdditionalData(CallbackInfo ci) {
|
||||
final JsonObject itemIdentifiers = ViaFabricPlusMappingDataLoader.INSTANCE.loadData("item-identifiers-1.8.json");
|
||||
|
@ -88,7 +86,7 @@ public abstract class MixinItemRewriter {
|
|||
item.setTag(tag);
|
||||
attributeFixTag.putBoolean("RemoveTag", true);
|
||||
}
|
||||
tag.put(TAG_NAME, attributeFixTag);
|
||||
tag.put(ClientsideFixes.ATTRIBUTE_FIX_KEY, attributeFixTag);
|
||||
|
||||
ListTag<CompoundTag> attributeModifiers = tag.getListTag("AttributeModifiers", CompoundTag.class);
|
||||
if (attributeModifiers == null) {
|
||||
|
@ -115,7 +113,7 @@ public abstract class MixinItemRewriter {
|
|||
if (item == null) return;
|
||||
final CompoundTag tag = item.tag();
|
||||
if (tag == null) return;
|
||||
final CompoundTag attributeFixTag = tag.removeUnchecked(TAG_NAME);
|
||||
final CompoundTag attributeFixTag = tag.removeUnchecked(ClientsideFixes.ATTRIBUTE_FIX_KEY);
|
||||
if (attributeFixTag == null) return;
|
||||
|
||||
if (attributeFixTag.contains("RemoveAttributeModifiers")) {
|
||||
|
|
|
@ -1,48 +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.util;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
// Stolen from https://github.com/FlorianMichael/RClasses/blob/main/common/src/main/java/de/florianmichael/rclasses/common/StringUtils.java
|
||||
public class StringUtil {
|
||||
|
||||
/**
|
||||
* Convention: IEC 60027-2
|
||||
*/
|
||||
private final static String[] BYTES_UNIT = {"B", "KiB", "MiB", "GiB", "TiB"};
|
||||
private final static DecimalFormat OPTIONAL_FORMAT = new DecimalFormat("#.##");
|
||||
|
||||
/**
|
||||
* Formats a value in bytes to a human-readable format
|
||||
*
|
||||
* @param value The raw value in bytes
|
||||
* @return The formatted value in bytes
|
||||
*/
|
||||
public static String formatBytes(final long value) {
|
||||
int index = (int) (Math.log(value) / Math.log(1024.0));
|
||||
double data = value / Math.pow(1024.0, index);
|
||||
if (index < 0) index = 0;
|
||||
if (Double.isNaN(data)) data = 0;
|
||||
|
||||
return OPTIONAL_FORMAT.format(data) + " " + BYTES_UNIT[index];
|
||||
}
|
||||
|
||||
}
|
|
@ -193,7 +193,8 @@
|
|||
"viabedrock.MixinBedrockProtocol",
|
||||
"viabedrock.MixinJoinPackets",
|
||||
"vialegacy.MixinExtensionProtocolMetadataStorage",
|
||||
"vialegacy.MixinViaLegacyConfig"
|
||||
"vialegacy.MixinViaLegacyConfig",
|
||||
"fixes.viaversion.MixinItemRewriter"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
Loading…
Reference in New Issue