From b9a2404f9ce49f7fa265effa437b6dc5d5ebd77e Mon Sep 17 00:00:00 2001 From: Gerrygames Date: Wed, 16 Jan 2019 12:47:30 +0100 Subject: [PATCH] some more progress on 1.13 --- .../Protocol1_12_2To1_13.java | 44 ++-- .../data/PaintingMapping.java | 45 ++++ .../packets/BlockItemPackets1_13.java | 193 +++++++++++++++++- .../packets/EntityPackets1_13.java | 40 ++++ .../packets/PlayerPacket1_13.java | 89 ++++++++ .../packets/InventoryPackets.java | 2 +- 6 files changed, 385 insertions(+), 28 deletions(-) create mode 100644 core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/PaintingMapping.java create mode 100644 core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java create mode 100644 core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java 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 dd04b730..95f445b3 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 @@ -12,7 +12,10 @@ package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13; import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.BackwardsMappings; +import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.PaintingMapping; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.BlockItemPackets1_13; +import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.EntityPackets1_13; +import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.PlayerPacket1_13; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.remapper.PacketHandler; @@ -25,31 +28,30 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol { @Override protected void registerPackets() { new BlockItemPackets1_13().register(this); + new EntityPackets1_13().register(this); + new PlayerPacket1_13().register(this); // Thanks to https://wiki.vg/index.php?title=Pre-release_protocol&oldid=14150 - out(State.PLAY, 0x00, 0x00, cancel()); - out(State.PLAY, 0x04, 0x04, cancel());// Spawn Painting TODO MODIFIED + out(State.PLAY, 0x00, 0x00, cancel()); // Spawn Object TODO type ids + out(State.PLAY, 0x03, 0x03, cancel()); // Spawn Mob TODO Metadata, type ids out(State.PLAY, 0x07, 0x07, cancel()); // Statistics TODO MODIFIED out(State.PLAY, 0x09, 0x09, cancel()); // Update Block Entity TODO MODIFIED - out(State.PLAY, 0x0B, 0x0B, cancel()); // Block Change TODO MODIFIED out(State.PLAY, 0x0E, 0x0F); // Chat Message (clientbound) out(State.PLAY, 0x0F, 0x10, cancel()); // Multi Block Change TODO MODIFIED out(State.PLAY, 0x10, 0x0E, cancel()); // Tab-Complete (clientbound) TODO MODIFIED out(State.PLAY, 0x11, -1, cancel()); // Declare Commands TODO NEW - out(State.PLAY, 0x12, 0x11, cancel()); // Confirm Transaction (clientbound) - out(State.PLAY, 0x13, 0x12, cancel()); // Close Window (clientbound) - out(State.PLAY, 0x14, 0x13, cancel()); // Open Window - out(State.PLAY, 0x15, 0x14, cancel()); // Window Items - out(State.PLAY, 0x16, 0x15, cancel()); // Window Property - out(State.PLAY, 0x17, 0x16, cancel()); // Set Slot - out(State.PLAY, 0x18, 0x17); // Set Cooldown + out(State.PLAY, 0x12, 0x11); // Confirm Transaction (clientbound) + out(State.PLAY, 0x13, 0x12); // Close Window (clientbound) + out(State.PLAY, 0x14, 0x13); // Open Window + out(State.PLAY, 0x16, 0x15); // Window Property + out(State.PLAY, 0x18, 0x17); // Set Cooldown out(State.PLAY, 0x19, 0x18); // Plugin Message (clientbound) TODO MODIFIED out(State.PLAY, 0x1A, 0x19, cancel()); // Named Sound Effect TODO MODIFIED out(State.PLAY, 0x1B, 0x1A); // Disconnect (play) out(State.PLAY, 0x1C, 0x1B); // Entity Status - out(State.PLAY, 0x1D, -1, cancel()); // NBT Query Response TODO NEW + 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 out(State.PLAY, 0x1F, 0x1D); // Unload Chunk out(State.PLAY, 0x20, 0x1E); // Change Game State @@ -59,7 +61,6 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol { - out(State.PLAY, 0x23, 0x21, cancel()); // Effect TODO MODIFIED out(State.PLAY, 0x24, 0x22, cancel()); // Spawn Particle TODO MODIFIED out(State.PLAY, 0x25, 0x23, new PacketRemapper() { @Override @@ -78,7 +79,6 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol { }); } }); // Join Game - out(State.PLAY, 0x26, 0x24, cancel()); // Map TODO MODIFIED out(State.PLAY, 0x27, 0x25); // Entity out(State.PLAY, 0x28, 0x26); // Entity Relative Move out(State.PLAY, 0x29, 0x27); // Entity Look And Relative Move @@ -101,17 +101,14 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol { out(State.PLAY, 0x3A, 0x37); // Select Advancement Tab out(State.PLAY, 0x3B, 0x38); // World Border out(State.PLAY, 0x3C, 0x39); // Camera - out(State.PLAY, 0x3D, 0x3A, cancel()); // Held Item Change (clientbound) + out(State.PLAY, 0x3D, 0x3A); // Held Item Change (clientbound) out(State.PLAY, 0x3E, 0x3B); // Display Scoreboard out(State.PLAY, 0x3F, 0x3C, cancel()); // Entity Metadata out(State.PLAY, 0x40, 0x3D); // Attach Entity out(State.PLAY, 0x41, 0x3E); // Entity Velocity - out(State.PLAY, 0x42, 0x3F, cancel()); // Entity Equipment out(State.PLAY, 0x43, 0x40); // Set Experience out(State.PLAY, 0x44, 0x41); // Update Health - out(State.PLAY, 0x45, 0x42, cancel()); // Scoreboard Objective TODO MODIFIED out(State.PLAY, 0x46, 0x43); // Set Passengers - out(State.PLAY, 0x47, 0x44, cancel()); // Teams TODO MODIFIED out(State.PLAY, 0x48, 0x45); // Update Score out(State.PLAY, 0x49, 0x46); // Spawn Position out(State.PLAY, 0x4A, 0x47); // Time Update @@ -119,24 +116,21 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol { out(State.PLAY, 0x4C, -1, cancel()); // Stop Sound TODO NEW out(State.PLAY, 0x4D, 0x49); // Sound Effect out(State.PLAY, 0x4E, 0x4A); // Player List Header And Footer - out(State.PLAY, 0x4F, 0x4B, cancel()); // Collect Item + out(State.PLAY, 0x4F, 0x4B); // Collect Item out(State.PLAY, 0x50, 0x4C); // Entity Teleport out(State.PLAY, 0x51, 0x4D, cancel()); // Advancements out(State.PLAY, 0x52, 0x4E); // Entity Properties out(State.PLAY, 0x53, 0x4F); // Entity Effect out(State.PLAY, 0x54, -1, cancel()); // Declare Recipes TODO NEW - out(State.PLAY, 0x55, -1, cancel()); // Tags TODO NEW + out(State.PLAY, 0x55, -1, cancel()); // Tags (the client won't need this) - in(State.PLAY, 0x01, -1, cancel()); // Query Block NBT TODO NEW - in(State.PLAY, 0x05, 0x01); // Tab-Complete (serverbound) TODO MODIFIED - in(State.PLAY, 0x06, 0x05); //Confirm Transaction (serverbound) + in(State.PLAY, 0x05, 0x01, cancel()); // Tab-Complete (serverbound) TODO MODIFIED + in(State.PLAY, 0x06, 0x05); // Confirm Transaction (serverbound) in(State.PLAY, 0x07, 0x06); // Enchant Item - in(State.PLAY, 0x08, 0x07); // Click Window in(State.PLAY, 0x09, 0x08); // Close Window (serverbound) in(State.PLAY, 0x0A, 0x09, cancel()); // Plugin message (serverbound) TODO MODIFIED in(State.PLAY, 0x0B, -1, cancel()); // Edit Book TODO NEW - in(State.PLAY, 0x0C, -1, cancel()); // Query Entity NBT TODO NEW in(State.PLAY, 0x0D, 0x0A); // Use Entity in(State.PLAY, 0x0E, 0x0B); // Keep Alive (serverbound) in(State.PLAY, 0x0F, 0x0C); // Player @@ -160,7 +154,6 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol { in(State.PLAY, 0x21, 0x1A); // Held Item Change (serverbound) in(State.PLAY, 0x22, -1, cancel()); // Update Command Block TODO NEW in(State.PLAY, 0x23, -1, cancel()); // Update Command Block Minecart TODO NEW - in(State.PLAY, 0x24, 0x1B); // Creative Inventory Action in(State.PLAY, 0x25, -1, cancel()); // Update Structure Block TODO NEW in(State.PLAY, 0x26, 0x1C); // Update Sign in(State.PLAY, 0x27, 0x1D); // Animation (serverbound) @@ -194,6 +187,7 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol { static { BackwardsMappings.init(); + PaintingMapping.init(); } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/PaintingMapping.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/PaintingMapping.java new file mode 100644 index 00000000..bfb85bd7 --- /dev/null +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/PaintingMapping.java @@ -0,0 +1,45 @@ +package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data; + +import java.util.HashMap; +import java.util.Map; + +public class PaintingMapping { + private static Map paintings = new HashMap<>(); + + public static void init() { + add("kebab"); + add("aztec"); + add("alban"); + add("aztec2"); + add("bomb"); + add("plant"); + add("wasteland"); + add("pool"); + add("courbet"); + add("sea"); + add("sunset"); + add("creebet"); + add("wanderer"); + add("graham"); + add("match"); + add("bust"); + add("stage"); + add("void"); + add("skullandroses"); + add("wither"); + add("fighters"); + add("pointer"); + add("pigscene"); + add("burningskull"); + add("skeleton"); + add("donkeykong"); + } + + private static void add(String motive) { + paintings.put(paintings.size(), motive); + } + + public static String getStringId(int id) { + return paintings.getOrDefault(id, "kebab"); + } +} 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 5d0ad65a..fe48d5db 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 @@ -15,11 +15,16 @@ import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.BackwardsMappings; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; +import us.myles.ViaVersion.api.minecraft.BlockChangeRecord; import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; +import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; +import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type; import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; @@ -28,6 +33,74 @@ public class BlockItemPackets1_13 extends BlockItemRewriter> 4); + } else if (id == 2001) { // Block break + block break sound + data = toOldId(data); + int blockId = data >> 4; + int blockData = data & 0xF; + wrapper.set(Type.INT, 1, data = (blockId & 0xFFF) | (blockData << 12)); + } + } + }); + } + }); + + //Map + protocol.out(State.PLAY, 0x26, 0x24, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); + map(Type.BYTE); + map(Type.BOOLEAN); + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int iconCount = wrapper.passthrough(Type.VAR_INT); + for (int i = 0; i < iconCount; i++) { + int type = wrapper.read(Type.VAR_INT); + byte x = wrapper.read(Type.BYTE); + byte z = wrapper.read(Type.BYTE); + byte direction = wrapper.read(Type.BYTE); + if (wrapper.read(Type.BOOLEAN)) { + wrapper.read(Type.STRING); + } + if (type > 9) continue; + wrapper.write(Type.BYTE, (byte) ((type << 4) | (direction & 0x0F))); + wrapper.write(Type.BYTE, x); + wrapper.write(Type.BYTE, z); + } + } + }); + } + }); + + //Entity Equipment + protocol.out(State.PLAY, 0x42, 0x3F, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); + map(Type.VAR_INT); + map(Type.FLAT_ITEM, Type.ITEM); + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + Item item = wrapper.get(Type.ITEM, 0); + toClient(item); + } + }); + } + }); + + + //Set Creative Slot + protocol.in(State.PLAY, 0x24, 0x1B, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.SHORT); + map(Type.ITEM, Type.FLAT_ITEM); + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + Item item = wrapper.get(Type.FLAT_ITEM, 0); + toServer(item); + } + }); + } + }); + + //Click Window + protocol.in(State.PLAY, 0x08, 0x07, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.UNSIGNED_BYTE); + map(Type.SHORT); + map(Type.BYTE); + map(Type.SHORT); + map(Type.VAR_INT); + map(Type.ITEM, Type.FLAT_ITEM); + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + Item item = wrapper.get(Type.FLAT_ITEM, 0); + toServer(item); + } + }); + } + }); } - public static int toNewId(int oldId) { + public static int toOldId(int oldId) { if (oldId < 0) { oldId = 0; // Some plugins use negative numbers to clear blocks, remap them to air. } @@ -84,6 +265,14 @@ public class BlockItemPackets1_13 extends BlockItemRewriter { + + @Override + protected void registerPackets(Protocol1_12_2To1_13 protocol) { + + //Spawn Painting + protocol.out(State.PLAY, 0x04, 0x04, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); + map(Type.UUID); + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int motive = wrapper.read(Type.VAR_INT); + String title = PaintingMapping.getStringId(motive); + wrapper.write(Type.STRING, title); + } + }); + } + }); + + } + + @Override + protected void registerRewrites() { + + } +} diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java new file mode 100644 index 00000000..adbbbe39 --- /dev/null +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java @@ -0,0 +1,89 @@ +package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets; + +import nl.matsv.viabackwards.api.rewriters.Rewriter; +import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13; +import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.remapper.PacketHandler; +import us.myles.ViaVersion.api.remapper.PacketRemapper; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter; + +public class PlayerPacket1_13 extends Rewriter { + @Override + protected void registerPackets(Protocol1_12_2To1_13 protocol) { + + //Scoreboard Objective + protocol.out(State.PLAY, 0x45, 0x42, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.STRING); + map(Type.BYTE); + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + byte mode = wrapper.get(Type.BYTE, 0); + if (mode == 0 || mode == 2) { + String value = wrapper.read(Type.STRING); + value = ChatRewriter.jsonTextToLegacy(value); + if (value.length() > 32) value = value.substring(0, 32); + wrapper.write(Type.STRING, value); + int type = wrapper.read(Type.VAR_INT); + wrapper.write(Type.STRING, type == 1 ? "hearts" : "integer"); + } + } + }); + } + }); + + //Teams + protocol.out(State.PLAY, 0x47, 0x44, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.STRING); + map(Type.BYTE); + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + byte action = wrapper.get(Type.BYTE, 0); + if (action == 0 || action == 2) { + String displayName = wrapper.read(Type.STRING); + displayName = ChatRewriter.jsonTextToLegacy(displayName); + if (displayName.length() > 32) displayName = displayName.substring(0, 32); + wrapper.write(Type.STRING, displayName); + + String prefix = wrapper.read(Type.STRING); + String suffix = wrapper.read(Type.STRING); + + wrapper.passthrough(Type.BYTE); //Flags + + wrapper.passthrough(Type.STRING); //Name Tag Visibility + wrapper.passthrough(Type.STRING); //Collision Rule + + int colour = wrapper.read(Type.VAR_INT); + if (colour == 21) { + colour = -1; + } + + wrapper.write(Type.BYTE, (byte) colour); + + wrapper.write(Type.STRING, ChatRewriter.jsonTextToLegacy(prefix)); + wrapper.write(Type.STRING, ChatRewriter.jsonTextToLegacy(suffix)); + } + + if (action == 0 || action == 3 || action == 4) { + wrapper.passthrough(Type.STRING_ARRAY); // Entities + } + } + }); + } + }); + + + } + + @Override + protected void registerRewrites() { + + } +} diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/InventoryPackets.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/InventoryPackets.java index cf43be02..ecd88eec 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/InventoryPackets.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/InventoryPackets.java @@ -78,7 +78,7 @@ public class InventoryPackets { } }); - // // Declare Recipes + // Declare Recipes protocol.registerOutgoing(State.PLAY, 0x54, 0x54, new PacketRemapper() { @Override public void registerMap() {