From 6cfb21f660727854b19c33ae5c638c15b9e6dc78 Mon Sep 17 00:00:00 2001 From: Marco Neuhaus Date: Wed, 8 Aug 2018 18:58:25 +0200 Subject: [PATCH 1/5] add support for 18w32a --- .../api/protocol/ProtocolRegistry.java | 4 ++-- .../api/protocol/ProtocolVersion.java | 4 ++-- .../MetadataRewriter.java | 6 +++--- .../Protocol18w32aTO1_13.java} | 19 ++++++++++++------- 4 files changed, 19 insertions(+), 14 deletions(-) rename common/src/main/java/us/myles/ViaVersion/protocols/{protocol18w31ato1_13 => protocol18w32ato1_13}/MetadataRewriter.java (89%) rename common/src/main/java/us/myles/ViaVersion/protocols/{protocol18w31ato1_13/Protocol18w31aTO1_13.java => protocol18w32ato1_13/Protocol18w32aTO1_13.java} (97%) diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java index cddf1a730..c6af45153 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java @@ -19,7 +19,7 @@ import us.myles.ViaVersion.protocols.protocol1_9_1to1_9.Protocol1_9_1TO1_9; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.Protocol1_9_3TO1_9_1_2; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_9_1.Protocol1_9TO1_9_1; -import us.myles.ViaVersion.protocols.protocol18w31ato1_13.Protocol18w31aTO1_13; +import us.myles.ViaVersion.protocols.protocol18w32ato1_13.Protocol18w32aTO1_13; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -57,7 +57,7 @@ public class ProtocolRegistry { // 1.13 support in development! (: registerProtocol(new Protocol1_13To1_12_2(), Collections.singletonList(ProtocolVersion.v1_13.getId()), ProtocolVersion.v1_12_2.getId()); - registerProtocol(new Protocol18w31aTO1_13(), Arrays.asList(ProtocolVersion.v18w31a.getId()), ProtocolVersion.v1_13.getId()); + registerProtocol(new Protocol18w32aTO1_13(), Arrays.asList(ProtocolVersion.v18w32a.getId()), ProtocolVersion.v1_13.getId()); } /** diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java index 1041961e4..8fb744bab 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java @@ -34,7 +34,7 @@ public class ProtocolVersion { public static final ProtocolVersion v1_12_2; // v1_13 as name for better ViaBackwards compatibility. public static final ProtocolVersion v1_13; - public static final ProtocolVersion v18w31a; + public static final ProtocolVersion v18w32a; public static final ProtocolVersion unknown; private final int id; @@ -64,7 +64,7 @@ public class ProtocolVersion { register(v1_12_1 = new ProtocolVersion(338, "1.12.1")); register(v1_12_2 = new ProtocolVersion(340, "1.12.2")); register(v1_13 = new ProtocolVersion(393, "1.13")); - register(v18w31a = new ProtocolVersion(396, "18w31a")); + register(v18w32a = new ProtocolVersion(397, "18w32a")); register(unknown = new ProtocolVersion(-1, "UNKNOWN")); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w31ato1_13/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/MetadataRewriter.java similarity index 89% rename from common/src/main/java/us/myles/ViaVersion/protocols/protocol18w31ato1_13/MetadataRewriter.java rename to common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/MetadataRewriter.java index 4289166c3..b2ef64de7 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w31ato1_13/MetadataRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/MetadataRewriter.java @@ -1,4 +1,4 @@ -package us.myles.ViaVersion.protocols.protocol18w31ato1_13; +package us.myles.ViaVersion.protocols.protocol18w32ato1_13; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; @@ -17,13 +17,13 @@ public class MetadataRewriter { if (metadata.getMetaType() == MetaType1_13.BlockID) { // Convert to new block id int data = (int) metadata.getValue(); - metadata.setValue(Protocol18w31aTO1_13.getMapBlockId(data)); + metadata.setValue(Protocol18w32aTO1_13.getMapBlockId(data)); } if(type == null) continue; if (type.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT) && metadata.getId() == 9) { // New block format int data = (int) metadata.getValue(); - metadata.setValue(Protocol18w31aTO1_13.getMapBlockId(data)); + metadata.setValue(Protocol18w32aTO1_13.getMapBlockId(data)); } } catch (Exception e) { metadatas.remove(metadata); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w31ato1_13/Protocol18w31aTO1_13.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/Protocol18w32aTO1_13.java similarity index 97% rename from common/src/main/java/us/myles/ViaVersion/protocols/protocol18w31ato1_13/Protocol18w31aTO1_13.java rename to common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/Protocol18w32aTO1_13.java index 732df57d8..812ef1bf6 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w31ato1_13/Protocol18w31aTO1_13.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/Protocol18w32aTO1_13.java @@ -1,4 +1,4 @@ -package us.myles.ViaVersion.protocols.protocol18w31ato1_13; +package us.myles.ViaVersion.protocols.protocol18w32ato1_13; import com.google.common.base.Optional; import us.myles.ViaVersion.api.PacketWrapper; @@ -18,7 +18,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; -public class Protocol18w31aTO1_13 extends Protocol { +public class Protocol18w32aTO1_13 extends Protocol { @Override protected void registerPackets() { @@ -351,12 +351,17 @@ public class Protocol18w31aTO1_13 extends Protocol { } - public static int getMapBlockId(int blockId){ - if(blockId > 8573){ - return blockId +2; - }else if(blockId > 1126){ - return blockId +1; + public static int getMapBlockId(int blockId) { + if (blockId > 8573) { + blockId += 17; + } else if (blockId > 8463) { + blockId += 16; + } else if (blockId > 8458) { + blockId = 8470 + (blockId - 8459) * 2; + } else if (blockId > 1126) { + blockId += 1; } + return blockId; } } From 647bbbedb00c73fba726109fb00383171842bb06 Mon Sep 17 00:00:00 2001 From: Marco Neuhaus Date: Wed, 8 Aug 2018 21:45:54 +0200 Subject: [PATCH 2/5] add items remapping --- .../MetadataRewriter.java | 9 +- .../Protocol18w32aTO1_13.java | 2 + .../packets/InventoryPackets.java | 137 ++++++++++++++++++ 3 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/InventoryPackets.java diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/MetadataRewriter.java index b2ef64de7..7e666b529 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/MetadataRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/MetadataRewriter.java @@ -3,8 +3,10 @@ package us.myles.ViaVersion.protocols.protocol18w32ato1_13; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.entities.Entity1_13Types; +import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets; import java.util.ArrayList; import java.util.List; @@ -14,12 +16,15 @@ public class MetadataRewriter { public static void handleMetadata(int entityId, Entity1_13Types.EntityType type, List metadatas, UserConnection connection) { for (Metadata metadata : new ArrayList<>(metadatas)) { try { - if (metadata.getMetaType() == MetaType1_13.BlockID) { + // 1.13 changed item to flat item (no data) + if (metadata.getMetaType() == MetaType1_13.Slot) { + InventoryPackets.toClient((Item) metadata.getValue()); + } else if (metadata.getMetaType() == MetaType1_13.BlockID) { // Convert to new block id int data = (int) metadata.getValue(); metadata.setValue(Protocol18w32aTO1_13.getMapBlockId(data)); } - if(type == null) continue; + if (type == null) continue; if (type.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT) && metadata.getId() == 9) { // New block format int data = (int) metadata.getValue(); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/Protocol18w32aTO1_13.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/Protocol18w32aTO1_13.java index 812ef1bf6..1665499f5 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/Protocol18w32aTO1_13.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/Protocol18w32aTO1_13.java @@ -14,6 +14,7 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.version.Types1_13; import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol18w32ato1_13.packets.InventoryPackets; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; @@ -22,6 +23,7 @@ public class Protocol18w32aTO1_13 extends Protocol { @Override protected void registerPackets() { + InventoryPackets.register(this); //Tab complete registerIncoming(State.PLAY, 0x05, 0x05, new PacketRemapper() { @Override diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/InventoryPackets.java new file mode 100644 index 000000000..132c4ef9a --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/InventoryPackets.java @@ -0,0 +1,137 @@ +package us.myles.ViaVersion.protocols.protocol18w32ato1_13.packets; + +import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.minecraft.item.Item; +import us.myles.ViaVersion.api.protocol.Protocol; +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; + +/** + * Created by Marco Neuhaus on 08.08.2018 for the Project ViaVersion2. + */ +public class InventoryPackets { + + public static void register(Protocol protocol) { + + /* + Outgoing packets + */ + + // Set slot packet + protocol.registerOutgoing(State.PLAY, 0x17, 0x17, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.BYTE); // 0 - Window ID + map(Type.SHORT); // 1 - Slot ID + map(Type.FLAT_ITEM, Type.FLAT_ITEM); // 2 - Slot Value + + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + Item stack = wrapper.get(Type.FLAT_ITEM, 0); + toClient(stack); + } + }); + } + }); + + // Window items packet + protocol.registerOutgoing(State.PLAY, 0x15, 0x15, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.UNSIGNED_BYTE); // 0 - Window ID + map(Type.FLAT_ITEM_ARRAY, Type.FLAT_ITEM_ARRAY); // 1 - Window Values + + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + Item[] stacks = wrapper.get(Type.FLAT_ITEM_ARRAY, 0); + for (Item stack : stacks) + toClient(stack); + } + }); + } + }); + + // Entity Equipment Packet + protocol.registerOutgoing(State.PLAY, 0x42, 0x42, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); // 0 - Entity ID + map(Type.VAR_INT); // 1 - Slot ID + map(Type.FLAT_ITEM, Type.FLAT_ITEM); // 2 - Item + + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + Item stack = wrapper.get(Type.FLAT_ITEM, 0); + toClient(stack); + } + }); + } + }); + + + /* + Incoming packets + */ + + // Click window packet + protocol.registerIncoming(State.PLAY, 0x08, 0x08, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.UNSIGNED_BYTE); // 0 - Window ID + map(Type.SHORT); // 1 - Slot + map(Type.BYTE); // 2 - Button + map(Type.SHORT); // 3 - Action number + map(Type.VAR_INT); // 4 - Mode + map(Type.FLAT_ITEM, Type.FLAT_ITEM); // 5 - Clicked Item + + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + Item item = wrapper.get(Type.FLAT_ITEM, 0); + toServer(item); + } + }); + } + } + ); + + // Creative Inventory Action + protocol.registerIncoming(State.PLAY, 0x24, 0x24, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.SHORT); // 0 - Slot + map(Type.FLAT_ITEM, Type.FLAT_ITEM); // 1 - Clicked Item + + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + Item item = wrapper.get(Type.FLAT_ITEM, 0); + toServer(item); + } + }); + } + } + ); + } + + // TODO CLEANUP / SMARTER REWRITE SYSTEM + // TODO Rewrite identifiers + public static void toClient(Item item) { + if (item == null) return; + if(item.getId() >= 443){ + item.setId((short) (item.getId() + 5)); + } + } + + public static void toServer(Item item) { + if (item == null) return; + if(item.getId() >= 448){ + item.setId((short) (item.getId() - 5)); + } + } +} From fd5bb94cb5f07f7ca7e7ab146d3c29485e3d6fb6 Mon Sep 17 00:00:00 2001 From: Marco Neuhaus Date: Wed, 8 Aug 2018 22:32:29 +0200 Subject: [PATCH 3/5] code cleanup --- .../Protocol18w32aTO1_13.java | 275 +----------------- .../packets/EntityPackets.java | 154 ++++++++++ .../packets/InventoryPackets.java | 2 - .../packets/WorldPackets.java | 155 ++++++++++ 4 files changed, 314 insertions(+), 272 deletions(-) create mode 100644 common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/EntityPackets.java create mode 100644 common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/WorldPackets.java diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/Protocol18w32aTO1_13.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/Protocol18w32aTO1_13.java index 1665499f5..1c98516a2 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/Protocol18w32aTO1_13.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/Protocol18w32aTO1_13.java @@ -1,29 +1,26 @@ package us.myles.ViaVersion.protocols.protocol18w32ato1_13; -import com.google.common.base.Optional; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.data.UserConnection; -import us.myles.ViaVersion.api.entities.Entity1_13Types; -import us.myles.ViaVersion.api.entities.Entity1_13Types.EntityType; -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.protocol.Protocol; 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.api.type.types.version.Types1_13; import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol18w32ato1_13.packets.EntityPackets; import us.myles.ViaVersion.protocols.protocol18w32ato1_13.packets.InventoryPackets; +import us.myles.ViaVersion.protocols.protocol18w32ato1_13.packets.WorldPackets; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker; -import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; public class Protocol18w32aTO1_13 extends Protocol { @Override protected void registerPackets() { + EntityPackets.register(this); InventoryPackets.register(this); + WorldPackets.register(this); + //Tab complete registerIncoming(State.PLAY, 0x05, 0x05, new PacketRemapper() { @Override @@ -59,111 +56,6 @@ public class Protocol18w32aTO1_13 extends Protocol { } }); - //Chunk - registerOutgoing(State.PLAY, 0x22, 0x22, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); - Chunk chunk = wrapper.passthrough(new Chunk1_13Type(clientWorld)); - - for (int i = 0; i < chunk.getSections().length; i++) { - ChunkSection section = chunk.getSections()[i]; - if (section == null) - continue; - - // TODO improve performance - for (int x = 0; x < 16; x++) { - for (int y = 0; y < 16; y++) { - for (int z = 0; z < 16; z++) { - int block = section.getBlock(x, y, z); - - section.setFlatBlock(x, y, z, getMapBlockId(block)); - } - } - } - } - - } - }); - } - }); - - // Block Change - 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, getMapBlockId(id)); - } - }); - } - }); - - // Multi Block Change - 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(getMapBlockId(id)); - } - } - }); - } - }); - - //join game - registerOutgoing(State.PLAY, 0x25, 0x25, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.INT); // 0 - Entity ID - map(Type.UNSIGNED_BYTE); // 1 - Gamemode - map(Type.INT); // 2 - Dimension - - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - // Store the player - ClientWorld clientChunks = wrapper.user().get(ClientWorld.class); - int dimensionId = wrapper.get(Type.INT, 1); - clientChunks.setEnvironment(dimensionId); - } - }); - } - }); - - //respawn - registerOutgoing(State.PLAY, 0x38, 0x38, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.INT); // 0 - Dimension ID - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); - int dimensionId = wrapper.get(Type.INT, 0); - clientWorld.setEnvironment(dimensionId); - } - }); - } - }); - //boss bar registerOutgoing(State.PLAY, 0x0C, 0x0C, new PacketRemapper() { @Override @@ -186,163 +78,6 @@ public class Protocol18w32aTO1_13 extends Protocol { }); } }); - - //spawn particle - 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, getMapBlockId(data)); - } - } - }); - } - }); - - //spawn entity - registerOutgoing(State.PLAY, 0x0, 0x0, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.VAR_INT); // 0 - Entity id - map(Type.UUID); // 1 - UUID - map(Type.BYTE); // 2 - Type - map(Type.DOUBLE); // 3 - X - map(Type.DOUBLE); // 4 - Y - map(Type.DOUBLE); // 5 - Z - map(Type.BYTE); // 6 - Pitch - map(Type.BYTE); // 7 - Yaw - map(Type.INT); // 8 - Data - - // Track Entity - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - int entityId = wrapper.get(Type.VAR_INT, 0); - byte type = wrapper.get(Type.BYTE, 0); - Entity1_13Types.EntityType entType = Entity1_13Types.getTypeFromId(type, true); - - if (entType != null) { - if (entType.is(Entity1_13Types.EntityType.FALLING_BLOCK)) { - int data = wrapper.get(Type.INT, 0); - wrapper.set(Type.INT, 0, getMapBlockId(data)); - } - } - // Register Type ID - wrapper.user().get(EntityTracker.class).addEntity(entityId, entType); - } - }); - } - }); - // Spawn mob packet - registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.VAR_INT); // 0 - Entity ID - map(Type.UUID); // 1 - Entity UUID - map(Type.VAR_INT); // 2 - Entity Type - map(Type.DOUBLE); // 3 - X - map(Type.DOUBLE); // 4 - Y - map(Type.DOUBLE); // 5 - Z - map(Type.BYTE); // 6 - Yaw - map(Type.BYTE); // 7 - Pitch - map(Type.BYTE); // 8 - Head Pitch - map(Type.SHORT); // 9 - Velocity X - map(Type.SHORT); // 10 - Velocity Y - map(Type.SHORT); // 11 - Velocity Z - map(Types1_13.METADATA_LIST); // 12 - Metadata - - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - int entityId = wrapper.get(Type.VAR_INT, 0); - int type = wrapper.get(Type.VAR_INT, 1); - - Entity1_13Types.EntityType entType = Entity1_13Types.getTypeFromId(type, false); - - // Register Type ID - wrapper.user().get(EntityTracker.class).addEntity(entityId, entType); - - MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user()); - } - }); - } - }); - - // Spawn player packet - registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.VAR_INT); // 0 - Entity ID - map(Type.UUID); // 1 - Player UUID - map(Type.DOUBLE); // 2 - X - map(Type.DOUBLE); // 3 - Y - map(Type.DOUBLE); // 4 - Z - map(Type.BYTE); // 5 - Yaw - map(Type.BYTE); // 6 - Pitch - map(Types1_13.METADATA_LIST); // 7 - Metadata - - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - int entityId = wrapper.get(Type.VAR_INT, 0); - - Entity1_13Types.EntityType entType = Entity1_13Types.EntityType.PLAYER; - // Register Type ID - wrapper.user().get(EntityTracker.class).addEntity(entityId, entType); - MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user()); - } - }); - } - }); - // Destroy entities - registerOutgoing(State.PLAY, 0x35, 0x35, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.VAR_INT_ARRAY); // 0 - Entity IDS - - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0)) - wrapper.user().get(EntityTracker.class).removeEntity(entity); - } - }); - } - }); - - - // Metadata packet - registerOutgoing(State.PLAY, 0x3F, 0x3F, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.VAR_INT); // 0 - Entity ID - map(Types1_13.METADATA_LIST); // 1 - Metadata list - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - int entityId = wrapper.get(Type.VAR_INT, 0); - - Optional type = wrapper.user().get(EntityTracker.class).get(entityId); - MetadataRewriter.handleMetadata(entityId, type.orNull(), wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user()); - } - }); - } - }); } @Override diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/EntityPackets.java new file mode 100644 index 000000000..d8366968f --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/EntityPackets.java @@ -0,0 +1,154 @@ +package us.myles.ViaVersion.protocols.protocol18w32ato1_13.packets; + +import com.google.common.base.Optional; +import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.entities.Entity1_13Types; +import us.myles.ViaVersion.api.entities.Entity1_13Types.EntityType; +import us.myles.ViaVersion.api.protocol.Protocol; +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.api.type.types.version.Types1_13; +import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol18w32ato1_13.MetadataRewriter; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker; +import us.myles.ViaVersion.protocols.protocol18w32ato1_13.Protocol18w32aTO1_13; +/** + * Created by Marco Neuhaus on 08.08.2018 for the Project ViaVersion2. + */ +public class EntityPackets { + + public static void register(Protocol protocol) { + + //spawn entity + protocol.registerOutgoing(State.PLAY, 0x0, 0x0, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); // 0 - Entity id + map(Type.UUID); // 1 - UUID + map(Type.BYTE); // 2 - Type + map(Type.DOUBLE); // 3 - X + map(Type.DOUBLE); // 4 - Y + map(Type.DOUBLE); // 5 - Z + map(Type.BYTE); // 6 - Pitch + map(Type.BYTE); // 7 - Yaw + map(Type.INT); // 8 - Data + + // Track Entity + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int entityId = wrapper.get(Type.VAR_INT, 0); + byte type = wrapper.get(Type.BYTE, 0); + Entity1_13Types.EntityType entType = Entity1_13Types.getTypeFromId(type, true); + + if (entType != null) { + if (entType.is(Entity1_13Types.EntityType.FALLING_BLOCK)) { + int data = wrapper.get(Type.INT, 0); + wrapper.set(Type.INT, 0, Protocol18w32aTO1_13.getMapBlockId(data)); + } + } + // Register Type ID + wrapper.user().get(EntityTracker.class).addEntity(entityId, entType); + } + }); + } + }); + // Spawn mob packet + protocol.registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); // 0 - Entity ID + map(Type.UUID); // 1 - Entity UUID + map(Type.VAR_INT); // 2 - Entity Type + map(Type.DOUBLE); // 3 - X + map(Type.DOUBLE); // 4 - Y + map(Type.DOUBLE); // 5 - Z + map(Type.BYTE); // 6 - Yaw + map(Type.BYTE); // 7 - Pitch + map(Type.BYTE); // 8 - Head Pitch + map(Type.SHORT); // 9 - Velocity X + map(Type.SHORT); // 10 - Velocity Y + map(Type.SHORT); // 11 - Velocity Z + map(Types1_13.METADATA_LIST); // 12 - Metadata + + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int entityId = wrapper.get(Type.VAR_INT, 0); + int type = wrapper.get(Type.VAR_INT, 1); + + Entity1_13Types.EntityType entType = Entity1_13Types.getTypeFromId(type, false); + + // Register Type ID + wrapper.user().get(EntityTracker.class).addEntity(entityId, entType); + + MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user()); + } + }); + } + }); + + // Spawn player packet + protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); // 0 - Entity ID + map(Type.UUID); // 1 - Player UUID + map(Type.DOUBLE); // 2 - X + map(Type.DOUBLE); // 3 - Y + map(Type.DOUBLE); // 4 - Z + map(Type.BYTE); // 5 - Yaw + map(Type.BYTE); // 6 - Pitch + map(Types1_13.METADATA_LIST); // 7 - Metadata + + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int entityId = wrapper.get(Type.VAR_INT, 0); + + Entity1_13Types.EntityType entType = Entity1_13Types.EntityType.PLAYER; + // Register Type ID + wrapper.user().get(EntityTracker.class).addEntity(entityId, entType); + MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user()); + } + }); + } + }); + // Destroy entities + protocol.registerOutgoing(State.PLAY, 0x35, 0x35, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT_ARRAY); // 0 - Entity IDS + + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0)) + wrapper.user().get(EntityTracker.class).removeEntity(entity); + } + }); + } + }); + + + // Metadata packet + protocol.registerOutgoing(State.PLAY, 0x3F, 0x3F, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); // 0 - Entity ID + map(Types1_13.METADATA_LIST); // 1 - Metadata list + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int entityId = wrapper.get(Type.VAR_INT, 0); + + Optional type = wrapper.user().get(EntityTracker.class).get(entityId); + MetadataRewriter.handleMetadata(entityId, type.orNull(), wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user()); + } + }); + } + }); + } + +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/InventoryPackets.java index 132c4ef9a..825df9fdb 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/InventoryPackets.java @@ -119,8 +119,6 @@ public class InventoryPackets { ); } - // TODO CLEANUP / SMARTER REWRITE SYSTEM - // TODO Rewrite identifiers public static void toClient(Item item) { if (item == null) return; if(item.getId() >= 443){ diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/WorldPackets.java new file mode 100644 index 000000000..c28aa4834 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/WorldPackets.java @@ -0,0 +1,155 @@ +package us.myles.ViaVersion.protocols.protocol18w32ato1_13.packets; + +import us.myles.ViaVersion.api.PacketWrapper; +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.protocol.Protocol; +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.protocol18w32ato1_13.Protocol18w32aTO1_13; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; + +/** + * Created by Marco Neuhaus on 08.08.2018 for the Project ViaVersion2. + */ +public class WorldPackets { + + public static void register(Protocol protocol) { + //Chunk + protocol.registerOutgoing(State.PLAY, 0x22, 0x22, new PacketRemapper() { + @Override + public void registerMap() { + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); + Chunk chunk = wrapper.passthrough(new Chunk1_13Type(clientWorld)); + + for (int i = 0; i < chunk.getSections().length; i++) { + ChunkSection section = chunk.getSections()[i]; + if (section == null) + continue; + + // TODO improve performance + for (int x = 0; x < 16; x++) { + for (int y = 0; y < 16; y++) { + for (int z = 0; z < 16; z++) { + int block = section.getBlock(x, y, z); + + section.setFlatBlock(x, y, z, Protocol18w32aTO1_13.getMapBlockId(block)); + } + } + } + } + + } + }); + } + }); + + // 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, Protocol18w32aTO1_13.getMapBlockId(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(Protocol18w32aTO1_13.getMapBlockId(id)); + } + } + }); + } + }); + + //join game + protocol.registerOutgoing(State.PLAY, 0x25, 0x25, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.INT); // 0 - Entity ID + map(Type.UNSIGNED_BYTE); // 1 - Gamemode + map(Type.INT); // 2 - Dimension + + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + // Store the player + ClientWorld clientChunks = wrapper.user().get(ClientWorld.class); + int dimensionId = wrapper.get(Type.INT, 1); + clientChunks.setEnvironment(dimensionId); + } + }); + } + }); + + //respawn + protocol.registerOutgoing(State.PLAY, 0x38, 0x38, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.INT); // 0 - Dimension ID + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); + int dimensionId = wrapper.get(Type.INT, 0); + clientWorld.setEnvironment(dimensionId); + } + }); + } + }); + + //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, Protocol18w32aTO1_13.getMapBlockId(data)); + } + } + }); + } + }); + } + +} From 849c7b4fcf705eade26376586ea1f30e57128ba5 Mon Sep 17 00:00:00 2001 From: Marco Neuhaus Date: Wed, 8 Aug 2018 23:35:14 +0200 Subject: [PATCH 4/5] fix wrong import --- .../protocols/protocol18w32ato1_13/MetadataRewriter.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/MetadataRewriter.java index 7e666b529..ddddc130e 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/MetadataRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/MetadataRewriter.java @@ -3,10 +3,11 @@ package us.myles.ViaVersion.protocols.protocol18w32ato1_13; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.entities.Entity1_13Types; +import us.myles.ViaVersion.api.entities.Entity1_13Types.EntityType; import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13; -import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets; +import us.myles.ViaVersion.protocols.protocol18w32ato1_13.packets.InventoryPackets; import java.util.ArrayList; import java.util.List; @@ -30,6 +31,9 @@ public class MetadataRewriter { int data = (int) metadata.getValue(); metadata.setValue(Protocol18w32aTO1_13.getMapBlockId(data)); } + if(type.is(EntityType.ITEM)){ + + } } catch (Exception e) { metadatas.remove(metadata); if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) { From 5c490be861d8150da031363ef4bed2dd4410afe1 Mon Sep 17 00:00:00 2001 From: Marco Neuhaus Date: Thu, 9 Aug 2018 09:25:00 +0200 Subject: [PATCH 5/5] remove file header --- .../protocols/protocol18w32ato1_13/packets/EntityPackets.java | 4 +--- .../protocol18w32ato1_13/packets/InventoryPackets.java | 3 --- .../protocols/protocol18w32ato1_13/packets/WorldPackets.java | 4 ---- 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/EntityPackets.java index d8366968f..565eb6395 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/EntityPackets.java @@ -13,9 +13,7 @@ import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol18w32ato1_13.MetadataRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker; import us.myles.ViaVersion.protocols.protocol18w32ato1_13.Protocol18w32aTO1_13; -/** - * Created by Marco Neuhaus on 08.08.2018 for the Project ViaVersion2. - */ + public class EntityPackets { public static void register(Protocol protocol) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/InventoryPackets.java index 825df9fdb..e92ad8bf5 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/InventoryPackets.java @@ -8,9 +8,6 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; -/** - * Created by Marco Neuhaus on 08.08.2018 for the Project ViaVersion2. - */ public class InventoryPackets { public static void register(Protocol protocol) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/WorldPackets.java index c28aa4834..12481f639 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol18w32ato1_13/packets/WorldPackets.java @@ -13,9 +13,6 @@ import us.myles.ViaVersion.protocols.protocol18w32ato1_13.Protocol18w32aTO1_13; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; -/** - * Created by Marco Neuhaus on 08.08.2018 for the Project ViaVersion2. - */ public class WorldPackets { public static void register(Protocol protocol) { @@ -34,7 +31,6 @@ public class WorldPackets { if (section == null) continue; - // TODO improve performance for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { for (int z = 0; z < 16; z++) {