From b4f1d64cb0437a9a11f270318e3159c74a37ed0a Mon Sep 17 00:00:00 2001 From: Desetude Date: Mon, 6 Aug 2018 09:03:44 +0100 Subject: [PATCH] Add 1.8 support --- .../proxy/protocol/ProtocolConstants.java | 4 +++- .../proxy/protocol/StateRegistry.java | 15 +++++++++++++++ .../proxy/protocol/packet/ClientSettings.java | 10 ++++++++-- .../proxy/protocol/packet/JoinGame.java | 12 ++++++++++-- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolConstants.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolConstants.java index 54b021775..421a04124 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolConstants.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolConstants.java @@ -3,6 +3,7 @@ package com.velocitypowered.proxy.protocol; import java.util.Arrays; public enum ProtocolConstants { ; + public static final int MINECRAFT_1_8 = 47; public static final int MINECRAFT_1_9 = 107; public static final int MINECRAFT_1_9_1 = 108; public static final int MINECRAFT_1_9_2 = 109; @@ -15,9 +16,10 @@ public enum ProtocolConstants { ; public static final int MINECRAFT_1_12_2 = 340; public static final int MINECRAFT_1_13 = 393; - public static final int MINIMUM_GENERIC_VERSION = MINECRAFT_1_9; + public static final int MINIMUM_GENERIC_VERSION = MINECRAFT_1_8; public static final int[] SUPPORTED_VERSIONS = new int[] { + MINECRAFT_1_8, MINECRAFT_1_9, MINECRAFT_1_9_1, MINECRAFT_1_9_2, 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 891cdf8c9..3658126df 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java @@ -32,21 +32,25 @@ public enum StateRegistry { PLAY { { SERVERBOUND.register(Chat.class, Chat::new, + map(0x01, MINECRAFT_1_8), map(0x02, MINECRAFT_1_9), map(0x03, MINECRAFT_1_12), map(0x02, MINECRAFT_1_12_2), map(0x02, MINECRAFT_1_13)); SERVERBOUND.register(ClientSettings.class, ClientSettings::new, + map(0x15, MINECRAFT_1_8), map(0x04, MINECRAFT_1_9), map(0x05, MINECRAFT_1_12), map(0x04, MINECRAFT_1_12_1), map(0x04, MINECRAFT_1_13)); SERVERBOUND.register(PluginMessage.class, PluginMessage::new, + map(0x17, MINECRAFT_1_8), map(0x09, MINECRAFT_1_9), map(0x0A, MINECRAFT_1_12), map(0x09, MINECRAFT_1_12_1), map(0x0A, MINECRAFT_1_13)); SERVERBOUND.register(KeepAlive.class, KeepAlive::new, + map(0x00, MINECRAFT_1_8), map(0x0B, MINECRAFT_1_9), map(0x0C, MINECRAFT_1_12), map(0x0B, MINECRAFT_1_12_1), @@ -56,46 +60,56 @@ public enum StateRegistry { map(0x0C, MINECRAFT_1_9), map(0x0C, MINECRAFT_1_12)); CLIENTBOUND.register(Chat.class, Chat::new, + map(0x02, MINECRAFT_1_8), map(0x0F, MINECRAFT_1_9), map(0x0F, MINECRAFT_1_12), map(0x0E, MINECRAFT_1_13)); CLIENTBOUND.register(PluginMessage.class, PluginMessage::new, + map(0x3F, MINECRAFT_1_8), map(0x18, MINECRAFT_1_9), map(0x18, MINECRAFT_1_12), map(0x19, MINECRAFT_1_13)); CLIENTBOUND.register(Disconnect.class, Disconnect::new, + map(0x40, MINECRAFT_1_8), map(0x1A, MINECRAFT_1_9), map(0x1A, MINECRAFT_1_12), map(0x1B, MINECRAFT_1_13)); CLIENTBOUND.register(KeepAlive.class, KeepAlive::new, + map(0x00, MINECRAFT_1_8), map(0x1F, MINECRAFT_1_9), map(0x1F, MINECRAFT_1_12), map(0x21, MINECRAFT_1_13)); CLIENTBOUND.register(JoinGame.class, JoinGame::new, + map(0x01, MINECRAFT_1_8), map(0x23, MINECRAFT_1_9), map(0x23, MINECRAFT_1_12), map(0x25, MINECRAFT_1_13)); CLIENTBOUND.register(Respawn.class, Respawn::new, + map(0x07, MINECRAFT_1_8), map(0x33, MINECRAFT_1_9), map(0x34, MINECRAFT_1_12), map(0x35, MINECRAFT_1_12_2), map(0x38, MINECRAFT_1_13)); CLIENTBOUND.register(ScoreboardDisplay.class, ScoreboardDisplay::new, + map(0x3D, MINECRAFT_1_8), map(0x38, MINECRAFT_1_9), map(0x3A, MINECRAFT_1_12), map(0x3B, MINECRAFT_1_12_1), map(0x3E, MINECRAFT_1_13)); CLIENTBOUND.register(ScoreboardObjective.class, ScoreboardObjective::new, + map(0x3B, MINECRAFT_1_8), map(0x3F, MINECRAFT_1_9), map(0x41, MINECRAFT_1_12), map(0x42, MINECRAFT_1_12_1), map(0x45, MINECRAFT_1_13)); CLIENTBOUND.register(ScoreboardTeam.class, ScoreboardTeam::new, + map(0x3E, MINECRAFT_1_8), map(0x41, MINECRAFT_1_9), map(0x43, MINECRAFT_1_12), map(0x44, MINECRAFT_1_12_1), map(0x47, MINECRAFT_1_13)); CLIENTBOUND.register(ScoreboardSetScore.class, ScoreboardSetScore::new, + map(0x3C, MINECRAFT_1_8), map(0x42, MINECRAFT_1_9), map(0x44, MINECRAFT_1_12), map(0x45, MINECRAFT_1_12_1), @@ -266,6 +280,7 @@ public enum StateRegistry { private static PacketMapping[] genericMappings(int id) { return new PacketMapping[]{ + map(id, MINECRAFT_1_8), map(id, MINECRAFT_1_9), map(id, MINECRAFT_1_12), map(id, MINECRAFT_1_13) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientSettings.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientSettings.java index 74ca21bf8..cd5a92bab 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientSettings.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientSettings.java @@ -80,7 +80,10 @@ public class ClientSettings implements MinecraftPacket { this.chatVisibility = ProtocolUtils.readVarInt(buf); this.chatColors = buf.readBoolean(); this.skinParts = buf.readUnsignedByte(); - this.mainHand = ProtocolUtils.readVarInt(buf); + + if (protocolVersion >= ProtocolConstants.MINECRAFT_1_9) { + this.mainHand = ProtocolUtils.readVarInt(buf); + } } @Override @@ -90,6 +93,9 @@ public class ClientSettings implements MinecraftPacket { ProtocolUtils.writeVarInt(buf, chatVisibility); buf.writeBoolean(chatColors); buf.writeByte(skinParts); - ProtocolUtils.writeVarInt(buf, mainHand); + + if (protocolVersion >= ProtocolConstants.MINECRAFT_1_9) { + ProtocolUtils.writeVarInt(buf, mainHand); + } } } 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 100950a74..69aaa92da 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 @@ -87,7 +87,11 @@ public class JoinGame implements MinecraftPacket { public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { this.entityId = buf.readInt(); this.gamemode = buf.readUnsignedByte(); - this.dimension = buf.readInt(); + if (protocolVersion >= ProtocolConstants.MINECRAFT_1_9_1) { + this.dimension = buf.readInt(); + } else { + this.dimension = buf.readByte(); + } this.difficulty = buf.readUnsignedByte(); this.maxPlayers = buf.readUnsignedByte(); this.levelType = ProtocolUtils.readString(buf, 16); @@ -98,7 +102,11 @@ public class JoinGame implements MinecraftPacket { public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { buf.writeInt(entityId); buf.writeByte(gamemode); - buf.writeInt(dimension); + if (protocolVersion >= ProtocolConstants.MINECRAFT_1_9_1) { + buf.writeInt(dimension); + } else { + buf.writeByte(dimension); + } buf.writeByte(difficulty); buf.writeByte(maxPlayers); ProtocolUtils.writeString(buf, levelType);