From 59a621315b8b82ac5b7df63e7242119b5253940c Mon Sep 17 00:00:00 2001 From: EnZaXD <60033407+FlorianMichael@users.noreply.github.com> Date: Sun, 24 Mar 2024 12:14:51 +0100 Subject: [PATCH] Allow platforms to use BackwardsMappingDataLoader (#701) --- ...ingDataLoader.java => BackwardsMappingDataLoader.java} | 8 ++++---- .../viabackwards/api/data/BackwardsMappings.java | 2 +- .../api/rewriters/LegacyBlockItemRewriter.java | 4 ++-- .../viabackwards/api/rewriters/TranslatableRewriter.java | 4 ++-- .../protocol1_16_1to1_16_2/data/BiomeMappings.java | 4 ++-- .../protocol1_18_2to1_19/data/BackwardsMappings.java | 4 ++-- .../protocol1_19_1to1_19_3/data/BackwardsMappings.java | 4 ++-- .../protocol1_19_4to1_20/data/BackwardsMappings.java | 4 ++-- .../protocol1_20_3to1_20_5/data/BackwardsMappings.java | 4 ++-- 9 files changed, 19 insertions(+), 19 deletions(-) rename common/src/main/java/com/viaversion/viabackwards/api/data/{VBMappingDataLoader.java => BackwardsMappingDataLoader.java} (89%) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/data/VBMappingDataLoader.java b/common/src/main/java/com/viaversion/viabackwards/api/data/BackwardsMappingDataLoader.java similarity index 89% rename from common/src/main/java/com/viaversion/viabackwards/api/data/VBMappingDataLoader.java rename to common/src/main/java/com/viaversion/viabackwards/api/data/BackwardsMappingDataLoader.java index 5b23f440..0f6924f6 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/data/VBMappingDataLoader.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/data/BackwardsMappingDataLoader.java @@ -26,12 +26,12 @@ import java.io.IOException; import java.util.Map; import org.checkerframework.checker.nullness.qual.Nullable; -public class VBMappingDataLoader extends MappingDataLoader { +public class BackwardsMappingDataLoader extends MappingDataLoader { - public static final VBMappingDataLoader INSTANCE = new VBMappingDataLoader(); + public static final BackwardsMappingDataLoader INSTANCE = new BackwardsMappingDataLoader(BackwardsMappingDataLoader.class, "assets/viabackwards/data/"); - public VBMappingDataLoader() { - super(VBMappingDataLoader.class, "assets/viabackwards/data/"); + public BackwardsMappingDataLoader(final Class dataLoaderClass, final String dataPath) { + super(dataLoaderClass, dataPath); } @Override 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 4347306c..5ecd95fe 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 @@ -168,6 +168,6 @@ public class BackwardsMappings extends MappingDataBase { @Override protected @Nullable CompoundTag readMappingsFile(final String name) { - return VBMappingDataLoader.INSTANCE.loadNBTFromDir(name); + return BackwardsMappingDataLoader.INSTANCE.loadNBTFromDir(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 fa74708c..18e6444c 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 @@ -20,7 +20,7 @@ package com.viaversion.viabackwards.api.rewriters; import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.data.MappedLegacyBlockItem; -import com.viaversion.viabackwards.api.data.VBMappingDataLoader; +import com.viaversion.viabackwards.api.data.BackwardsMappingDataLoader; import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.BlockColors; import com.viaversion.viabackwards.utils.Block; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; @@ -52,7 +52,7 @@ public abstract class LegacyBlockItemRewriter replacementData; // Raw id -> mapped data static { - JsonObject jsonObject = VBMappingDataLoader.INSTANCE.loadFromDataDir("legacy-mappings.json"); + JsonObject jsonObject = BackwardsMappingDataLoader.INSTANCE.loadFromDataDir("legacy-mappings.json"); for (Map.Entry entry : jsonObject.entrySet()) { Int2ObjectMap mappings = new Int2ObjectOpenHashMap<>(8); LEGACY_MAPPINGS.put(entry.getKey(), mappings); diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/TranslatableRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/TranslatableRewriter.java index 7eda082c..1dd778fa 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/TranslatableRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/TranslatableRewriter.java @@ -19,7 +19,7 @@ package com.viaversion.viabackwards.api.rewriters; import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.api.BackwardsProtocol; -import com.viaversion.viabackwards.api.data.VBMappingDataLoader; +import com.viaversion.viabackwards.api.data.BackwardsMappingDataLoader; import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.libs.gson.JsonElement; import com.viaversion.viaversion.libs.gson.JsonObject; @@ -34,7 +34,7 @@ public class TranslatableRewriter extends Compo private final Map translatables; public static void loadTranslatables() { - final JsonObject jsonObject = VBMappingDataLoader.INSTANCE.loadFromDataDir("translation-mappings.json"); + final JsonObject jsonObject = BackwardsMappingDataLoader.INSTANCE.loadFromDataDir("translation-mappings.json"); for (final Map.Entry entry : jsonObject.entrySet()) { final Map versionMappings = new HashMap<>(); TRANSLATABLES.put(entry.getKey(), versionMappings); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/data/BiomeMappings.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/data/BiomeMappings.java index f2b2afd9..33c53700 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/data/BiomeMappings.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/data/BiomeMappings.java @@ -18,7 +18,7 @@ package com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.data; import com.viaversion.viabackwards.ViaBackwards; -import com.viaversion.viabackwards.api.data.VBMappingDataLoader; +import com.viaversion.viabackwards.api.data.BackwardsMappingDataLoader; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.libs.fastutil.objects.Object2IntMap; import com.viaversion.viaversion.libs.fastutil.objects.Object2IntOpenHashMap; @@ -117,7 +117,7 @@ public final class BiomeMappings { MODERN_TO_LEGACY_ID.put(entry.getKey(), entry.getIntValue()); } - final JsonObject mappings = VBMappingDataLoader.INSTANCE.loadFromDataDir("biome-mappings.json"); + final JsonObject mappings = BackwardsMappingDataLoader.INSTANCE.loadFromDataDir("biome-mappings.json"); for (final Map.Entry entry : mappings.entrySet()) { final int legacyBiome = LEGACY_BIOMES.getInt(entry.getValue().getAsString()); if (legacyBiome == -1) { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/data/BackwardsMappings.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/data/BackwardsMappings.java index 681f2ee6..0f513b29 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/data/BackwardsMappings.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/data/BackwardsMappings.java @@ -17,7 +17,7 @@ */ package com.viaversion.viabackwards.protocol.protocol1_18_2to1_19.data; -import com.viaversion.viabackwards.api.data.VBMappingDataLoader; +import com.viaversion.viabackwards.api.data.BackwardsMappingDataLoader; import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; @@ -38,7 +38,7 @@ public final class BackwardsMappings extends com.viaversion.viabackwards.api.dat protected void loadExtras(final CompoundTag data) { super.loadExtras(data); - final ListTag chatTypes = VBMappingDataLoader.INSTANCE.loadNBT("chat-types-1.19.1.nbt").getListTag("values", CompoundTag.class); + final ListTag chatTypes = BackwardsMappingDataLoader.INSTANCE.loadNBT("chat-types-1.19.1.nbt").getListTag("values", CompoundTag.class); for (final CompoundTag chatType : chatTypes) { final NumberTag idTag = chatType.getNumberTag("id"); defaultChatTypes.put(idTag.asInt(), chatType); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/data/BackwardsMappings.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/data/BackwardsMappings.java index ab561c9b..cf47d6ed 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/data/BackwardsMappings.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/data/BackwardsMappings.java @@ -17,7 +17,7 @@ */ package com.viaversion.viabackwards.protocol.protocol1_19_1to1_19_3.data; -import com.viaversion.viabackwards.api.data.VBMappingDataLoader; +import com.viaversion.viabackwards.api.data.BackwardsMappingDataLoader; import com.viaversion.viaversion.libs.fastutil.objects.Object2IntMap; import com.viaversion.viaversion.libs.fastutil.objects.Object2IntOpenHashMap; import com.viaversion.viaversion.libs.gson.JsonArray; @@ -39,7 +39,7 @@ public final class BackwardsMappings extends com.viaversion.viabackwards.api.dat protected void loadExtras(final CompoundTag data) { super.loadExtras(data); - final JsonArray sounds = VBMappingDataLoader.INSTANCE.loadData("sounds-1.19.json").getAsJsonArray("sounds"); + final JsonArray sounds = BackwardsMappingDataLoader.INSTANCE.loadData("sounds-1.19.json").getAsJsonArray("sounds"); int i = 0; for (final JsonElement sound : sounds) { mappedSounds.put(sound.getAsString(), i++); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/data/BackwardsMappings.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/data/BackwardsMappings.java index 33f03732..d246e6fd 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/data/BackwardsMappings.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/data/BackwardsMappings.java @@ -17,7 +17,7 @@ */ package com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.data; -import com.viaversion.viabackwards.api.data.VBMappingDataLoader; +import com.viaversion.viabackwards.api.data.BackwardsMappingDataLoader; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.protocols.protocol1_20to1_19_4.Protocol1_20To1_19_4; @@ -33,7 +33,7 @@ public class BackwardsMappings extends com.viaversion.viabackwards.api.data.Back protected void loadExtras(CompoundTag data) { super.loadExtras(data); - trimPatternRegistry = VBMappingDataLoader.INSTANCE.loadNBT("trim_pattern-1.19.4.nbt"); + trimPatternRegistry = BackwardsMappingDataLoader.INSTANCE.loadNBT("trim_pattern-1.19.4.nbt"); } public CompoundTag getTrimPatternRegistry() { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/data/BackwardsMappings.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/data/BackwardsMappings.java index a16d574c..84d3c36d 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/data/BackwardsMappings.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/data/BackwardsMappings.java @@ -17,7 +17,7 @@ */ package com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.data; -import com.viaversion.viabackwards.api.data.VBMappingDataLoader; +import com.viaversion.viabackwards.api.data.BackwardsMappingDataLoader; import com.viaversion.viaversion.libs.gson.JsonArray; import com.viaversion.viaversion.libs.gson.JsonElement; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; @@ -36,7 +36,7 @@ public final class BackwardsMappings extends com.viaversion.viabackwards.api.dat protected void loadExtras(final CompoundTag data) { super.loadExtras(data); - final JsonArray sounds = VBMappingDataLoader.INSTANCE.loadData("sounds-1.20.3.json").getAsJsonArray("sounds"); + final JsonArray sounds = BackwardsMappingDataLoader.INSTANCE.loadData("sounds-1.20.3.json").getAsJsonArray("sounds"); this.sounds = new String[sounds.size()]; int i = 0; for (final JsonElement sound : sounds) {