From e878d7795943d5728ce3c7114d2dfbd2843ac897 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 6 Nov 2024 10:42:18 +0100 Subject: [PATCH] Trim override materials are string to string --- .../api/minecraft/item/data/ArmorTrimMaterial.java | 14 +++++++------- .../rewriter/BlockItemPacketRewriter1_20_5.java | 12 ++++-------- .../rewriter/ComponentRewriter1_20_5.java | 9 ++------- .../rewriter/StructuredDataConverter.java | 5 ++--- .../rewriter/EntityPacketRewriter1_21_2.java | 2 +- 5 files changed, 16 insertions(+), 26 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrimMaterial.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrimMaterial.java index efed9bcff..3e8bf4399 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrimMaterial.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrimMaterial.java @@ -27,11 +27,11 @@ import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.misc.HolderType; import io.netty.buffer.ByteBuf; import it.unimi.dsi.fastutil.ints.Int2IntFunction; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; +import java.util.Map; public record ArmorTrimMaterial(String assetName, int itemId, float itemModelIndex, - Int2ObjectMap overrideArmorMaterials, Tag description) { + Map overrideArmorMaterials, Tag description) { public static final HolderType TYPE = new HolderType<>() { @Override @@ -41,9 +41,9 @@ public record ArmorTrimMaterial(String assetName, int itemId, float itemModelInd final float itemModelIndex = buffer.readFloat(); final int overrideArmorMaterialsSize = Types.VAR_INT.readPrimitive(buffer); - final Int2ObjectMap overrideArmorMaterials = new Int2ObjectOpenHashMap<>(overrideArmorMaterialsSize); + final Map overrideArmorMaterials = new Object2ObjectArrayMap<>(overrideArmorMaterialsSize); for (int i = 0; i < overrideArmorMaterialsSize; i++) { - final int key = Types.VAR_INT.readPrimitive(buffer); + final String key = Types.STRING.read(buffer); final String value = Types.STRING.read(buffer); overrideArmorMaterials.put(key, value); } @@ -59,8 +59,8 @@ public record ArmorTrimMaterial(String assetName, int itemId, float itemModelInd buffer.writeFloat(value.itemModelIndex()); Types.VAR_INT.writePrimitive(buffer, value.overrideArmorMaterials().size()); - for (final Int2ObjectMap.Entry entry : value.overrideArmorMaterials().int2ObjectEntrySet()) { - Types.VAR_INT.writePrimitive(buffer, entry.getIntKey()); + for (final Map.Entry entry : value.overrideArmorMaterials().entrySet()) { + Types.STRING.write(buffer, entry.getKey()); Types.STRING.write(buffer, entry.getValue()); } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java index 64d4965ae..3d068b02a 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java @@ -105,8 +105,7 @@ import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.SerializerVersion; import com.viaversion.viaversion.util.UUIDUtil; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -1000,17 +999,14 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter overrideArmorMaterials = new Int2ObjectOpenHashMap<>(); + final Map overrideArmorMaterials = new Object2ObjectArrayMap<>(); if (overrideArmorMaterialsTag != null) { for (final Map.Entry entry : overrideArmorMaterialsTag.entrySet()) { if (!(entry.getValue() instanceof StringTag valueTag)) { continue; } - try { - final int id = Integer.parseInt(entry.getKey()); - overrideArmorMaterials.put(id, valueTag.getValue()); - } catch (NumberFormatException ignored) { - } + + overrideArmorMaterials.put(entry.getKey(), valueTag.getValue()); } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/ComponentRewriter1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/ComponentRewriter1_20_5.java index 931f80a8b..2713aaa27 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/ComponentRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/ComponentRewriter1_20_5.java @@ -74,7 +74,6 @@ import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.api.type.types.UnsignedByteType; import com.viaversion.viaversion.api.type.types.item.StructuredDataType; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.Protocol1_20_3To1_20_5; -import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.ArmorMaterials1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.Attributes1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.BannerPatterns1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.DyeColors; @@ -92,7 +91,6 @@ import com.viaversion.viaversion.util.SerializerVersion; import com.viaversion.viaversion.util.UUIDUtil; import com.viaversion.viaversion.util.Unit; import it.unimi.dsi.fastutil.ints.Int2IntMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap; import java.util.ArrayList; import java.util.List; @@ -693,11 +691,8 @@ public class ComponentRewriter1_20_5 extends Co } final CompoundTag overrideArmorMaterialsTag = new CompoundTag(); - for (final Int2ObjectMap.Entry entry : armorTrimMaterial.overrideArmorMaterials().int2ObjectEntrySet()) { - final String materialKey = ArmorMaterials1_20_5.idToKey(entry.getIntKey()); - if (materialKey != null) { - overrideArmorMaterialsTag.putString(materialKey, entry.getValue()); - } + for (final Map.Entry entry : armorTrimMaterial.overrideArmorMaterials().entrySet()) { + overrideArmorMaterialsTag.putString(entry.getKey(), entry.getValue()); } materialTag.putString("asset_name", armorTrimMaterial.assetName()); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/StructuredDataConverter.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/StructuredDataConverter.java index 1c303b05b..571cd88bf 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/StructuredDataConverter.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/StructuredDataConverter.java @@ -65,7 +65,6 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.BannerPattern import com.viaversion.viaversion.util.ComponentUtil; import com.viaversion.viaversion.util.UUIDUtil; import it.unimi.dsi.fastutil.ints.Int2IntMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap; import java.util.Arrays; import java.util.Collections; @@ -530,8 +529,8 @@ public final class StructuredDataConverter { final CompoundTag overrideArmorMaterials = new CompoundTag(); if (!material.overrideArmorMaterials().isEmpty()) { - for (final Int2ObjectMap.Entry entry : material.overrideArmorMaterials().int2ObjectEntrySet()) { - overrideArmorMaterials.put(Integer.toString(entry.getIntKey()), new StringTag(entry.getValue())); + for (final Map.Entry entry : material.overrideArmorMaterials().entrySet()) { + overrideArmorMaterials.put(entry.getKey(), new StringTag(entry.getValue())); } materialTag.put("override_armor_materials", overrideArmorMaterials); } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/EntityPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/EntityPacketRewriter1_21_2.java index 2638a44ff..aba23c3a8 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/EntityPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/EntityPacketRewriter1_21_2.java @@ -453,7 +453,7 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter