From c709b019e195f9612c5d213c6e79b484ec651b0a Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Mon, 6 Aug 2018 15:30:36 -0300 Subject: [PATCH 1/3] Use ChatRewriter.legacyTextToJson in metadata rewriting --- .../protocols/protocol1_13to1_12_2/MetadataRewriter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/MetadataRewriter.java index 0a59e1dc6..38e9e7dcc 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/MetadataRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/MetadataRewriter.java @@ -28,7 +28,7 @@ public class MetadataRewriter { if (metadata.getId() == 2) { metadata.setMetaType(MetaType1_13.OptChat); if (metadata.getValue() != null && !((String) metadata.getValue()).isEmpty()) { - metadata.setValue(Protocol1_9TO1_8.fixJson((String) metadata.getValue())); + metadata.setValue(ChatRewriter.legacyTextToJson((String) metadata.getValue())); } else { metadata.setValue(null); } From e39876ae676b0d47923432b9b914ef8c309f47f1 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Sat, 11 Aug 2018 06:54:38 -0300 Subject: [PATCH 2/3] Use unpowered note block --- .../protocols/protocol1_13to1_12_2/packets/WorldPackets.java | 2 +- .../src/main/resources/assets/viaversion/data/mapping-1.12.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 8b762f8e3..d8378e077 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 @@ -152,7 +152,7 @@ public class WorldPackets { if (blockId == 73) { // Note block PacketWrapper blockChange = wrapper.create(0x0B); // block change blockChange.write(Type.POSITION, new Position(pos.getX(), pos.getY(), pos.getZ())); // Clone because position is mutable - blockChange.write(Type.VAR_INT, 248 + (action * 24 * 2) + (param * 2)); + blockChange.write(Type.VAR_INT, 249 + (action * 24 * 2) + (param * 2)); blockChange.send(Protocol1_13To1_12_2.class, true, true); } wrapper.set(Type.VAR_INT, 0, blockId); diff --git a/common/src/main/resources/assets/viaversion/data/mapping-1.12.json b/common/src/main/resources/assets/viaversion/data/mapping-1.12.json index f923bb0c2..120eebfde 100644 --- a/common/src/main/resources/assets/viaversion/data/mapping-1.12.json +++ b/common/src/main/resources/assets/viaversion/data/mapping-1.12.json @@ -154,7 +154,7 @@ "384": "minecraft:sandstone", "385": "minecraft:chiseled_sandstone", "386": "minecraft:cut_sandstone", - "400": "minecraft:note_block[instrument=harp,note=0,powered=true]", + "400": "minecraft:note_block[instrument=harp,note=0,powered=false]", "416": "minecraft:red_bed[facing=south,occupied=false,part=foot]", "417": "minecraft:red_bed[facing=west,occupied=false,part=foot]", "418": "minecraft:red_bed[facing=north,occupied=false,part=foot]", From 12e2f8b35a614e4f868b742c730640b45cc0ea3a Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Sun, 12 Aug 2018 09:56:39 -0300 Subject: [PATCH 3/3] Make enchanting table show the enchantment correctly --- .../Protocol1_13To1_12_2.java | 2 +- .../data/MappingData.java | 91 +++++++++++-------- .../packets/InventoryPackets.java | 20 ++++ .../assets/viaversion/data/mapping-1.13.json | 38 +++++++- 4 files changed, 113 insertions(+), 38 deletions(-) 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