From 910f5d98dc0d7dbbcb2ddee01f6ae53b03c34eae Mon Sep 17 00:00:00 2001 From: KennyTV Date: Tue, 31 Mar 2020 19:13:41 +0200 Subject: [PATCH] Fix 1.13->1.12.2 enchantment table preview Fixes #192 --- .../viabackwards/api/data/VBMappings.java | 4 ++++ .../Protocol1_12_2To1_13.java | 1 - .../data/BackwardsMappings.java | 2 ++ .../packets/BlockItemPackets1_13.java | 18 ++++++++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/nl/matsv/viabackwards/api/data/VBMappings.java b/core/src/main/java/nl/matsv/viabackwards/api/data/VBMappings.java index 964b8106..3f88a209 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/data/VBMappings.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/data/VBMappings.java @@ -8,6 +8,10 @@ import java.util.Arrays; public class VBMappings extends Mappings { + public VBMappings(JsonObject oldMapping, JsonObject newMapping, boolean warnOnMissing) { + this(oldMapping, newMapping, null, warnOnMissing); + } + public VBMappings(int size, JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping) { this(size, oldMapping, newMapping, diffMapping, true); } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java index 8d0191f7..ae78e85f 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java @@ -92,7 +92,6 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol { out(State.PLAY, 0x11, -1, cancel()); // Declare Commands TODO NEW out(State.PLAY, 0x12, 0x11); // Confirm Transaction (clientbound) out(State.PLAY, 0x13, 0x12); // Close Window (clientbound) - out(State.PLAY, 0x16, 0x15); // Window Property out(State.PLAY, 0x1C, 0x1B); // Entity Status out(State.PLAY, 0x1D, -1, cancel()); // NBT Query Response (client won't send a request, so the server should not answer) out(State.PLAY, 0x1E, 0x1C); // Explosion diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/BackwardsMappings.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/BackwardsMappings.java index ca8fe3b5..a73dce8d 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/BackwardsMappings.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/BackwardsMappings.java @@ -34,6 +34,7 @@ public class BackwardsMappings { public static BlockMappingsShortArray blockMappings; public static VBSoundMappings soundMappings; public static VBItemMappings itemMappings; + public static Mappings enchantmentMappings; public static void init() { JsonObject mapping1_12 = MappingDataLoader.loadData("mapping-1.12.json"); @@ -44,6 +45,7 @@ public class BackwardsMappings { blockMappings = new BlockMappingsShortArray(mapping1_13.getAsJsonObject("blocks"), mapping1_12.getAsJsonObject("blocks"), mapping1_12_2to1_13.getAsJsonObject("blockstates")); itemMappings = new VBItemMappings(mapping1_13.getAsJsonObject("items"), mapping1_12.getAsJsonObject("items"), mapping1_12_2to1_13.getAsJsonObject("items")); soundMappings = new VBSoundMappings(mapping1_13.getAsJsonArray("sounds"), mapping1_12.getAsJsonArray("sounds"), mapping1_12_2to1_13.getAsJsonObject("sounds")); + enchantmentMappings = new VBMappings(mapping1_13.getAsJsonObject("enchantments"), mapping1_12.getAsJsonObject("enchantments"), false); for (Map.Entry entry : StatisticMappings.statistics.entrySet()) { statisticMappings.put(entry.getValue(), entry.getKey()); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java index 2b60a121..f9d0ea8c 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java @@ -470,6 +470,24 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It } }); + // Window Property + protocol.out(State.PLAY, 0x16, 0x15, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.UNSIGNED_BYTE); // Window Id + map(Type.SHORT); // Property + map(Type.SHORT); // Value + handler(wrapper -> { + short property = wrapper.get(Type.SHORT, 0); + // Enchantment table + if (property >= 4 && property <= 6) { + short oldId = wrapper.get(Type.SHORT, 1); + wrapper.set(Type.SHORT, 1, (short) BackwardsMappings.enchantmentMappings.getNewId(oldId)); + } + }); + } + }); + // Set Creative Slot protocol.in(State.PLAY, 0x24, 0x1B, new PacketRemapper() {