diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java index b86c5db17..0fdc09051 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java @@ -16,13 +16,13 @@ import java.util.HashMap; import java.util.Map; public class MappingData { - public static IntObjectMap oldToNewBlocks = new IntObjectHashMap<>(); public static BiMap oldToNewItems = HashBiMap.create(); public static Map blockTags = new HashMap<>(); public static Map itemTags = new HashMap<>(); public static Map fluidTags = new HashMap<>(); public static BiMap oldEnchantmentsIds = HashBiMap.create(); public static Map oldToNewSounds = new HashMap<>(); + public static BlockMappings blockMappings; public static void init() { JsonObject mapping1_12 = loadData("mapping-1.12.json"); @@ -30,7 +30,12 @@ public class MappingData { // TODO: Remove how verbose this is System.out.println("Loading block mapping..."); - mapIdentifiers(oldToNewBlocks, mapping1_12.getAsJsonObject("blocks"), mapping1_13.getAsJsonObject("blocks")); + try { + blockMappings = new BMNettyCollections(); + } catch (NoClassDefFoundError e) { + blockMappings = new BMJDKCollections(); + } + blockMappings.init(mapping1_12, mapping1_13); System.out.println("Loading item mapping..."); mapIdentifiers(oldToNewItems, mapping1_12.getAsJsonObject("items"), mapping1_13.getAsJsonObject("items")); System.out.println("Loading new tags..."); @@ -54,17 +59,6 @@ public class MappingData { } } - private static void mapIdentifiers(IntObjectMap output, JsonObject oldIdentifiers, JsonObject newIdentifiers) { - for (Map.Entry entry : oldIdentifiers.entrySet()) { - Map.Entry value = findValue(newIdentifiers, entry.getValue().getAsString()); - if (value == null) { - System.out.println("No key for " + entry.getValue() + " :( "); - continue; - } - output.put(Integer.parseInt(entry.getKey()), Integer.parseInt(value.getKey())); - } - } - private static Map.Entry findValue(JsonObject object, String needle) { for (Map.Entry entry : object.entrySet()) { String value = entry.getValue().getAsString(); @@ -128,4 +122,48 @@ public class MappingData { } } } + + public interface BlockMappings { + void init(JsonObject mapping1_12, JsonObject mapping1_13); + Integer getNewBlock(int old); + } + + private static class BMJDKCollections implements BlockMappings { + private Map oldToNew = new HashMap<>(); + + @Override + public void init(JsonObject mapping1_12, JsonObject mapping1_13) { + mapIdentifiers(oldToNew, mapping1_12.getAsJsonObject("blocks"), mapping1_13.getAsJsonObject("blocks")); + } + + @Override + public Integer getNewBlock(int old) { + return oldToNew.get(old); + } + } + + private static class BMNettyCollections implements BlockMappings { + private IntObjectMap oldToNew = new IntObjectHashMap<>(); + + @Override + public void init(JsonObject mapping1_12, JsonObject mapping1_13) { + mapIdentifiers(oldToNew, mapping1_12.getAsJsonObject("blocks"), mapping1_13.getAsJsonObject("blocks")); + } + + @Override + public Integer getNewBlock(int old) { + return oldToNew.get(old); + } + + private static void mapIdentifiers(IntObjectMap output, JsonObject oldIdentifiers, JsonObject newIdentifiers) { + for (Map.Entry entry : oldIdentifiers.entrySet()) { + Map.Entry value = findValue(newIdentifiers, entry.getValue().getAsString()); + if (value == null) { + System.out.println("No key for " + entry.getValue() + " :( "); + continue; + } + output.put(Integer.parseInt(entry.getKey()), Integer.parseInt(value.getKey())); + } + } + } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java index fcf898dca..788ac54f4 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java @@ -256,11 +256,11 @@ public class WorldPackets { } public static int toNewId(int oldId) { - Integer newId = MappingData.oldToNewBlocks.get(oldId); + Integer newId = MappingData.blockMappings.getNewBlock(oldId); if (newId != null) { return newId; } - newId = MappingData.oldToNewBlocks.get(oldId & ~0xF); // Remove data + newId = MappingData.blockMappings.getNewBlock(oldId & ~0xF); // Remove data if (newId != null) { System.out.println("Missing block " + oldId); return newId; diff --git a/pom.xml b/pom.xml index 91a1f9e2f..7b33e133f 100644 --- a/pom.xml +++ b/pom.xml @@ -95,10 +95,12 @@ + + io.netty netty-all - 4.0.23.Final + 4.0.23.Final provided true