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 ede670f54..e41bdb500 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 @@ -198,7 +198,7 @@ public class Protocol1_13To1_12_2 extends Protocol { registerOutgoing(State.PLAY, 0x12, 0x13); registerOutgoing(State.PLAY, 0x13, 0x14); // InventoryPackets 0x14 -> 0x15 - registerOutgoing(State.PLAY, 0x15, 0x16); + // InventoryPackets 0x15 -> 0x16 // InventoryPackets 0x16 -> 0x17 registerOutgoing(State.PLAY, 0x17, 0x18); // WorldPackets 0x18 -> 0x19 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 3443a3d9f..92fd44f30 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 @@ -21,6 +21,7 @@ public class MappingData { public static Map itemTags = new HashMap<>(); public static Map fluidTags = new HashMap<>(); public static BiMap oldEnchantmentsIds = HashBiMap.create(); + public static EnchantmentMappings enchantmentMappings; public static SoundMappings soundMappings; public static BlockMappings blockMappings; @@ -38,6 +39,7 @@ public class MappingData { loadTags(fluidTags, mapping1_13.getAsJsonObject("fluid_tags")); Via.getPlatform().getLogger().info("Loading enchantments..."); loadEnchantments(oldEnchantmentsIds, mapping1_12.getAsJsonObject("enchantments")); + enchantmentMappings = new EnchantmentMappingByteArray(mapping1_12.getAsJsonObject("enchantments"), mapping1_13.getAsJsonObject("enchantments")); Via.getPlatform().getLogger().info("Loading sound mapping..."); soundMappings = new SoundMappingShortArray(mapping1_12.getAsJsonArray("sounds"), mapping1_13.getAsJsonArray("sounds")); } @@ -68,6 +70,40 @@ public class MappingData { } } + 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) { + Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( "); + continue; + } + output[Integer.parseInt(entry.getKey())] = Short.parseShort(value.getKey()); + } + } + + private static void mapIdentifiers(byte[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers) { + for (Map.Entry entry : oldIdentifiers.entrySet()) { + Map.Entry value = findValue(newIdentifiers, entry.getValue().getAsString()); + if (value == null) { + Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( "); + continue; + } + output[Integer.parseInt(entry.getKey())] = Byte.parseByte(value.getKey()); + } + } + + 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()); + if (index == null) { + Via.getPlatform().getLogger().warning("No key for " + v + " :( "); + continue; + } + output[i] = index.shortValue(); + } + } + private static void loadTags(Map output, JsonObject newTags) { for (Map.Entry entry : newTags.entrySet()) { JsonArray ids = entry.getValue().getAsJsonArray(); @@ -79,24 +115,12 @@ public class MappingData { } } - public static void loadEnchantments(Map output, JsonObject enchantments) { + private static void loadEnchantments(Map output, JsonObject enchantments) { for (Map.Entry enchantment : enchantments.entrySet()) { output.put(Short.parseShort(enchantment.getKey()), enchantment.getValue().getAsString()); } } - private static void mapIdentifiers(Map output, JsonArray oldIdentifiers, JsonArray newIdentifiers) { - for (int i = 0; i < oldIdentifiers.size(); i++) { - JsonElement v = oldIdentifiers.get(i); - Integer index = findIndex(newIdentifiers, v.getAsString()); - if (index == null) { - Via.getPlatform().getLogger().warning("No key for " + v + " :( "); - continue; - } - output.put(i, index); - } - } - private static Map.Entry findValue(JsonObject object, String needle) { for (Map.Entry entry : object.entrySet()) { String value = entry.getValue().getAsString(); @@ -121,29 +145,6 @@ public class MappingData { int getNewBlock(int old); } - 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) { - Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( "); - continue; - } - output[Integer.parseInt(entry.getKey())] = Short.parseShort(value.getKey()); - } - } - - 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()); - if (index == null) { - Via.getPlatform().getLogger().warning("No key for " + v + " :( "); - continue; - } - output[i] = index.shortValue(); - } - } - private static class BlockMappingsShortArray implements BlockMappings { private short[] oldToNew = new short[4084]; @@ -175,4 +176,22 @@ public class MappingData { return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1; } } + + public interface EnchantmentMappings { + int getNewEnchantment(int old); + } + + private static class EnchantmentMappingByteArray implements EnchantmentMappings { + private byte[] oldToNew = new byte[72]; + + private EnchantmentMappingByteArray(JsonObject m1_12, JsonObject m1_13) { + Arrays.fill(oldToNew, (byte) -1); + mapIdentifiers(oldToNew, m1_12, m1_13); + } + + @Override + public int getNewEnchantment(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/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java index 7ddd1688b..574d6704b 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java @@ -67,6 +67,26 @@ public class InventoryPackets { } }); + // Window property + protocol.registerOutgoing(State.PLAY, 0x15, 0x16, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.UNSIGNED_BYTE); // Window id + map(Type.SHORT); // Property + map(Type.SHORT); // Value + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + short property = wrapper.get(Type.SHORT, 0); + if (property >= 4 && property <= 6) { // Enchantment id + wrapper.set(Type.SHORT, 1, (short) MappingData.enchantmentMappings.getNewEnchantment( + wrapper.get(Type.SHORT, 1) + )); + } + } + }); + } + }); // Plugin message Packet -> Trading protocol.registerOutgoing(State.PLAY, 0x18, 0x19, new PacketRemapper() { diff --git a/common/src/main/resources/assets/viaversion/data/mapping-1.13.json b/common/src/main/resources/assets/viaversion/data/mapping-1.13.json index 1c0175296..6d8194e8e 100644 --- a/common/src/main/resources/assets/viaversion/data/mapping-1.13.json +++ b/common/src/main/resources/assets/viaversion/data/mapping-1.13.json @@ -10705,5 +10705,41 @@ "ui.toast.out", "weather.rain", "weather.rain.above" - ] + ], + "enchantments": { + "0": "minecraft:protection", + "1": "minecraft:fire_protection", + "2": "minecraft:feather_falling", + "3": "minecraft:blast_protection", + "4": "minecraft:projectile_protection", + "5": "minecraft:respiration", + "6": "minecraft:aqua_affinity", + "7": "minecraft:thorns", + "8": "minecraft:depth_strider", + "9": "minecraft:frost_walker", + "10": "minecraft:binding_curse", + "11": "minecraft:sharpness", + "12": "minecraft:smite", + "13": "minecraft:bane_of_arthropods", + "14": "minecraft:knockback", + "15": "minecraft:fire_aspect", + "16": "minecraft:looting", + "17": "minecraft:sweeping", + "18": "minecraft:efficiency", + "19": "minecraft:silk_touch", + "20": "minecraft:unbreaking", + "21": "minecraft:fortune", + "22": "minecraft:power", + "23": "minecraft:punch", + "24": "minecraft:flame", + "25": "minecraft:infinity", + "26": "minecraft:luck_of_the_sea", + "27": "minecraft:lure", + "28": "minecraft:loyalty", + "29": "minecraft:impaling", + "30": "minecraft:riptide", + "31": "minecraft:channeling", + "32": "minecraft:mending", + "33": "minecraft:vanishing_curse" + } } \ No newline at end of file