Read custom_model_data field from item mappings

Closes #525
This commit is contained in:
Nassim Jahnke 2023-02-02 10:51:26 +01:00
parent 4797914556
commit 94210e92f1
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
4 changed files with 20 additions and 5 deletions

View File

@ -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;
}
}

View File

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

View File

@ -88,6 +88,11 @@ public abstract class ItemRewriter<T extends BackwardsProtocol> 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());

View File

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