diff --git a/bukkit/pom.xml b/bukkit/pom.xml index cfae64176..07f87bfb2 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 2.0.2-SNAPSHOT + 2.1.0-1.14.1-pre1 4.0.0 diff --git a/bungee/pom.xml b/bungee/pom.xml index 5a9fdd1fd..d195808c6 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 2.0.2-SNAPSHOT + 2.1.0-1.14.1-pre1 4.0.0 diff --git a/common/pom.xml b/common/pom.xml index d55c461bf..0d150ef17 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 2.0.2-SNAPSHOT + 2.1.0-1.14.1-pre1 4.0.0 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 c77885625..a56806bc3 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 @@ -15,6 +15,7 @@ import us.myles.ViaVersion.protocols.protocol1_12_2to1_12_1.Protocol1_12_2To1_12 import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.Protocol1_12To1_11_1; import us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.Protocol1_13_2To1_13_1; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; +import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.Protocol1_14_1To1_14; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2; import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.Protocol1_9_1_2To1_9_3_4; import us.myles.ViaVersion.protocols.protocol1_9_1to1_9.Protocol1_9_1To1_9; @@ -62,6 +63,7 @@ public class ProtocolRegistry { registerProtocol(new Protocol1_13_2To1_13_1(), Arrays.asList(ProtocolVersion.v1_13_2.getId()), ProtocolVersion.v1_13_1.getId()); registerProtocol(new Protocol1_14To1_13_2(), Arrays.asList(ProtocolVersion.v1_14.getId()), ProtocolVersion.v1_13_2.getId()); + registerProtocol(new Protocol1_14_1To1_14(), Arrays.asList(ProtocolVersion.v1_14_1.getId()), ProtocolVersion.v1_14.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 e43721e4b..5242a42f4 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 @@ -36,6 +36,7 @@ public class ProtocolVersion { public static final ProtocolVersion v1_13_1; public static final ProtocolVersion v1_13_2; public static final ProtocolVersion v1_14; + public static final ProtocolVersion v1_14_1; public static final ProtocolVersion unknown; private final int id; @@ -68,6 +69,7 @@ public class ProtocolVersion { register(v1_13_1 = new ProtocolVersion(401, "1.13.1")); register(v1_13_2 = new ProtocolVersion(404, "1.13.2")); register(v1_14 = new ProtocolVersion(477, "1.14")); + register(v1_14_1 = new ProtocolVersion(478, "1.14.1")); register(unknown = new ProtocolVersion(-1, "UNKNOWN")); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/MetadataRewriter.java new file mode 100644 index 000000000..f8724e2d5 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/MetadataRewriter.java @@ -0,0 +1,33 @@ +package us.myles.ViaVersion.protocols.protocol1_14_1to1_14; + +import us.myles.ViaVersion.api.Via; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.entities.Entity1_14Types; +import us.myles.ViaVersion.api.minecraft.metadata.Metadata; + +import java.util.ArrayList; +import java.util.List; + +public class MetadataRewriter { + + public static void handleMetadata(int entityId, Entity1_14Types.EntityType type, List metadatas, UserConnection connection) { + if (type == null) return; + + for (Metadata metadata : new ArrayList<>(metadatas)) { + try { + if (type.is(Entity1_14Types.EntityType.VILLAGER) || type.is(Entity1_14Types.EntityType.WANDERING_TRADER)) { + if (metadata.getId() >= 15) { + metadata.setId(metadata.getId() + 1); + } + } + } 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/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/Protocol1_14_1To1_14.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/Protocol1_14_1To1_14.java new file mode 100644 index 000000000..77b4182ef --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/Protocol1_14_1To1_14.java @@ -0,0 +1,19 @@ +package us.myles.ViaVersion.protocols.protocol1_14_1to1_14; + +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.protocol.Protocol; +import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.packets.EntityPackets; +import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker; + +public class Protocol1_14_1To1_14 extends Protocol { + + @Override + protected void registerPackets() { + EntityPackets.register(this); + } + + @Override + public void init(UserConnection userConnection) { + userConnection.put(new EntityTracker(userConnection)); + } +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/packets/EntityPackets.java new file mode 100644 index 000000000..7d7373909 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/packets/EntityPackets.java @@ -0,0 +1,101 @@ +package us.myles.ViaVersion.protocols.protocol1_14_1to1_14.packets; + +import com.google.common.base.Optional; +import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.entities.Entity1_14Types; +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_14; +import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.MetadataRewriter; +import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker; + +public class EntityPackets { + + public static void register(Protocol protocol) { + + // Spawn Mob + protocol.registerOutgoing(State.PLAY, 0x03, 0x03, 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_14.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_14Types.EntityType entType = Entity1_14Types.getTypeFromId(type); + + // Register Type ID + wrapper.user().get(EntityTracker.class).addEntity(entityId, entType); + + MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user()); + } + }); + } + }); + + // Spawn Player + 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_14.METADATA_LIST); // 7 - Metadata + + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int entityId = wrapper.get(Type.VAR_INT, 0); + + Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER; + + // Register Type ID + wrapper.user().get(EntityTracker.class).addEntity(entityId, entType); + MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user()); + } + }); + } + }); + + // Entity Metadata + protocol.registerOutgoing(State.PLAY, 0x43, 0x43, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); // 0 - Entity ID + map(Types1_14.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_14.METADATA_LIST, 0), wrapper.user()); + } + }); + } + }); + } +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/storage/EntityTracker.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/storage/EntityTracker.java new file mode 100644 index 000000000..c28f14b49 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/storage/EntityTracker.java @@ -0,0 +1,45 @@ +package us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage; + +import com.google.common.base.Optional; +import lombok.Getter; +import lombok.Setter; +import us.myles.ViaVersion.api.data.ExternalJoinGameListener; +import us.myles.ViaVersion.api.data.StoredObject; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.entities.Entity1_14Types; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class EntityTracker extends StoredObject implements ExternalJoinGameListener { + private final Map clientEntityTypes = new ConcurrentHashMap<>(); + @Getter + @Setter + private int clientEntityId; + + public EntityTracker(UserConnection user) { + super(user); + } + + public void removeEntity(int entityId) { + clientEntityTypes.remove(entityId); + } + + public void addEntity(int entityId, Entity1_14Types.EntityType type) { + clientEntityTypes.put(entityId, type); + } + + public boolean has(int entityId) { + return clientEntityTypes.containsKey(entityId); + } + + public Optional get(int id) { + return Optional.fromNullable(clientEntityTypes.get(id)); + } + + @Override + public void onExternalJoinGame(int playerEntityId) { + clientEntityId = playerEntityId; + clientEntityTypes.put(playerEntityId, Entity1_14Types.EntityType.PLAYER); + } +} diff --git a/jar/pom.xml b/jar/pom.xml index b81450cc3..92bb42d6e 100644 --- a/jar/pom.xml +++ b/jar/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 2.0.2-SNAPSHOT + 2.1.0-1.14.1-pre1 4.0.0 viaversion-jar diff --git a/pom.xml b/pom.xml index ee74971f7..4cc08776d 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ us.myles viaversion-parent - 2.0.2-SNAPSHOT + 2.1.0-1.14.1-pre1 pom viaversion-parent diff --git a/sponge-legacy/pom.xml b/sponge-legacy/pom.xml index d983cc973..e9088a97b 100644 --- a/sponge-legacy/pom.xml +++ b/sponge-legacy/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 2.0.2-SNAPSHOT + 2.1.0-1.14.1-pre1 4.0.0 diff --git a/sponge/pom.xml b/sponge/pom.xml index aad9f0855..30d56ba3d 100644 --- a/sponge/pom.xml +++ b/sponge/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 2.0.2-SNAPSHOT + 2.1.0-1.14.1-pre1 4.0.0 diff --git a/velocity/pom.xml b/velocity/pom.xml index cade95e88..431910fbe 100644 --- a/velocity/pom.xml +++ b/velocity/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 2.0.2-SNAPSHOT + 2.1.0-1.14.1-pre1 4.0.0