From 2da9b99789f95fc57304dfefddfd19385fd55f60 Mon Sep 17 00:00:00 2001 From: Gerrygames Date: Fri, 26 Oct 2018 18:36:35 +0200 Subject: [PATCH] 1.14 position changes --- .../us/myles/ViaVersion/api/type/Type.java | 1 + .../types/minecraft/Position1_14Type.java | 26 +++ .../Protocol1_14To1_13_2.java | 2 + .../packets/EntityPackets.java | 21 ++ .../packets/InventoryPackets.java | 32 ++- .../packets/PlayerPackets.java | 71 +++++++ .../packets/WorldPackets.java | 184 ++++++++++-------- 7 files changed, 241 insertions(+), 96 deletions(-) create mode 100644 common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/Position1_14Type.java create mode 100644 common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/PlayerPackets.java diff --git a/common/src/main/java/us/myles/ViaVersion/api/type/Type.java b/common/src/main/java/us/myles/ViaVersion/api/type/Type.java index 3e1db7013..ff10237f3 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/type/Type.java +++ b/common/src/main/java/us/myles/ViaVersion/api/type/Type.java @@ -59,6 +59,7 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { public static final Type NOTHING = new VoidType(); // This is purely used for remapping. /* MC Types */ public static final Type POSITION = new PositionType(); + public static final Type POSITION1_14 = new Position1_14Type(); public static final Type ROTATION = new EulerAngleType(); public static final Type VECTOR = new VectorType(); public static final Type NBT = new NBTType(); diff --git a/common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/Position1_14Type.java b/common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/Position1_14Type.java new file mode 100644 index 000000000..05543d43b --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/Position1_14Type.java @@ -0,0 +1,26 @@ +package us.myles.ViaVersion.api.type.types.minecraft; + +import io.netty.buffer.ByteBuf; +import us.myles.ViaVersion.api.minecraft.Position; +import us.myles.ViaVersion.api.type.Type; + +public class Position1_14Type extends Type { + public Position1_14Type() { + super(Position.class); + } + + @Override + public Position read(ByteBuf buffer) { + long val = buffer.readLong(); + long x = (val >> 38); + long y = val & 0xfff; + long z = (((val << 38) >> 38)) >> 12; + + return new Position(x, y, z); + } + + @Override + public void write(ByteBuf buffer, Position object) { + buffer.writeLong(((object.getX() & 0x3ffffff) << 38) | (object.getY() & 0xfff) | ((object.getZ() & 0x3ffffff) << 12)); + } +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java index 359c74f44..2e9782f84 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java @@ -9,6 +9,7 @@ import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.EntityPackets; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.InventoryPackets; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.PlayerPackets; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.WorldPackets; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; @@ -19,6 +20,7 @@ public class Protocol1_14To1_13_2 extends Protocol { InventoryPackets.register(this); EntityPackets.register(this); WorldPackets.register(this); + PlayerPackets.register(this); // Sound Effect registerOutgoing(State.PLAY, 0x4D, 0x4D, new PacketRemapper() { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java index 60218147e..cd1738597 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java @@ -92,6 +92,18 @@ public class EntityPackets { } }); + // Spawn painting + protocol.registerOutgoing(State.PLAY, 0x04, 0x04, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); + map(Type.UUID); + map(Type.VAR_INT); + map(Type.POSITION, Type.POSITION1_14); + map(Type.BYTE); + } + }); + // Spawn player packet protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { @Override @@ -119,6 +131,15 @@ public class EntityPackets { } }); + // Use bed + protocol.registerOutgoing(State.PLAY, 0x33, 0x33, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); + map(Type.POSITION, Type.POSITION1_14); + } + }); + // Destroy entities protocol.registerOutgoing(State.PLAY, 0x35, 0x35, new PacketRemapper() { @Override diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java index 49146bc31..b4e62f4ce 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java @@ -27,8 +27,7 @@ public class InventoryPackets { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - Item stack = wrapper.get(Type.FLAT_VAR_INT_ITEM, 0); - toClient(stack); + toClient(wrapper.get(Type.FLAT_VAR_INT_ITEM, 0)); } }); } @@ -45,8 +44,7 @@ public class InventoryPackets { @Override public void handle(PacketWrapper wrapper) throws Exception { Item[] stacks = wrapper.get(Type.FLAT_VAR_INT_ITEM_ARRAY, 0); - for (Item stack : stacks) - toClient(stack); + for (Item stack : stacks) toClient(stack); } }); } @@ -69,12 +67,12 @@ public class InventoryPackets { // Input Item toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Output Item - InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); + toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item if (secondItem) { // Second Item - InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); + toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); } wrapper.passthrough(Type.BOOLEAN); // Trade disabled @@ -98,8 +96,7 @@ public class InventoryPackets { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - Item stack = wrapper.get(Type.FLAT_VAR_INT_ITEM, 0); - toClient(stack); + toClient(wrapper.get(Type.FLAT_VAR_INT_ITEM, 0)); } }); } @@ -129,19 +126,22 @@ public class InventoryPackets { int ingredientsNo = wrapper.passthrough(Type.VAR_INT); for (int j = 0; j < ingredientsNo; j++) { Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients + for (Item item : items) toClient(item); } - wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); // Result + toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result } else if (type.equals("crafting_shaped")) { int ingredientsNo = wrapper.passthrough(Type.VAR_INT) * wrapper.passthrough(Type.VAR_INT); wrapper.passthrough(Type.STRING); // Group for (int j = 0; j < ingredientsNo; j++) { - wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients + Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients + for (Item item : items) toClient(item); } - wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); // Result + toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result } else if (type.equals("smelting")) { wrapper.passthrough(Type.STRING); // Group - wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients - wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); + Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients + for (Item item : items) toClient(item); + toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); wrapper.passthrough(Type.FLOAT); // EXP wrapper.passthrough(Type.VAR_INT); // Cooking time } @@ -171,8 +171,7 @@ public class InventoryPackets { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - Item item = wrapper.get(Type.FLAT_VAR_INT_ITEM, 0); - toServer(item); + toServer(wrapper.get(Type.FLAT_VAR_INT_ITEM, 0)); } }); } @@ -188,8 +187,7 @@ public class InventoryPackets { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - Item item = wrapper.get(Type.FLAT_VAR_INT_ITEM, 0); - toServer(item); + toServer(wrapper.get(Type.FLAT_VAR_INT_ITEM, 0)); } }); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/PlayerPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/PlayerPackets.java new file mode 100644 index 000000000..91f4b9b13 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/PlayerPackets.java @@ -0,0 +1,71 @@ +package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets; + +import us.myles.ViaVersion.api.protocol.Protocol; +import us.myles.ViaVersion.api.remapper.PacketRemapper; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.packets.State; + +public class PlayerPackets { + + public static void register(Protocol protocol) { + + // Open Sign Editor + protocol.registerOutgoing(State.PLAY, 0x2C, 0x2C, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.POSITION, Type.POSITION1_14); + } + }); + + // Query Block NBT + protocol.registerIncoming(State.PLAY, 0x01, 0x01, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); + map(Type.POSITION1_14, Type.POSITION); + } + }); + + // Player Digging + protocol.registerIncoming(State.PLAY, 0x18, 0x18, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); + map(Type.POSITION1_14, Type.POSITION); + map(Type.BYTE); + } + }); + + // Update Command Block + protocol.registerIncoming(State.PLAY, 0x22, 0x22, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.POSITION1_14, Type.POSITION); + } + }); + + // Update Structure Block + protocol.registerIncoming(State.PLAY, 0x25, 0x25, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.POSITION1_14, Type.POSITION); + } + }); + + // Update Sign + protocol.registerIncoming(State.PLAY, 0x26, 0x26, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.POSITION1_14, Type.POSITION); + } + }); + + // Player Block Placement + protocol.registerIncoming(State.PLAY, 0x29, 0x29, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.POSITION1_14, Type.POSITION); + } + }); + } +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java index 56dd17530..b55c1d769 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java @@ -19,6 +19,78 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; public class WorldPackets { public static void register(Protocol protocol) { + + // Block break animation + protocol.registerOutgoing(State.PLAY, 0x08, 0x08, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); + map(Type.POSITION, Type.POSITION1_14); + map(Type.BYTE); + } + }); + + // Update block entity + protocol.registerOutgoing(State.PLAY, 0x09, 0x09, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.POSITION, Type.POSITION1_14); + } + }); + + // Block Action + protocol.registerOutgoing(State.PLAY, 0x0A, 0x0A, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.POSITION, Type.POSITION1_14); // Location + map(Type.UNSIGNED_BYTE); // Action id + map(Type.UNSIGNED_BYTE); // Action param + map(Type.VAR_INT); // Block id - /!\ NOT BLOCK STATE + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + wrapper.set(Type.VAR_INT, 0, Protocol1_14To1_13_2.getNewBlockId(wrapper.get(Type.VAR_INT, 0))); + } + }); + } + }); + + // Block Change + protocol.registerOutgoing(State.PLAY, 0xB, 0xB, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.POSITION, Type.POSITION1_14); + map(Type.VAR_INT); + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int id = wrapper.get(Type.VAR_INT, 0); + + wrapper.set(Type.VAR_INT, 0, Protocol1_14To1_13_2.getNewBlockStateId(id)); + } + }); + } + }); + + // Multi Block Change + protocol.registerOutgoing(State.PLAY, 0xF, 0xF, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.INT); // 0 - Chunk X + map(Type.INT); // 1 - Chunk Z + map(Type.BLOCK_CHANGE_RECORD_ARRAY); // 2 - Records + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + // Convert ids + for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) { + int id = record.getBlockId(); + record.setBlockId(Protocol1_14To1_13_2.getNewBlockStateId(id)); + } + } + }); + } + }); //Chunk protocol.registerOutgoing(State.PLAY, 0x22, 0x22, new PacketRemapper() { @Override @@ -98,66 +170,12 @@ public class WorldPackets { } }); - // Block Action - protocol.registerOutgoing(State.PLAY, 0x0A, 0x0A, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.POSITION); // Location - map(Type.UNSIGNED_BYTE); // Action id - map(Type.UNSIGNED_BYTE); // Action param - map(Type.VAR_INT); // Block id - /!\ NOT BLOCK STATE - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.set(Type.VAR_INT, 0, Protocol1_14To1_13_2.getNewBlockId(wrapper.get(Type.VAR_INT, 0))); - } - }); - } - }); - - // Block Change - protocol.registerOutgoing(State.PLAY, 0xB, 0xB, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.POSITION); - map(Type.VAR_INT); - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - int id = wrapper.get(Type.VAR_INT, 0); - - wrapper.set(Type.VAR_INT, 0, Protocol1_14To1_13_2.getNewBlockStateId(id)); - } - }); - } - }); - - // Multi Block Change - protocol.registerOutgoing(State.PLAY, 0xF, 0xF, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.INT); // 0 - Chunk X - map(Type.INT); // 1 - Chunk Z - map(Type.BLOCK_CHANGE_RECORD_ARRAY); // 2 - Records - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - // Convert ids - for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) { - int id = record.getBlockId(); - record.setBlockId(Protocol1_14To1_13_2.getNewBlockStateId(id)); - } - } - }); - } - }); - // Effect packet protocol.registerOutgoing(State.PLAY, 0x23, 0x23, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // Effect Id - map(Type.POSITION); // Location + map(Type.POSITION, Type.POSITION1_14); // Location map(Type.INT); // Data handler(new PacketHandler() { @Override @@ -174,6 +192,35 @@ public class WorldPackets { } }); + //spawn particle + protocol.registerOutgoing(State.PLAY, 0x24, 0x24, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.INT); // 0 - Particle ID + map(Type.BOOLEAN); // 1 - Long Distance + map(Type.FLOAT); // 2 - X + map(Type.FLOAT); // 3 - Y + map(Type.FLOAT); // 4 - Z + map(Type.FLOAT); // 5 - Offset X + map(Type.FLOAT); // 6 - Offset Y + map(Type.FLOAT); // 7 - Offset Z + map(Type.FLOAT); // 8 - Particle Data + map(Type.INT); // 9 - Particle Count + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int id = wrapper.get(Type.INT, 0); + if (id == 3 || id == 20) { + int data = wrapper.passthrough(Type.VAR_INT); + wrapper.set(Type.VAR_INT, 0, Protocol1_14To1_13_2.getNewBlockStateId(data)); + } else if (id == 27) { + InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); + } + } + }); + } + }); + //join game protocol.registerOutgoing(State.PLAY, 0x25, 0x25, new PacketRemapper() { @Override @@ -210,32 +257,11 @@ public class WorldPackets { } }); - //spawn particle - protocol.registerOutgoing(State.PLAY, 0x24, 0x24, new PacketRemapper() { + // Spawn position + protocol.registerOutgoing(State.PLAY, 0x49, 0x49, new PacketRemapper() { @Override public void registerMap() { - map(Type.INT); // 0 - Particle ID - map(Type.BOOLEAN); // 1 - Long Distance - map(Type.FLOAT); // 2 - X - map(Type.FLOAT); // 3 - Y - map(Type.FLOAT); // 4 - Z - map(Type.FLOAT); // 5 - Offset X - map(Type.FLOAT); // 6 - Offset Y - map(Type.FLOAT); // 7 - Offset Z - map(Type.FLOAT); // 8 - Particle Data - map(Type.INT); // 9 - Particle Count - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - int id = wrapper.get(Type.INT, 0); - if (id == 3 || id == 20) { - int data = wrapper.passthrough(Type.VAR_INT); - wrapper.set(Type.VAR_INT, 0, Protocol1_14To1_13_2.getNewBlockStateId(data)); - } else if (id == 27) { - InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); - } - } - }); + map(Type.POSITION, Type.POSITION1_14); } }); }