From 444eabcebf4a7ad6ab5917900e516f1cff67ce08 Mon Sep 17 00:00:00 2001 From: Matsv Date: Thu, 4 Jan 2018 14:59:59 +0100 Subject: [PATCH] Handle metadata correctly, implement new MetaTypes & bump protocol to 18w01a (non-stable) --- bukkit/pom.xml | 2 +- bungee/pom.xml | 4 +- common/pom.xml | 2 +- .../metadata/types/MetaType1_13.java | 20 ++--- .../api/protocol/ProtocolVersion.java | 2 +- .../us/myles/ViaVersion/api/type/Type.java | 1 + .../types/minecraft/OptionalChatType.java | 27 +++++++ .../MetadataRewriter.java | 35 ++++++--- .../ProtocolSnapshotTo1_12_2.java | 76 +++++++++++-------- .../packets/EntityPackets.java | 42 ++++++++-- .../packets/InventoryPackets.java | 2 +- jar/pom.xml | 2 +- pom.xml | 2 +- sponge-legacy/pom.xml | 2 +- sponge/pom.xml | 2 +- 15 files changed, 153 insertions(+), 68 deletions(-) create mode 100644 common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/OptionalChatType.java diff --git a/bukkit/pom.xml b/bukkit/pom.xml index b5002aaea..59b1c9730 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-17w50a + 1.4.0-18w01a 4.0.0 diff --git a/bungee/pom.xml b/bungee/pom.xml index 5ff5695f2..30636ed3c 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-17w50a + 1.4.0-18w01a 4.0.0 @@ -37,7 +37,7 @@ us.myles viaversion-common - 1.4.0-17w50a + 1.4.0-18w01a \ No newline at end of file diff --git a/common/pom.xml b/common/pom.xml index e57467fa8..30167807b 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-17w50a + 1.4.0-18w01a 4.0.0 diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/metadata/types/MetaType1_13.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/metadata/types/MetaType1_13.java index 969e09570..2a311e569 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/metadata/types/MetaType1_13.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/metadata/types/MetaType1_13.java @@ -13,15 +13,17 @@ public enum MetaType1_13 implements MetaType { Float(2, Type.FLOAT), String(3, Type.STRING), Chat(4, Type.STRING), - Slot(5, Type.FLAT_ITEM), - Boolean(6, Type.BOOLEAN), - Vector3F(7, Type.ROTATION), - Position(8, Type.POSITION), - OptPosition(9, Type.OPTIONAL_POSITION), - Direction(10, Type.VAR_INT), - OptUUID(11, Type.OPTIONAL_UUID), - BlockID(12, Type.VAR_INT), - NBTTag(13, Type.NBT), + OptChat(5, Type.OPTIONAL_CHAT), + Slot(6, Type.FLAT_ITEM), + Boolean(7, Type.BOOLEAN), + Vector3F(8, Type.ROTATION), + Position(9, Type.POSITION), + OptPosition(10, Type.OPTIONAL_POSITION), + Direction(11, Type.VAR_INT), + OptUUID(12, Type.OPTIONAL_UUID), + BlockID(13, Type.VAR_INT), + NBTTag(14, Type.NBT), + UNKNOWN(15, null), // TODO do research Discontinued(99, null); private final int typeID; 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 ec28c0a93..ad5c2942e 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 @@ -62,7 +62,7 @@ public class ProtocolVersion { register(v1_12 = new ProtocolVersion(335, "1.12")); 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(351, "17w50a")); + register(v1_13 = new ProtocolVersion(352, "18w01a")); register(unknown = new ProtocolVersion(-1, "UNKNOWN")); } 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 bfe3feadf..b8a0c9484 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 @@ -63,6 +63,7 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { public static final Type NBT_ARRAY = new ArrayType<>(Type.NBT); public static final Type OPTIONAL_UUID = new OptUUIDType(); + public static final Type OPTIONAL_CHAT = new OptionalChatType(); public static final Type OPTIONAL_POSITION = new OptPositionType(); public static final Type ITEM = new ItemType(); diff --git a/common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/OptionalChatType.java b/common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/OptionalChatType.java new file mode 100644 index 000000000..527650a10 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/OptionalChatType.java @@ -0,0 +1,27 @@ +package us.myles.ViaVersion.api.type.types.minecraft; + +import io.netty.buffer.ByteBuf; +import us.myles.ViaVersion.api.type.Type; + +public class OptionalChatType extends Type { + public OptionalChatType() { + super(String.class); + } + + @Override + public String read(ByteBuf buffer) throws Exception { + boolean present = buffer.readBoolean(); + if (!present) return null; + return Type.STRING.read(buffer); + } + + @Override + public void write(ByteBuf buffer, String object) throws Exception { + if (object == null) { + buffer.writeBoolean(false); + } else { + buffer.writeBoolean(true); + Type.STRING.write(buffer, object); + } + } +} \ No newline at end of file diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/MetadataRewriter.java index 8a37c085e..eebedbf8d 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/MetadataRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/MetadataRewriter.java @@ -6,36 +6,46 @@ import us.myles.ViaVersion.api.entities.Entity1_12Types; 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.api.type.Type; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.packets.InventoryPackets; -import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.packets.WorldPackets; +import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.packets.WorldPackets; import java.util.ArrayList; import java.util.List; public class MetadataRewriter { public static void handleMetadata(int entityId, Entity1_12Types.EntityType type, List metadatas, UserConnection connection) { - // metadatas.clear(); for (Metadata metadata : new ArrayList<>(metadatas)) { + // Handle new MetaTypes + if (metadata.getMetaType().getTypeID() > 4) + metadata.setMetaType(MetaType1_13.byId(metadata.getMetaType().getTypeID() + 1)); + + // TODO Fix displayname + if (metadata.getId() == 2) { + metadata.setMetaType(MetaType1_13.OptChat); + metadata.setValue(metadata.getValue() != null ? Protocol1_9TO1_8.fixJson((String) metadata.getValue()) : null); + } + // 1.13 changed item to flat item (no data) - if (metadata.getMetaType().getType() == Type.ITEM) { + if (metadata.getMetaType() == MetaType1_13.Slot) { metadata.setMetaType(MetaType1_13.Slot); InventoryPackets.toClient((Item) metadata.getValue()); } - if (metadata.getMetaType().getTypeID() == MetaType1_13.BlockID.getTypeID()) { - // Convert to new block id - metadata.setValue(WorldPackets.toNewId((int) metadata.getValue())); - } + if (metadata.getMetaType() == MetaType1_13.BlockID) { + // Convert to new block id + metadata.setValue(WorldPackets.toNewId((int) metadata.getValue())); + } + // Handle other changes try { - if (type != null && type.is(Entity1_12Types.EntityType.AREA_EFFECT_CLOUD)) { - if (metadata.getId() == 9 || metadata.getId() == 10 || metadata.getId() == 11) { + if (type != null && type.is(Entity1_12Types.EntityType.AREA_EFFECT_CLOUD)) { + if (metadata.getId() == 9 || metadata.getId() == 10 || metadata.getId() == 11) { // TODO: AreaEffectCloud has lost 2 integers and gained "ef" // Will be implemented when more info is known metadatas.remove(metadata); // Remove } } - // TODO: Boat has changed + // TODO: Boat has changed } catch (Exception e) { metadatas.remove(metadata); if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) { @@ -46,5 +56,8 @@ public class MetadataRewriter { } } + for (Metadata metadata : metadatas) { + System.out.println(metadata.getMetaType() instanceof MetaType1_13); + } } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/ProtocolSnapshotTo1_12_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/ProtocolSnapshotTo1_12_2.java index b3d272272..ec8a72d4f 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/ProtocolSnapshotTo1_12_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/ProtocolSnapshotTo1_12_2.java @@ -157,14 +157,26 @@ public class ProtocolSnapshotTo1_12_2 extends Protocol { registerOutgoing(State.PLAY, 0x28, 0x29); registerOutgoing(State.PLAY, 0x29, 0x2A); registerOutgoing(State.PLAY, 0x2A, 0x2B); - registerOutgoing(State.PLAY, 0x2B, 0x2C); + // Craft recipe response + registerOutgoing(State.PLAY, 0x2B, 0x2C, new PacketRemapper() { + @Override + public void registerMap() { + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + // TODO This packet changed + wrapper.cancel(); + } + }); + } + }); registerOutgoing(State.PLAY, 0x2C, 0x2D); registerOutgoing(State.PLAY, 0x2D, 0x2E); registerOutgoing(State.PLAY, 0x2E, 0x2F); - registerOutgoing(State.PLAY, 0x2F, 0x30); - registerOutgoing(State.PLAY, 0x30, 0x31); + registerOutgoing(State.PLAY, 0x2F, 0x31); + registerOutgoing(State.PLAY, 0x30, 0x32); // Recipe - registerOutgoing(State.PLAY, 0x31, 0x32, new PacketRemapper() { + registerOutgoing(State.PLAY, 0x31, 0x33, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -177,11 +189,11 @@ public class ProtocolSnapshotTo1_12_2 extends Protocol { } }); - registerOutgoing(State.PLAY, 0x33, 0x34); - registerOutgoing(State.PLAY, 0x34, 0x35); + registerOutgoing(State.PLAY, 0x33, 0x35); + registerOutgoing(State.PLAY, 0x34, 0x36); // Respawn (save dimension id) - registerOutgoing(State.PLAY, 0x35, 0x36, new PacketRemapper() { + registerOutgoing(State.PLAY, 0x35, 0x37, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Dimension ID @@ -196,20 +208,20 @@ public class ProtocolSnapshotTo1_12_2 extends Protocol { } }); - registerOutgoing(State.PLAY, 0x36, 0x37); - registerOutgoing(State.PLAY, 0x37, 0x38); - registerOutgoing(State.PLAY, 0x38, 0x39); - registerOutgoing(State.PLAY, 0x39, 0x3A); - registerOutgoing(State.PLAY, 0x3A, 0x3B); - registerOutgoing(State.PLAY, 0x3B, 0x3C); + registerOutgoing(State.PLAY, 0x36, 0x38); + registerOutgoing(State.PLAY, 0x37, 0x39); + registerOutgoing(State.PLAY, 0x38, 0x3A); + registerOutgoing(State.PLAY, 0x39, 0x3B); + registerOutgoing(State.PLAY, 0x3A, 0x3C); + registerOutgoing(State.PLAY, 0x3B, 0x3D); - registerOutgoing(State.PLAY, 0x3D, 0x3E); - registerOutgoing(State.PLAY, 0x3E, 0x3F); + registerOutgoing(State.PLAY, 0x3D, 0x3F); + registerOutgoing(State.PLAY, 0x3E, 0x40); - registerOutgoing(State.PLAY, 0x40, 0x41); - registerOutgoing(State.PLAY, 0x41, 0x42); + registerOutgoing(State.PLAY, 0x40, 0x42); + registerOutgoing(State.PLAY, 0x41, 0x43); // Scoreboard Objective - registerOutgoing(State.PLAY, 0x42, 0x43, new PacketRemapper() { + registerOutgoing(State.PLAY, 0x42, 0x44, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); @@ -228,20 +240,22 @@ public class ProtocolSnapshotTo1_12_2 extends Protocol { } }); - registerOutgoing(State.PLAY, 0x43, 0x44); - registerOutgoing(State.PLAY, 0x44, 0x45); - registerOutgoing(State.PLAY, 0x45, 0x46); - registerOutgoing(State.PLAY, 0x46, 0x47); - registerOutgoing(State.PLAY, 0x47, 0x48); - registerOutgoing(State.PLAY, 0x48, 0x49); + // TODO UPDATE BLOCK ENTITY? + + registerOutgoing(State.PLAY, 0x43, 0x45); + registerOutgoing(State.PLAY, 0x44, 0x46); + registerOutgoing(State.PLAY, 0x45, 0x47); + registerOutgoing(State.PLAY, 0x46, 0x48); + registerOutgoing(State.PLAY, 0x47, 0x49); + registerOutgoing(State.PLAY, 0x48, 0x4A); // New packet 0x4A - Stop sound (TODO: Migrate from Plugin Messages) - registerOutgoing(State.PLAY, 0x49, 0x4B); - registerOutgoing(State.PLAY, 0x4A, 0x4C); - registerOutgoing(State.PLAY, 0x4B, 0x4D); - registerOutgoing(State.PLAY, 0x4C, 0x4E); - registerOutgoing(State.PLAY, 0x4D, 0x4F); - registerOutgoing(State.PLAY, 0x4E, 0x50); - registerOutgoing(State.PLAY, 0x4F, 0x51); + registerOutgoing(State.PLAY, 0x49, 0x4C); + registerOutgoing(State.PLAY, 0x4A, 0x4D); + registerOutgoing(State.PLAY, 0x4B, 0x4E); + registerOutgoing(State.PLAY, 0x4C, 0x4F); + registerOutgoing(State.PLAY, 0x4D, 0x50); + registerOutgoing(State.PLAY, 0x4E, 0x51); + registerOutgoing(State.PLAY, 0x4F, 0x52); // New packet 0x52 - Declare Recipes // New packet 0x53 - Tags diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/EntityPackets.java index 35c77dfdc..3c88abcba 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/EntityPackets.java @@ -8,6 +8,7 @@ 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_12; +import us.myles.ViaVersion.api.type.types.version.Types1_13; import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.MetadataRewriter; import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.storage.EntityTracker; @@ -28,7 +29,6 @@ public class EntityPackets { 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); @@ -57,7 +57,7 @@ public class EntityPackets { map(Type.SHORT); // 9 - Velocity X map(Type.SHORT); // 10 - Velocity Y map(Type.SHORT); // 11 - Velocity Z - map(Types1_12.METADATA_LIST); // 12 - Metadata + map(Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); // 12 - Metadata handler(new PacketHandler() { @Override @@ -68,14 +68,42 @@ public class EntityPackets { Entity1_12Types.EntityType entType = Entity1_12Types.getTypeFromId(type, false); // Register Type ID wrapper.user().get(EntityTracker.class).addEntity(entityId, entType); - MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_12.METADATA_LIST, 0), wrapper.user()); + + 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_12.METADATA_LIST, 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_12Types.EntityType entType = Entity1_12Types.EntityType.PLAYER; + System.out.println("REGISTER 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, 0x32, 0x33, new PacketRemapper() { + protocol.registerOutgoing(State.PLAY, 0x32, 0x34, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT_ARRAY); // 0 - Entity IDS @@ -91,11 +119,11 @@ public class EntityPackets { }); // Metadata packet - protocol.registerOutgoing(State.PLAY, 0x3C, 0x3D, new PacketRemapper() { + protocol.registerOutgoing(State.PLAY, 0x3C, 0x3E, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID - map(Types1_12.METADATA_LIST); // 1 - Metadata list + map(Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); // 1 - Metadata list handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { @@ -103,7 +131,7 @@ public class EntityPackets { Optional type = wrapper.user().get(EntityTracker.class).get(entityId); - MetadataRewriter.handleMetadata(entityId, type.orNull(), wrapper.get(Types1_12.METADATA_LIST, 0), wrapper.user()); + 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/protocolsnapshotto1_12_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/InventoryPackets.java index 51a8bda2f..c115b465a 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/InventoryPackets.java @@ -101,7 +101,7 @@ public class InventoryPackets { }); // Entity Equipment Packet - protocol.registerOutgoing(State.PLAY, 0x3F, 0x40, new PacketRemapper() { + protocol.registerOutgoing(State.PLAY, 0x3F, 0x41, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID diff --git a/jar/pom.xml b/jar/pom.xml index 08721eed9..e84fcd6bb 100644 --- a/jar/pom.xml +++ b/jar/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-17w50a + 1.4.0-18w01a 4.0.0 viaversion-jar diff --git a/pom.xml b/pom.xml index 0687f1176..6a7327b37 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ us.myles viaversion-parent - 1.4.0-17w50a + 1.4.0-18w01a pom viaversion-parent diff --git a/sponge-legacy/pom.xml b/sponge-legacy/pom.xml index d573aea16..73686df90 100644 --- a/sponge-legacy/pom.xml +++ b/sponge-legacy/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-17w50a + 1.4.0-18w01a 4.0.0 diff --git a/sponge/pom.xml b/sponge/pom.xml index bdd82ff18..9e0ce56c4 100644 --- a/sponge/pom.xml +++ b/sponge/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-17w50a + 1.4.0-18w01a 4.0.0