diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java index 67759eadb..e27eaddad 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java @@ -840,7 +840,7 @@ public class Protocol1_13To1_12_2 extends Protocol { } private int getNewSoundID(final int oldID) { - return MappingData.oldToNewSounds.get(oldID); + return MappingData.blockMappings.getNewBlock(oldID); } // Based on method from https://github.com/Bukkit/Bukkit/blob/master/src/main/java/org/bukkit/ChatColor.java 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 0615bb726..bba17797e 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 @@ -20,7 +20,7 @@ public class MappingData { 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 SoundMappings soundMappings; public static BlockMappings blockMappings; public static void init() { @@ -29,7 +29,7 @@ public class MappingData { // TODO: Remove how verbose this is System.out.println("Loading block mapping..."); - blockMappings = new BlockMappingsShortArray(mapping1_12, mapping1_13); + blockMappings = new BlockMappingsShortArray(mapping1_12.getAsJsonObject("blocks"), mapping1_13.getAsJsonObject("blocks")); System.out.println("Loading item mapping..."); mapIdentifiers(oldToNewItems, mapping1_12.getAsJsonObject("items"), mapping1_13.getAsJsonObject("items")); System.out.println("Loading new tags..."); @@ -39,7 +39,7 @@ public class MappingData { System.out.println("Loading enchantments..."); loadEnchantments(oldEnchantmentsIds, mapping1_12.getAsJsonObject("enchantments")); System.out.println("Loading sound mapping..."); - mapIdentifiers(oldToNewSounds, mapping1_12.getAsJsonArray("sounds"), mapping1_13.getAsJsonArray("sounds")); + soundMappings = new SoundMappingShortArray(mapping1_12.getAsJsonArray("sounds"), mapping1_13.getAsJsonArray("sounds")); } private static void mapIdentifiers(Map output, JsonObject oldIdentifiers, JsonObject newIdentifiers) { @@ -63,7 +63,7 @@ public class MappingData { return null; } - private static void mapIdentifiers(Map output, JsonArray oldIdentifiers, JsonArray newIdentifiers) { + private static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers) { for (int i = 0; i < oldIdentifiers.size(); i++) { JsonElement v = oldIdentifiers.get(i); Integer index = findIndex(newIdentifiers, v.getAsString()); @@ -71,7 +71,7 @@ public class MappingData { System.out.println("No key for " + v + " :( "); continue; } - output.put(i, index); + output[i] = index.shortValue(); } } @@ -129,7 +129,7 @@ public class MappingData { } public interface BlockMappings { - short getNewBlock(int old); + int getNewBlock(int old); } private static class BlockMappingsShortArray implements BlockMappings { @@ -137,11 +137,29 @@ public class MappingData { private BlockMappingsShortArray(JsonObject mapping1_12, JsonObject mapping1_13) { Arrays.fill(oldToNew, (short) -1); - mapIdentifiers(oldToNew, mapping1_12.getAsJsonObject("blocks"), mapping1_13.getAsJsonObject("blocks")); + mapIdentifiers(oldToNew, mapping1_12, mapping1_13); } @Override - public short getNewBlock(int old) { + public int getNewBlock(int old) { + return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1; + } + } + + public interface SoundMappings { + int getNewSound(int old); + } + + private static class SoundMappingShortArray implements SoundMappings { + private short[] oldToNew = new short[662]; + + private SoundMappingShortArray(JsonArray mapping1_12, JsonArray mapping1_13) { + Arrays.fill(oldToNew, (short) -1); + mapIdentifiers(oldToNew, mapping1_12, mapping1_13); + } + + @Override + public int getNewSound(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 10fcd78c8..431eb687f 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,7 +339,7 @@ public class WorldPackets { } public static int toNewId(int oldId) { - short newId = MappingData.blockMappings.getNewBlock(oldId); + int newId = MappingData.blockMappings.getNewBlock(oldId); if (newId != -1) { return newId; }