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 714c0944d..0615bb726 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 @@ -5,13 +5,12 @@ import com.google.common.collect.HashBiMap; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import io.netty.util.collection.IntObjectHashMap; -import io.netty.util.collection.IntObjectMap; import us.myles.ViaVersion.util.GsonUtil; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -30,13 +29,7 @@ public class MappingData { // TODO: Remove how verbose this is System.out.println("Loading block mapping..."); - try { - Class.forName("io.netty.util.collection.IntObjectMap"); - blockMappings = new BMNettyCollections(); - } catch (ClassNotFoundException e) { - blockMappings = new BMJDKCollections(); - } - blockMappings.init(mapping1_12, mapping1_13); + blockMappings = new BlockMappingsShortArray(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..."); @@ -124,47 +117,32 @@ 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())); + private static void mapIdentifiers(short[] 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[Integer.parseInt(entry.getKey())] = Short.parseShort(value.getKey()); + } + } + + public interface BlockMappings { + short getNewBlock(int old); + } + + private static class BlockMappingsShortArray implements BlockMappings { + private short[] oldToNew = new short[4084]; + + private BlockMappingsShortArray(JsonObject mapping1_12, JsonObject mapping1_13) { + Arrays.fill(oldToNew, (short) -1); + mapIdentifiers(oldToNew, mapping1_12.getAsJsonObject("blocks"), mapping1_13.getAsJsonObject("blocks")); + } + + @Override + public short getNewBlock(int old) { + return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1; } } } 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 0920d1d14..10fcd78c8 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 @@ -339,12 +339,12 @@ public class WorldPackets { } public static int toNewId(int oldId) { - Integer newId = MappingData.blockMappings.getNewBlock(oldId); - if (newId != null) { + short newId = MappingData.blockMappings.getNewBlock(oldId); + if (newId != -1) { return newId; } newId = MappingData.blockMappings.getNewBlock(oldId & ~0xF); // Remove data - if (newId != null) { + if (newId != -1) { System.out.println("Missing block " + oldId); return newId; } diff --git a/pom.xml b/pom.xml index 98aaa200e..009961095 100644 --- a/pom.xml +++ b/pom.xml @@ -95,12 +95,10 @@ - - io.netty netty-all - 4.0.23.Final + 4.0.20.Final provided true