From 94210e92f1f008751cec40893c4b70241a411234 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 2 Feb 2023 10:51:26 +0100 Subject: [PATCH] Read custom_model_data field from item mappings Closes #525 --- .../viabackwards/api/data/MappedItem.java | 15 +++++++++++++-- .../api/data/VBMappingDataLoader.java | 3 ++- .../viabackwards/api/rewriters/ItemRewriter.java | 5 +++++ .../data/EntityPackets1_19_4.java | 2 -- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/data/MappedItem.java b/common/src/main/java/com/viaversion/viabackwards/api/data/MappedItem.java index 892d4aaa..0460f341 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/data/MappedItem.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/data/MappedItem.java @@ -18,15 +18,22 @@ package com.viaversion.viabackwards.api.data; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter; +import org.checkerframework.checker.nullness.qual.Nullable; public class MappedItem { private final int id; private final String jsonName; + private final Integer customModelData; - public MappedItem(int id, String name) { + public MappedItem(final int id, final String name) { + this(id, name, null); + } + + public MappedItem(final int id, final String name, @Nullable final Integer customModelData) { this.id = id; - this.jsonName = ChatRewriter.legacyTextToJsonString("§f" + name); + this.jsonName = ChatRewriter.legacyTextToJsonString("§f" + name, true); + this.customModelData = customModelData; } public int getId() { @@ -36,4 +43,8 @@ public class MappedItem { public String getJsonName() { return jsonName; } + + public @Nullable Integer customModelData() { + return customModelData; + } } diff --git a/common/src/main/java/com/viaversion/viabackwards/api/data/VBMappingDataLoader.java b/common/src/main/java/com/viaversion/viabackwards/api/data/VBMappingDataLoader.java index c5e7c156..48dd9725 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/data/VBMappingDataLoader.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/data/VBMappingDataLoader.java @@ -162,7 +162,8 @@ public final class VBMappingDataLoader { } String name = object.getAsJsonPrimitive("name").getAsString(); - itemMapping.put(oldId, new MappedItem(mappedId, name)); + JsonPrimitive customModelData = object.getAsJsonPrimitive("custom_model_data"); + itemMapping.put(oldId, new MappedItem(mappedId, name, customModelData != null ? customModelData.getAsInt() : null)); } // Look for missing keys diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriter.java index 5efe4b39..d6e9c933 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriter.java @@ -88,6 +88,11 @@ public abstract class ItemRewriter extends ItemRewr item.tag().put(nbtTagName + "|id", new IntTag(item.identifier())); item.setIdentifier(data.getId()); + // Add custom model data + if (data.customModelData() != null && !item.tag().contains("CustomModelData")) { + item.tag().put("CustomModelData", new IntTag(data.customModelData())); + } + // Set custom name - only done if there is no original one if (display == null) { item.tag().put("display", display = new CompoundTag()); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/data/EntityPackets1_19_4.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/data/EntityPackets1_19_4.java index 64e96f51..4a6139cc 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/data/EntityPackets1_19_4.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/data/EntityPackets1_19_4.java @@ -20,10 +20,8 @@ package com.viaversion.viabackwards.protocol.protocol1_19_3to1_19_4.data; import com.viaversion.viabackwards.protocol.protocol1_19_3to1_19_4.Protocol1_19_3To1_19_4; import com.viaversion.viaversion.api.minecraft.entities.Entity1_19_3Types; import com.viaversion.viaversion.api.minecraft.entities.EntityType; -import com.viaversion.viaversion.api.minecraft.nbt.BinaryTagIO; import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.libs.opennbt.NBTIO; import com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;