From ab11527c86b5c1a79eba1a49571039d5c18a326b Mon Sep 17 00:00:00 2001 From: EnZaXD <60033407+FlorianMichael@users.noreply.github.com> Date: Tue, 23 Apr 2024 22:18:45 +0200 Subject: [PATCH 1/3] Reuse existing logger getter in BackwardsMappings (#726) --- .../com/viaversion/viabackwards/api/data/BackwardsMappings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/data/BackwardsMappings.java b/common/src/main/java/com/viaversion/viabackwards/api/data/BackwardsMappings.java index 5ecd95fe..33aa5351 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/data/BackwardsMappings.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/data/BackwardsMappings.java @@ -142,7 +142,7 @@ public class BackwardsMappings extends MappingDataBase { public @Nullable String mappedEntityName(final String entityName) { if (entityNames == null) { - ViaBackwards.getPlatform().getLogger().severe("No entity mappings found when requesting them for " + entityName); + getLogger().severe("No entity mappings found when requesting them for " + entityName); new Exception().printStackTrace(); return null; } From c4c15fb047efcb16e2999733cb2d2e32aab6a61b Mon Sep 17 00:00:00 2001 From: EnZaXD <60033407+FlorianMichael@users.noreply.github.com> Date: Tue, 23 Apr 2024 22:18:58 +0200 Subject: [PATCH 2/3] Add EntityRewriterBase#getDisplayVisibilityMetaValue (#725) --- .../viabackwards/api/rewriters/EntityRewriterBase.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriterBase.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriterBase.java index b23e0e47..aecdda5b 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriterBase.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriterBase.java @@ -105,10 +105,14 @@ public abstract class EntityRewriterBase metadataList) { if (alwaysShowOriginalMobName()) { removeMeta(displayVisibilityIndex, metadataList); - metadataList.add(new Metadata(displayVisibilityIndex, displayVisibilityMetaType, true)); + metadataList.add(new Metadata(displayVisibilityIndex, displayVisibilityMetaType, getDisplayVisibilityMetaValue())); } } + protected Object getDisplayVisibilityMetaValue() { + return true; + } + protected boolean alwaysShowOriginalMobName() { return ViaBackwards.getConfig().alwaysShowOriginalMobName(); } From 100febf575891616024ede2109da21c0312a631d Mon Sep 17 00:00:00 2001 From: EnZaXD <60033407+FlorianMichael@users.noreply.github.com> Date: Fri, 26 Apr 2024 09:18:42 +0200 Subject: [PATCH 3/3] Rework legacy item/block mappings format (#728) --- .../api/data/MappedLegacyBlockItem.java | 31 ++++++++-- .../rewriters/LegacyBlockItemRewriter.java | 33 +++++++---- .../packets/BlockItemPackets1_11.java | 2 +- .../viabackwards/data/item-mappings-1.10.json | 57 +++++++++---------- .../data/item-mappings-1.11.1.json | 8 ++- .../viabackwards/data/item-mappings-1.11.json | 36 ++++++------ .../viabackwards/data/item-mappings-1.12.json | 47 +++++++-------- 7 files changed, 125 insertions(+), 89 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/data/MappedLegacyBlockItem.java b/common/src/main/java/com/viaversion/viabackwards/api/data/MappedLegacyBlockItem.java index 88aeaebd..b5027e2e 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/data/MappedLegacyBlockItem.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/data/MappedLegacyBlockItem.java @@ -27,13 +27,19 @@ public class MappedLegacyBlockItem { private final short data; private final String name; private final IdAndData block; + private final Type type; private BlockEntityHandler blockEntityHandler; - public MappedLegacyBlockItem(int id, short data, @Nullable String name, boolean block) { + public MappedLegacyBlockItem(int id) { + this(id, (short) -1, null, Type.ITEM); + } + + public MappedLegacyBlockItem(int id, short data, @Nullable String name, Type type) { this.id = id; this.data = data; this.name = name != null ? "§f" + name : null; - this.block = block ? data != -1 ? new IdAndData(id, data) : new IdAndData(id) : null; + this.block = type != Type.ITEM ? data != -1 ? new IdAndData(id, data) : new IdAndData(id) : null; + this.type = type; } public int getId() { @@ -48,8 +54,8 @@ public class MappedLegacyBlockItem { return name; } - public boolean isBlock() { - return block != null; + public Type getType() { + return type; } public IdAndData getBlock() { @@ -73,4 +79,21 @@ public class MappedLegacyBlockItem { CompoundTag handleOrNewCompoundTag(int block, CompoundTag tag); } + + public enum Type { + + ITEM("items"), + BLOCK_ITEM("block-items"), + BLOCK("blocks"); + + final String name; + + Type(final String name) { + this.name = name; + } + + public String getName() { + return name; + } + } } diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java index d06c0c7e..e6a1b05a 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java @@ -62,18 +62,25 @@ public abstract class LegacyBlockItemRewriter dataEntry : jsonObject.entrySet()) { - addMapping(dataEntry.getKey(), dataEntry.getValue().getAsJsonObject(), replacementData); + for (final MappedLegacyBlockItem.Type value : MappedLegacyBlockItem.Type.values()) { + addMappings(value, jsonObject, replacementData); } } - private void addMapping(String key, JsonObject object, Int2ObjectMap mappings) { + private void addMappings(MappedLegacyBlockItem.Type type, JsonObject object, Int2ObjectMap mappings) { + if (object.has(type.getName())) { + final JsonObject mappingsObject = object.getAsJsonObject(type.getName()); + for (Map.Entry dataEntry : mappingsObject.entrySet()) { + addMapping(dataEntry.getKey(), dataEntry.getValue().getAsJsonObject(), type, mappings); + } + } + } + + private void addMapping(String key, JsonObject object, MappedLegacyBlockItem.Type type, Int2ObjectMap mappings) { int id = object.getAsJsonPrimitive("id").getAsInt(); JsonPrimitive jsonData = object.getAsJsonPrimitive("data"); short data = jsonData != null ? jsonData.getAsShort() : 0; - String name = object.getAsJsonPrimitive("name").getAsString(); - JsonPrimitive blockField = object.getAsJsonPrimitive("block"); - boolean block = blockField != null && blockField.getAsBoolean(); + String name = type != MappedLegacyBlockItem.Type.BLOCK ? object.getAsJsonPrimitive("name").getAsString() : null; if (key.indexOf('-') == -1) { int unmappedId; @@ -87,7 +94,7 @@ public abstract class LegacyBlockItemRewriter new MappedLegacyBlockItem(52, (short) -1, null, false)); + MappedLegacyBlockItem data = replacementData.computeIfAbsent(IdAndData.toRawData(52), s -> new MappedLegacyBlockItem(52)); data.setBlockEntityHandler((b, tag) -> { EntityIdRewriter.toClientSpawner(tag, true); return tag; diff --git a/common/src/main/resources/assets/viabackwards/data/item-mappings-1.10.json b/common/src/main/resources/assets/viabackwards/data/item-mappings-1.10.json index 909adbf5..3fc636c2 100644 --- a/common/src/main/resources/assets/viabackwards/data/item-mappings-1.10.json +++ b/common/src/main/resources/assets/viabackwards/data/item-mappings-1.10.json @@ -1,33 +1,32 @@ { - "255": { - "id": 217, - "name": "1.10 Structure Block" + "items": { + "255": { + "id": 217, + "name": "1.10 Structure Block" + } }, - "217": { - "id": 287, - "name": "1.10 Structure Void", - "block": true - }, - "213": { - "id": 159, - "data": 1, - "name": "1.10 Magma Block", - "block": true - }, - "214": { - "id": 159, - "data": 14, - "name": "1.10 Nether Wart Block", - "block": true - }, - "215": { - "id": 112, - "name": "1.10 Red Nether Bricks", - "block": true - }, - "216": { - "id": 155, - "name": "1.10 Bone Block", - "block": true + "block-items": { + "217": { + "id": 287, + "name": "1.10 Structure Void" + }, + "213": { + "id": 159, + "data": 1, + "name": "1.10 Magma Block" + }, + "214": { + "id": 159, + "data": 14, + "name": "1.10 Nether Wart Block" + }, + "215": { + "id": 112, + "name": "1.10 Red Nether Bricks" + }, + "216": { + "id": 155, + "name": "1.10 Bone Block" + } } } \ No newline at end of file diff --git a/common/src/main/resources/assets/viabackwards/data/item-mappings-1.11.1.json b/common/src/main/resources/assets/viabackwards/data/item-mappings-1.11.1.json index 2c29ef68..44821667 100644 --- a/common/src/main/resources/assets/viabackwards/data/item-mappings-1.11.1.json +++ b/common/src/main/resources/assets/viabackwards/data/item-mappings-1.11.1.json @@ -1,6 +1,8 @@ { - "452": { - "id": 265, - "name": "1.11.1 Iron Nugget" + "items": { + "452": { + "id": 265, + "name": "1.11.1 Iron Nugget" + } } } \ No newline at end of file diff --git a/common/src/main/resources/assets/viabackwards/data/item-mappings-1.11.json b/common/src/main/resources/assets/viabackwards/data/item-mappings-1.11.json index 1c81065c..8af61941 100644 --- a/common/src/main/resources/assets/viabackwards/data/item-mappings-1.11.json +++ b/common/src/main/resources/assets/viabackwards/data/item-mappings-1.11.json @@ -1,21 +1,23 @@ { - "218": { - "id": 23, - "data": -1, - "name": "1.11 Observer", - "block": true + "items": { + "449": { + "id": 418, + "name": "1.11 Totem of Undying" + }, + "450": { + "id": 433, + "name": "1.11 Shulker Shell" + } }, - "449": { - "id": 418, - "name": "1.11 Totem of Undying" - }, - "450": { - "id": 433, - "name": "1.11 Shulker Shell" - }, - "219-234": { - "id": 158, - "name": "1.11 %color% Shulker Box", - "block": true + "block-items": { + "218": { + "id": 23, + "data": -1, + "name": "1.11 Observer" + }, + "219-234": { + "id": 158, + "name": "1.11 %color% Shulker Box" + } } } \ No newline at end of file diff --git a/common/src/main/resources/assets/viabackwards/data/item-mappings-1.12.json b/common/src/main/resources/assets/viabackwards/data/item-mappings-1.12.json index f496c075..2710d231 100644 --- a/common/src/main/resources/assets/viabackwards/data/item-mappings-1.12.json +++ b/common/src/main/resources/assets/viabackwards/data/item-mappings-1.12.json @@ -1,27 +1,28 @@ { - "251": { - "id": 159, - "data": -1, - "name": "1.12 %vb_color% Concrete", - "block": true + "items": { + "453": { + "id": 340, + "name": "1.12 Knowledge Book" + }, + "355": { + "id": 355, + "name": "1.12 %vb_color% Bed" + } }, - "252": { - "id": 35, - "data": -1, - "name": "1.12 %vb_color% Concrete Powder", - "block": true - }, - "453": { - "id": 340, - "name": "1.12 Knowledge Book" - }, - "355": { - "id": 355, - "name": "1.12 %vb_color% Bed" - }, - "235-250": { - "id": 159, - "name": "1.12 %color% Glazed Terracotta", - "block": true + "block-items": { + "251": { + "id": 159, + "data": -1, + "name": "1.12 %vb_color% Concrete" + }, + "252": { + "id": 35, + "data": -1, + "name": "1.12 %vb_color% Concrete Powder" + }, + "235-250": { + "id": 159, + "name": "1.12 %color% Glazed Terracotta" + } } } \ No newline at end of file