From 35cabf34b07bbff6280837c970c1abc11940bdf0 Mon Sep 17 00:00:00 2001 From: Marco Neuhaus Date: Tue, 28 Aug 2018 18:06:57 +0200 Subject: [PATCH 1/4] Add support for 1.13 at 1.13.1 server TODO: * add Tab complete * add boss bar * add Advancements * add tags --- .../api/ViaBackwardsPlatform.java | 3 +- .../MetadataRewriter.java | 48 +++++ .../Protocol1_13To1_13_1.java | 97 +++++++++ .../packets/EntityPackets.java | 152 ++++++++++++++ .../packets/InventoryPackets.java | 142 ++++++++++++++ .../packets/WorldPackets.java | 185 ++++++++++++++++++ pom.xml | 2 +- 7 files changed, 627 insertions(+), 2 deletions(-) create mode 100644 core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/MetadataRewriter.java create mode 100644 core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java create mode 100644 core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets.java create mode 100644 core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets.java create mode 100644 core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/WorldPackets.java diff --git a/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java b/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java index 52161ed7..f459ff7f 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java @@ -16,10 +16,10 @@ import nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1; import nl.matsv.viabackwards.protocol.protocol1_12_1to1_12_2.Protocol1_12_1To1_12_2; import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.Protocol1_11_1To1_12; import nl.matsv.viabackwards.protocol.protocol1_12to1_12_1.Protocol1_12To1_12_1; +import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1; import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10; import us.myles.ViaVersion.api.protocol.ProtocolRegistry; import us.myles.ViaVersion.api.protocol.ProtocolVersion; -import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; import java.lang.reflect.Field; import java.util.Collections; @@ -39,6 +39,7 @@ public interface ViaBackwardsPlatform { ProtocolRegistry.registerProtocol(new Protocol1_11_1To1_12(), Collections.singletonList(ProtocolVersion.v1_11_1.getId()), ProtocolVersion.v1_12.getId()); ProtocolRegistry.registerProtocol(new Protocol1_12To1_12_1(), Collections.singletonList(ProtocolVersion.v1_12.getId()), ProtocolVersion.v1_12_1.getId()); ProtocolRegistry.registerProtocol(new Protocol1_12_1To1_12_2(), Collections.singletonList(ProtocolVersion.v1_12_1.getId()), ProtocolVersion.v1_12_2.getId()); + ProtocolRegistry.registerProtocol(new Protocol1_13To1_13_1(), Collections.singletonList(ProtocolVersion.v1_13.getId()), ProtocolVersion.v1_13_1.getId()); } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/MetadataRewriter.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/MetadataRewriter.java new file mode 100644 index 00000000..72ebe475 --- /dev/null +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/MetadataRewriter.java @@ -0,0 +1,48 @@ +package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1; + +import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.InventoryPackets; +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 java.util.ArrayList; +import java.util.List; + +public class MetadataRewriter { + + public static void handleMetadata(int entityId, Entity1_13Types.EntityType type, List metadatas, UserConnection connection) { + for (Metadata metadata : new ArrayList<>(metadatas)) { + try { + // 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(Protocol1_13To1_13_1.getNewBlockStateId(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(Protocol1_13To1_13_1.getNewBlockStateId(data)); + } + if(type.is(EntityType.ITEM)){ + + } + } catch (Exception e) { + metadatas.remove(metadata); + if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) { + Via.getPlatform().getLogger().warning("An error occurred with entity metadata handler"); + Via.getPlatform().getLogger().warning("Metadata: " + metadata); + e.printStackTrace(); + } + } + } + } + +} diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java new file mode 100644 index 00000000..64b381d6 --- /dev/null +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java @@ -0,0 +1,97 @@ +package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1; + +import nl.matsv.viabackwards.api.BackwardsProtocol; +import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.EntityPackets; +import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.InventoryPackets; +import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.WorldPackets; +import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.remapper.PacketHandler; +import us.myles.ViaVersion.api.remapper.PacketRemapper; +import us.myles.ViaVersion.api.remapper.ValueTransformer; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; + +public class Protocol1_13To1_13_1 extends BackwardsProtocol { + + @Override + protected void registerPackets() { + EntityPackets.register(this); + InventoryPackets.register(this); + WorldPackets.register(this); + + //Tab complete + registerIncoming(State.PLAY, 0x05, 0x05, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); + map(Type.STRING, new ValueTransformer(Type.STRING) { + @Override + public String transform(PacketWrapper wrapper, String inputValue) { + // 1.13 starts sending slash at start, so we remove it for compatibility + return !inputValue.startsWith("/") ? "/" + inputValue : inputValue; + } + }); + } + }); + + //Edit Book + registerIncoming(State.PLAY, 0x0B, 0x0B, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.FLAT_ITEM); + map(Type.BOOLEAN); + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + wrapper.write(Type.VAR_INT, 0); + } + }); + } + }); + + } + + public static int getNewBlockStateId(int blockId) { + if (blockId > 8590) { + blockId -= 17; + } else if (blockId > 8573) { + blockId = 0; //TODO replace new blocks + } else if (blockId > 8479) { + blockId -= 16; + } else if (blockId > 8469 && blockId % 2 == 0) { + if (blockId % 2 == 0) { + blockId = 8459 + (blockId - 8470) / 2; + } else { + blockId = 0; //TODO replace new blocks + } + } else if (blockId > 8463) { + blockId = 0; //TODO replace new blocks + } else if (blockId > 1127) { + blockId -= 1; + } else if (blockId == 1127) { + blockId = 1126; + } + + return blockId; + } + + public static int getNewBlockId(int blockId) { + if (blockId > 565) { + blockId -= 5; + } else if (blockId > 561) { + blockId = 0; //TODO replace new blocks + } + + return blockId; + } + + @Override + public void init(UserConnection userConnection) { + userConnection.put(new EntityTracker(userConnection)); + if (!userConnection.has(ClientWorld.class)) + userConnection.put(new ClientWorld(userConnection)); + } +} diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets.java new file mode 100644 index 00000000..d1eb8d2a --- /dev/null +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets.java @@ -0,0 +1,152 @@ +package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets; + +import com.google.common.base.Optional; +import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.MetadataRewriter; +import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1; +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.protocol1_13to1_12_2.storage.EntityTracker; + +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, Protocol1_13To1_13_1.getNewBlockStateId(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/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets.java new file mode 100644 index 00000000..d9cdcce1 --- /dev/null +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets.java @@ -0,0 +1,142 @@ +package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.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; + +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); + } + }); + } + } + ); + } + + public static void toClient(Item item) { + if (item == null) return; + item.setId((short) getOldItemId(item.getId())); + } + + public static int getNewItemId(int itemId) { + if (itemId >= 443) { + return itemId + 5; + } + return itemId; + } + + public static void toServer(Item item) { + if (item == null) return; + item.setId((short) getNewItemId(item.getId())); + } + + public static int getOldItemId(int newId) { + if (newId >= 448) { + return newId - 5; + } + return newId; + } +} diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/WorldPackets.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/WorldPackets.java new file mode 100644 index 00000000..222f5eed --- /dev/null +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/WorldPackets.java @@ -0,0 +1,185 @@ +package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets; + +import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1; +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.protocol1_13to1_12_2.types.Chunk1_13Type; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; + +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 (ChunkSection section : chunk.getSections()) { + if (section != null) { + for (int i = 0; i < section.getPalette().size(); i++) { + section.getPalette().set( + i, + Protocol1_13To1_13_1.getNewBlockStateId(section.getPalette().get(i)) + ); + } + } + } + + } + }); + } + }); + + // 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_13To1_13_1.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_13To1_13_1.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_13To1_13_1.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.INT); // Data + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int id = wrapper.get(Type.INT, 0); + int data = wrapper.get(Type.INT, 1); + if (id == 1010) { // Play record + wrapper.set(Type.INT, 1, data = InventoryPackets.getNewItemId(data)); + } else if (id == 2001) { // Block break + block break sound + wrapper.set(Type.INT, 1, data = Protocol1_13To1_13_1.getNewBlockStateId(data)); + } + } + }); + } + }); + + //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, Protocol1_13To1_13_1.getNewBlockStateId(data)); + } + } + }); + } + }); + } + +} diff --git a/pom.xml b/pom.xml index 37264eec..9c78a9e5 100644 --- a/pom.xml +++ b/pom.xml @@ -65,7 +65,7 @@ us.myles viaversion - 1.4.1 + 1.5.0 provided From bc19f1a57db7c59bc13ff15a36244d581a80d93e Mon Sep 17 00:00:00 2001 From: Marco Neuhaus Date: Tue, 28 Aug 2018 18:13:56 +0200 Subject: [PATCH 2/4] add mappings for advancements add mappings for tags --- .../Protocol1_13To1_13_1.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java index 64b381d6..c13fb5d7 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java @@ -6,6 +6,7 @@ import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.InventoryPack import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.WorldPackets; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.data.UserConnection; +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.remapper.ValueTransformer; @@ -52,6 +53,77 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol { } }); + // Advancements + registerOutgoing(State.PLAY, 0x51, 0x51, new PacketRemapper() { + @Override + public void registerMap() { + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + wrapper.passthrough(Type.BOOLEAN); // Reset/clear + int size = wrapper.passthrough(Type.VAR_INT); // Mapping size + + for (int i = 0; i < size; i++) { + wrapper.passthrough(Type.STRING); // Identifier + + // Parent + if (wrapper.passthrough(Type.BOOLEAN)) + wrapper.passthrough(Type.STRING); + + // Display data + if (wrapper.passthrough(Type.BOOLEAN)) { + wrapper.passthrough(Type.STRING); // Title + wrapper.passthrough(Type.STRING); // Description + Item icon = wrapper.passthrough(Type.FLAT_ITEM); + InventoryPackets.toClient(icon); + wrapper.passthrough(Type.VAR_INT); // Frame type + int flags = wrapper.passthrough(Type.INT); // Flags + if ((flags & 1) != 0) + wrapper.passthrough(Type.STRING); // Background texture + wrapper.passthrough(Type.FLOAT); // X + wrapper.passthrough(Type.FLOAT); // Y + } + + wrapper.passthrough(Type.STRING_ARRAY); // Criteria + + int arrayLength = wrapper.passthrough(Type.VAR_INT); + for (int array = 0; array < arrayLength; array++) { + wrapper.passthrough(Type.STRING_ARRAY); // String array + } + } + } + }); + } + }); + + //Tags + registerOutgoing(State.PLAY, 0x55, 0x55, new PacketRemapper() { + @Override + public void registerMap() { + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int blockTagsSize = wrapper.passthrough(Type.VAR_INT); // block tags + for (int i = 0; i < blockTagsSize; i++) { + wrapper.passthrough(Type.STRING); + Integer[] blocks = wrapper.passthrough(Type.VAR_INT_ARRAY); + for (int j = 0; j < blocks.length; j++) { + blocks[j] = getNewBlockId(blocks[j]); + } + } + int itemTagsSize = wrapper.passthrough(Type.VAR_INT); // item tags + for (int i = 0; i < itemTagsSize; i++) { + wrapper.passthrough(Type.STRING); + Integer[] items = wrapper.passthrough(Type.VAR_INT_ARRAY); + for (int j = 0; j < items.length; j++) { + items[j] = InventoryPackets.getOldItemId(items[j]); + } + } + } + }); + } + }); + } public static int getNewBlockStateId(int blockId) { From 00ad68389c062262ac6be185093a869423aef2fd Mon Sep 17 00:00:00 2001 From: Marco Neuhaus Date: Tue, 28 Aug 2018 18:49:13 +0200 Subject: [PATCH 3/4] add mappings for bossbar add mappings for tab complete --- .../Protocol1_13To1_13_1.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java index c13fb5d7..b884a825 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java @@ -53,6 +53,57 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol { } }); + // Tab complete + registerOutgoing(State.PLAY, 0x10, 0x10, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); // Transaction id + map(Type.VAR_INT); // Start + map(Type.VAR_INT); // Length + map(Type.VAR_INT); // Count + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int start = wrapper.get(Type.VAR_INT, 1); + wrapper.set(Type.VAR_INT, 1, start - 1); // Offset by +1 to take into account / at beginning + // Passthrough suggestions + int count = wrapper.get(Type.VAR_INT, 3); + for (int i = 0; i < count; i++) { + wrapper.passthrough(Type.STRING); + boolean hasTooltip = wrapper.passthrough(Type.BOOLEAN); + if (hasTooltip) { + wrapper.passthrough(Type.STRING); // JSON Tooltip + } + } + } + }); + } + }); + + //boss bar + registerOutgoing(State.PLAY, 0x0C, 0x0C, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.UUID); + map(Type.VAR_INT); + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int action = wrapper.get(Type.VAR_INT, 0); + if (action == 0) { + wrapper.passthrough(Type.STRING); + wrapper.passthrough(Type.FLOAT); + wrapper.passthrough(Type.VAR_INT); + short flags = wrapper.read(Type.UNSIGNED_BYTE); + if ((flags & 0x04) != 0) flags |= 0x02; + wrapper.write(Type.UNSIGNED_BYTE, flags); + } + } + }); + } + }); + + // Advancements registerOutgoing(State.PLAY, 0x51, 0x51, new PacketRemapper() { @Override From f2e35a0c5a16622f9df9cf89b069ce379ee05bff Mon Sep 17 00:00:00 2001 From: Marco Neuhaus Date: Tue, 28 Aug 2018 19:47:01 +0200 Subject: [PATCH 4/4] add comment --- .../protocol/protocol1_13to1_13_1/packets/InventoryPackets.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets.java index d9cdcce1..f1f94122 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets.java @@ -121,6 +121,7 @@ public class InventoryPackets { item.setId((short) getOldItemId(item.getId())); } + //1.13.1 Item Id public static int getNewItemId(int itemId) { if (itemId >= 443) { return itemId + 5; @@ -133,6 +134,7 @@ public class InventoryPackets { item.setId((short) getNewItemId(item.getId())); } + //1.13 Item Id public static int getOldItemId(int newId) { if (newId >= 448) { return newId - 5;