From ac192c281c8d694f76ad5ec513b9970ff868a80d Mon Sep 17 00:00:00 2001 From: Leymooo Date: Thu, 18 Apr 2019 22:45:17 +0300 Subject: [PATCH] 1.14-pre5 --- .../api/network/ProtocolVersion.java | 7 +- .../proxy/protocol/StateRegistry.java | 68 +++++++++++++------ .../proxy/protocol/packet/JoinGame.java | 24 ++++++- .../proxy/protocol/packet/Respawn.java | 8 ++- 4 files changed, 78 insertions(+), 29 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java b/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java index 18763a2c8..8841b1a45 100644 --- a/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java +++ b/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java @@ -26,8 +26,9 @@ public enum ProtocolVersion { MINECRAFT_1_12_2(340, "1.12.2"), MINECRAFT_1_13(393, "1.13"), MINECRAFT_1_13_1(401, "1.13.1"), - MINECRAFT_1_13_2(404, "1.13.2"); - + MINECRAFT_1_13_2(404, "1.13.2"), + MINECRAFT_1_14(476, "1.14"); + private final int protocol; private final String name; @@ -38,7 +39,7 @@ public enum ProtocolVersion { /** * Represents the highest supported version. */ - public static final ProtocolVersion MAXIMUM_VERSION = MINECRAFT_1_13_2; + public static final ProtocolVersion MAXIMUM_VERSION = MINECRAFT_1_14; /** * The user-friendly representation of the lowest and highest supported versions. diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java index daf8519bf..bd7dbd76b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java @@ -9,6 +9,7 @@ import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_12_2; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_13; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_13_1; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_13_2; +import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_14; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_8; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9_1; @@ -91,104 +92,123 @@ public enum StateRegistry { map(0x01, MINECRAFT_1_9, false), map(0x02, MINECRAFT_1_12, false), map(0x01, MINECRAFT_1_12_1, false), - map(0x05, MINECRAFT_1_13, false)); + map(0x05, MINECRAFT_1_13, false), + map(0x06, MINECRAFT_1_14, false)); serverbound.register(Chat.class, Chat::new, map(0x01, MINECRAFT_1_8, false), map(0x02, MINECRAFT_1_9, false), map(0x03, MINECRAFT_1_12, false), map(0x02, MINECRAFT_1_12_1, false), - map(0x02, MINECRAFT_1_13, false)); + map(0x02, MINECRAFT_1_13, false), + map(0x03, MINECRAFT_1_14, false)); serverbound.register(ClientSettings.class, ClientSettings::new, map(0x15, MINECRAFT_1_8, false), map(0x04, MINECRAFT_1_9, false), map(0x05, MINECRAFT_1_12, false), map(0x04, MINECRAFT_1_12_1, false), - map(0x04, MINECRAFT_1_13, false)); + map(0x04, MINECRAFT_1_13, false), + map(0x05, MINECRAFT_1_14, false)); serverbound.register(PluginMessage.class, PluginMessage::new, map(0x17, MINECRAFT_1_8, false), map(0x09, MINECRAFT_1_9, false), map(0x0A, MINECRAFT_1_12, false), map(0x09, MINECRAFT_1_12_1, false), - map(0x0A, MINECRAFT_1_13, false)); + map(0x0A, MINECRAFT_1_13, false), + map(0x0B, MINECRAFT_1_14, false)); serverbound.register(KeepAlive.class, KeepAlive::new, map(0x00, MINECRAFT_1_8, false), map(0x0B, MINECRAFT_1_9, false), map(0x0C, MINECRAFT_1_12, false), map(0x0B, MINECRAFT_1_12_1, false), - map(0x0E, MINECRAFT_1_13, false)); + map(0x0E, MINECRAFT_1_13, false), + map(0x0F, MINECRAFT_1_14, false)); serverbound.register(ResourcePackResponse.class, ResourcePackResponse::new, map(0x19, MINECRAFT_1_8, false), map(0x16, MINECRAFT_1_9, false), map(0x18, MINECRAFT_1_12, false), - map(0x1D, MINECRAFT_1_13, false)); + map(0x1D, MINECRAFT_1_13, false), + map(0x1F, MINECRAFT_1_14, false)); clientbound.register(BossBar.class, BossBar::new, map(0x0C, MINECRAFT_1_9, false), map(0x0C, MINECRAFT_1_12, false), - map(0x0C, MINECRAFT_1_13, false)); + map(0x0C, MINECRAFT_1_13, false), + map(0x0C, MINECRAFT_1_14, false)); clientbound.register(Chat.class, Chat::new, map(0x02, MINECRAFT_1_8, true), map(0x0F, MINECRAFT_1_9, true), map(0x0F, MINECRAFT_1_12, true), - map(0x0E, MINECRAFT_1_13, true)); + map(0x0E, MINECRAFT_1_13, true), + map(0x0E, MINECRAFT_1_14, false)); clientbound.register(TabCompleteResponse.class, TabCompleteResponse::new, map(0x3A, MINECRAFT_1_8, false), map(0x0E, MINECRAFT_1_9, false), map(0x0E, MINECRAFT_1_12, false), - map(0x10, MINECRAFT_1_13, false)); + map(0x10, MINECRAFT_1_13, false), + map(0x10, MINECRAFT_1_14, false)); clientbound.register(AvailableCommands.class, AvailableCommands::new, - map(0x11, MINECRAFT_1_13, false)); + map(0x11, MINECRAFT_1_13, false), + map(0x11, MINECRAFT_1_14, false)); clientbound.register(PluginMessage.class, PluginMessage::new, map(0x3F, MINECRAFT_1_8, false), map(0x18, MINECRAFT_1_9, false), map(0x18, MINECRAFT_1_12, false), - map(0x19, MINECRAFT_1_13, false)); + map(0x19, MINECRAFT_1_13, false), + map(0x18, MINECRAFT_1_14, false)); clientbound.register(Disconnect.class, Disconnect::new, map(0x40, MINECRAFT_1_8, false), map(0x1A, MINECRAFT_1_9, false), map(0x1A, MINECRAFT_1_12, false), - map(0x1B, MINECRAFT_1_13, false)); + map(0x1B, MINECRAFT_1_13, false), + map(0x1A, MINECRAFT_1_14, false)); clientbound.register(KeepAlive.class, KeepAlive::new, map(0x00, MINECRAFT_1_8, false), map(0x1F, MINECRAFT_1_9, false), map(0x1F, MINECRAFT_1_12, false), - map(0x21, MINECRAFT_1_13, false)); + map(0x21, MINECRAFT_1_13, false), + map(0x20, MINECRAFT_1_14, false)); clientbound.register(JoinGame.class, JoinGame::new, map(0x01, MINECRAFT_1_8, false), map(0x23, MINECRAFT_1_9, false), map(0x23, MINECRAFT_1_12, false), - map(0x25, MINECRAFT_1_13, false)); + map(0x25, MINECRAFT_1_13, false), + map(0x25, MINECRAFT_1_14, false)); clientbound.register(Respawn.class, Respawn::new, map(0x07, MINECRAFT_1_8, true), map(0x33, MINECRAFT_1_9, true), map(0x34, MINECRAFT_1_12, true), map(0x35, MINECRAFT_1_12_1, true), - map(0x38, MINECRAFT_1_13, true)); + map(0x38, MINECRAFT_1_13, true), + map(0x3A, MINECRAFT_1_14, true)); clientbound.register(ResourcePackRequest.class, ResourcePackRequest::new, map(0x48, MINECRAFT_1_8, true), map(0x32, MINECRAFT_1_9, true), map(0x33, MINECRAFT_1_12, true), map(0x34, MINECRAFT_1_12_1, true), - map(0x37, MINECRAFT_1_13, true)); + map(0x37, MINECRAFT_1_13, true), + map(0x39, MINECRAFT_1_14, true)); clientbound.register(HeaderAndFooter.class, HeaderAndFooter::new, map(0x47, MINECRAFT_1_8, true), map(0x48, MINECRAFT_1_9, true), map(0x47, MINECRAFT_1_9_4, true), map(0x49, MINECRAFT_1_12, true), map(0x4A, MINECRAFT_1_12_1, true), - map(0x4E, MINECRAFT_1_13, true)); + map(0x4E, MINECRAFT_1_13, true), + map(0x53, MINECRAFT_1_14, true)); clientbound.register(TitlePacket.class, TitlePacket::new, map(0x45, MINECRAFT_1_8, true), map(0x45, MINECRAFT_1_9, true), map(0x47, MINECRAFT_1_12, true), map(0x48, MINECRAFT_1_12_1, true), - map(0x4B, MINECRAFT_1_13, true)); + map(0x4B, MINECRAFT_1_13, true), + map(0x4F, MINECRAFT_1_14, true)); clientbound.register(PlayerListItem.class, PlayerListItem::new, map(0x38, MINECRAFT_1_8, false), map(0x2D, MINECRAFT_1_9, false), map(0x2D, MINECRAFT_1_12, false), map(0x2E, MINECRAFT_1_12_1, false), - map(0x30, MINECRAFT_1_13, false)); + map(0x30, MINECRAFT_1_13, false), + map(0x33, MINECRAFT_1_14, false)); } }, LOGIN { @@ -198,7 +218,8 @@ public enum StateRegistry { serverbound.register(EncryptionResponse.class, EncryptionResponse::new, genericMappings(0x01)); serverbound.register(LoginPluginResponse.class, LoginPluginResponse::new, - map(0x02, MINECRAFT_1_13, false)); + map(0x02, MINECRAFT_1_13, false), + map(0x02, MINECRAFT_1_14, false)); clientbound.register(Disconnect.class, Disconnect::new, genericMappings(0x00)); @@ -209,7 +230,8 @@ public enum StateRegistry { clientbound.register(SetCompression.class, SetCompression::new, genericMappings(0x03)); clientbound.register(LoginPluginMessage.class, LoginPluginMessage::new, - map(0x04, MINECRAFT_1_13, false)); + map(0x04, MINECRAFT_1_13, false), + map(0x04, MINECRAFT_1_14, false)); } }; @@ -231,6 +253,7 @@ public enum StateRegistry { LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_12, EnumSet.of(MINECRAFT_1_12_1)); LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_12_1, EnumSet.of(MINECRAFT_1_12_2)); LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_13, EnumSet.of(MINECRAFT_1_13_1, MINECRAFT_1_13_2)); + //for 1.14 ??? } private final Direction direction; @@ -396,7 +419,8 @@ public enum StateRegistry { map(id, MINECRAFT_1_8, false), map(id, MINECRAFT_1_9, false), map(id, MINECRAFT_1_12, false), - map(id, MINECRAFT_1_13, false) + map(id, MINECRAFT_1_13, false), + map(id, MINECRAFT_1_14, false) }; } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java index bae132f5c..af5eb6774 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java @@ -15,6 +15,7 @@ public class JoinGame implements MinecraftPacket { private short difficulty; private short maxPlayers; private @Nullable String levelType; + private int viewDistance; //1.14+ private boolean reducedDebugInfo; public int getEntityId() { @@ -68,6 +69,14 @@ public class JoinGame implements MinecraftPacket { this.levelType = levelType; } + public int getViewDistance() { + return viewDistance; + } + + public void setViewDistance(int viewDistance) { + this.viewDistance = viewDistance; + } + public boolean isReducedDebugInfo() { return reducedDebugInfo; } @@ -85,6 +94,7 @@ public class JoinGame implements MinecraftPacket { + ", difficulty=" + difficulty + ", maxPlayers=" + maxPlayers + ", levelType='" + levelType + '\'' + + ", viewDistance=" + viewDistance + ", reducedDebugInfo=" + reducedDebugInfo + '}'; } @@ -98,9 +108,14 @@ public class JoinGame implements MinecraftPacket { } else { this.dimension = buf.readByte(); } - this.difficulty = buf.readUnsignedByte(); + if (version.compareTo(ProtocolVersion.MINECRAFT_1_13_2) <= 0) { + this.difficulty = buf.readUnsignedByte(); + } this.maxPlayers = buf.readUnsignedByte(); this.levelType = ProtocolUtils.readString(buf, 16); + if (version.compareTo(ProtocolVersion.MINECRAFT_1_14) >= 0) { + this.viewDistance = ProtocolUtils.readVarInt(buf); + } this.reducedDebugInfo = buf.readBoolean(); } @@ -113,12 +128,17 @@ public class JoinGame implements MinecraftPacket { } else { buf.writeByte(dimension); } - buf.writeByte(difficulty); + if (version.compareTo(ProtocolVersion.MINECRAFT_1_13_2) <= 0) { + buf.writeByte(difficulty); + } buf.writeByte(maxPlayers); if (levelType == null) { throw new IllegalStateException("No level type specified."); } ProtocolUtils.writeString(buf, levelType); + if (version.compareTo(ProtocolVersion.MINECRAFT_1_14) >= 0) { + ProtocolUtils.writeVarInt(buf,viewDistance); + } buf.writeBoolean(reducedDebugInfo); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java index 89a607170..4979954fe 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java @@ -68,7 +68,9 @@ public class Respawn implements MinecraftPacket { @Override public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { this.dimension = buf.readInt(); - this.difficulty = buf.readUnsignedByte(); + if (version.compareTo(ProtocolVersion.MINECRAFT_1_13_2) <= 0) { + this.difficulty = buf.readUnsignedByte(); + } this.gamemode = buf.readUnsignedByte(); this.levelType = ProtocolUtils.readString(buf, 16); } @@ -76,7 +78,9 @@ public class Respawn implements MinecraftPacket { @Override public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { buf.writeInt(dimension); - buf.writeByte(difficulty); + if (version.compareTo(ProtocolVersion.MINECRAFT_1_13_2) <= 0) { + buf.writeByte(difficulty); + } buf.writeByte(gamemode); ProtocolUtils.writeString(buf, levelType); }