From 4ba8996fedba6f7a2dc96bb11d879a335361c046 Mon Sep 17 00:00:00 2001 From: Lechner Markus Date: Wed, 1 Jul 2020 22:01:33 +0200 Subject: [PATCH 1/3] Changes 20w27a --- .../api/network/ProtocolVersion.java | 3 +- .../proxy/protocol/StateRegistry.java | 4 +- .../proxy/protocol/packet/JoinGame.java | 44 ++++++++++++++++--- 3 files changed, 42 insertions(+), 9 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 152aae5f3..cfc11b608 100644 --- a/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java +++ b/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java @@ -36,7 +36,8 @@ public enum ProtocolVersion { MINECRAFT_1_15_1(575, "1.15.1"), MINECRAFT_1_15_2(578, "1.15.2"), MINECRAFT_1_16(735, "1.16"), - MINECRAFT_1_16_1(736, "1.16.1"); + MINECRAFT_1_16_1(736, "1.16.1"), + MINECRAFT_1_16_2(738, "1.16.2"); private final int protocol; private final String name; 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 658c818d7..2b89b575c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java @@ -7,6 +7,7 @@ import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_13; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_14; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_15; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_16; +import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_16_2; 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_4; @@ -122,7 +123,8 @@ public enum StateRegistry { map(0x18, MINECRAFT_1_12, false), map(0x1D, MINECRAFT_1_13, false), map(0x1F, MINECRAFT_1_14, false), - map(0x20, MINECRAFT_1_16, false)); + map(0x20, MINECRAFT_1_16, false), + map(0x21, MINECRAFT_1_16_2, false)); clientbound.register(BossBar.class, BossBar::new, map(0x0C, MINECRAFT_1_9, 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 630a60de2..3dd55a265 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 @@ -17,7 +17,8 @@ public class JoinGame implements MinecraftPacket { private int dimension; private long partialHashedSeed; // 1.15+ private short difficulty; - private short maxPlayers; + private boolean isHardcore; + private int maxPlayers; private @Nullable String levelType; private int viewDistance; // 1.14+ private boolean reducedDebugInfo; @@ -62,11 +63,11 @@ public class JoinGame implements MinecraftPacket { this.difficulty = difficulty; } - public short getMaxPlayers() { + public int getMaxPlayers() { return maxPlayers; } - public void setMaxPlayers(short maxPlayers) { + public void setMaxPlayers(int maxPlayers) { this.maxPlayers = maxPlayers; } @@ -118,6 +119,14 @@ public class JoinGame implements MinecraftPacket { this.previousGamemode = previousGamemode; } + public boolean getIsHardcore() { + return isHardcore; + } + + public void setIsHardcore(boolean isHardcore) { + this.isHardcore = isHardcore; + } + @Override public String toString() { return "JoinGame{" @@ -126,6 +135,7 @@ public class JoinGame implements MinecraftPacket { + ", dimension=" + dimension + ", partialHashedSeed=" + partialHashedSeed + ", difficulty=" + difficulty + + ", isHardcore=" + isHardcore + ", maxPlayers=" + maxPlayers + ", levelType='" + levelType + '\'' + ", viewDistance=" + viewDistance @@ -139,7 +149,14 @@ public class JoinGame implements MinecraftPacket { @Override public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { this.entityId = buf.readInt(); - this.gamemode = buf.readByte(); + if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { + this.isHardcore = buf.readBoolean(); + this.gamemode = buf.readByte(); + } else { + this.gamemode = buf.readByte(); + this.isHardcore = (this.gamemode & 0x08) != 0; + this.gamemode &= ~0x08; + } String dimensionIdentifier = null; String levelName = null; if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { @@ -160,7 +177,11 @@ public class JoinGame implements MinecraftPacket { if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) { this.partialHashedSeed = buf.readLong(); } - this.maxPlayers = buf.readUnsignedByte(); + if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { + this.maxPlayers = ProtocolUtils.readVarInt(buf); + } else { + this.maxPlayers = buf.readUnsignedByte(); + } if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) < 0) { this.levelType = ProtocolUtils.readString(buf, 16); } @@ -181,7 +202,12 @@ public class JoinGame implements MinecraftPacket { @Override public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { buf.writeInt(entityId); - buf.writeByte(gamemode); + if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { + buf.writeBoolean(isHardcore); + buf.writeByte(gamemode); + } else { + buf.writeByte(isHardcore ? gamemode | 0x8 : gamemode); + } if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { buf.writeByte(previousGamemode); ProtocolUtils.writeStringArray(buf, dimensionRegistry.getLevelNames().toArray( @@ -200,7 +226,11 @@ public class JoinGame implements MinecraftPacket { if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) { buf.writeLong(partialHashedSeed); } - buf.writeByte(maxPlayers); + if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { + ProtocolUtils.writeVarInt(buf, maxPlayers); + } else { + buf.writeByte(maxPlayers); + } if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) < 0) { if (levelType == null) { throw new IllegalStateException("No level type specified."); From c8aeac455bb46185e212ba75c1dd0b53127e0b38 Mon Sep 17 00:00:00 2001 From: "Five (Xer)" Date: Sun, 12 Jul 2020 14:36:28 +0200 Subject: [PATCH 2/3] Changes 20w28a --- .../api/network/ProtocolVersion.java | 2 +- .../registry/DimensionRegistry.java | 15 +++----- .../proxy/protocol/StateRegistry.java | 27 +++++++++----- .../proxy/protocol/packet/JoinGame.java | 37 ++++++++++++++++++- 4 files changed, 59 insertions(+), 22 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 cfc11b608..d65771644 100644 --- a/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java +++ b/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java @@ -37,7 +37,7 @@ public enum ProtocolVersion { MINECRAFT_1_15_2(578, "1.15.2"), MINECRAFT_1_16(735, "1.16"), MINECRAFT_1_16_1(736, "1.16.1"), - MINECRAFT_1_16_2(738, "1.16.2"); + MINECRAFT_1_16_2(740, "1.16.2"); private final int protocol; private final String name; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionRegistry.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionRegistry.java index 22bf61977..6fdf4d88d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionRegistry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionRegistry.java @@ -79,27 +79,22 @@ public final class DimensionRegistry { * Encodes the stored Dimension registry as CompoundTag. * @return the CompoundTag containing identifier:type mappings */ - public CompoundTag encodeRegistry() { - CompoundTag ret = new CompoundTag(); + public ListTag encodeRegistry() { ListTag list = new ListTag(TagType.COMPOUND); for (DimensionData iter : registeredDimensions.values()) { list.add(iter.encodeAsCompundTag()); } - ret.put("dimension", list); - return ret; + return list; } /** * Decodes a CompoundTag storing a dimension registry. * @param toParse CompoundTag containing a dimension registry */ - public static ImmutableSet fromGameData(CompoundTag toParse) { - Preconditions.checkNotNull(toParse, "CompoundTag cannot be null"); - Preconditions.checkArgument(toParse.contains("dimension", TagType.LIST), - "CompoundTag does not contain a dimension list"); - ListTag dimensions = toParse.getList("dimension"); + public static ImmutableSet fromGameData(ListTag toParse) { + Preconditions.checkNotNull(toParse, "ListTag cannot be null"); ImmutableSet.Builder mappings = ImmutableSet.builder(); - for (Tag iter : dimensions) { + for (Tag iter : toParse) { if (iter instanceof CompoundTag) { mappings.add(DimensionData.decodeCompoundTag((CompoundTag) iter)); } 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 2b89b575c..f2a969dbf 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java @@ -141,39 +141,45 @@ public enum StateRegistry { map(0x0E, MINECRAFT_1_9, false), map(0x10, MINECRAFT_1_13, false), map(0x11, MINECRAFT_1_15, false), - map(0x10, MINECRAFT_1_16, false)); + map(0x10, MINECRAFT_1_16, false), + map(0x0F, MINECRAFT_1_16_2, false)); clientbound.register(AvailableCommands.class, AvailableCommands::new, map(0x11, MINECRAFT_1_13, false), map(0x12, MINECRAFT_1_15, false), - map(0x11, MINECRAFT_1_16, false)); + map(0x11, MINECRAFT_1_16, false), + map(0x10, MINECRAFT_1_16_2, false)); clientbound.register(PluginMessage.class, PluginMessage::new, map(0x3F, MINECRAFT_1_8, false), map(0x18, MINECRAFT_1_9, false), map(0x19, MINECRAFT_1_13, false), map(0x18, MINECRAFT_1_14, false), map(0x19, MINECRAFT_1_15, false), - map(0x18, MINECRAFT_1_16, false)); + map(0x18, MINECRAFT_1_16, false), + map(0x17, MINECRAFT_1_16_2, false)); clientbound.register(Disconnect.class, Disconnect::new, map(0x40, MINECRAFT_1_8, false), map(0x1A, MINECRAFT_1_9, false), map(0x1B, MINECRAFT_1_13, false), map(0x1A, MINECRAFT_1_14, false), map(0x1B, MINECRAFT_1_15, false), - map(0x1A, MINECRAFT_1_16, false)); + map(0x1A, MINECRAFT_1_16, false), + map(0x19, MINECRAFT_1_16_2, false)); clientbound.register(KeepAlive.class, KeepAlive::new, map(0x00, MINECRAFT_1_8, false), map(0x1F, MINECRAFT_1_9, false), map(0x21, MINECRAFT_1_13, false), map(0x20, MINECRAFT_1_14, false), map(0x21, MINECRAFT_1_15, false), - map(0x20, MINECRAFT_1_16, false)); + map(0x20, MINECRAFT_1_16, false), + map(0x1F, MINECRAFT_1_16_2, false)); clientbound.register(JoinGame.class, JoinGame::new, map(0x01, MINECRAFT_1_8, false), map(0x23, MINECRAFT_1_9, false), map(0x25, MINECRAFT_1_13, false), map(0x25, MINECRAFT_1_14, false), map(0x26, MINECRAFT_1_15, false), - map(0x25, MINECRAFT_1_16, false)); + map(0x25, MINECRAFT_1_16, false), + map(0x24, MINECRAFT_1_16_2, false)); clientbound.register(Respawn.class, Respawn::new, map(0x07, MINECRAFT_1_8, true), map(0x33, MINECRAFT_1_9, true), @@ -182,7 +188,8 @@ public enum StateRegistry { map(0x38, MINECRAFT_1_13, true), map(0x3A, MINECRAFT_1_14, true), map(0x3B, MINECRAFT_1_15, true), - map(0x3A, MINECRAFT_1_16, true)); + map(0x3A, MINECRAFT_1_16, true), + map(0x39, MINECRAFT_1_16_2, true)); clientbound.register(ResourcePackRequest.class, ResourcePackRequest::new, map(0x48, MINECRAFT_1_8, true), map(0x32, MINECRAFT_1_9, true), @@ -191,7 +198,8 @@ public enum StateRegistry { map(0x37, MINECRAFT_1_13, true), map(0x39, MINECRAFT_1_14, true), map(0x3A, MINECRAFT_1_15, true), - map(0x39, MINECRAFT_1_16, true)); + map(0x39, MINECRAFT_1_16, true), + map(0x38, MINECRAFT_1_16_2, true)); clientbound.register(HeaderAndFooter.class, HeaderAndFooter::new, map(0x47, MINECRAFT_1_8, true), map(0x48, MINECRAFT_1_9, true), @@ -218,7 +226,8 @@ public enum StateRegistry { map(0x30, MINECRAFT_1_13, false), map(0x33, MINECRAFT_1_14, false), map(0x34, MINECRAFT_1_15, false), - map(0x33, MINECRAFT_1_16, false)); + map(0x33, MINECRAFT_1_16, false), + map(0x32, MINECRAFT_1_16_2, false)); } }, LOGIN { 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 3dd55a265..468d2f4e8 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 @@ -8,6 +8,9 @@ import com.velocitypowered.proxy.connection.registry.DimensionInfo; import com.velocitypowered.proxy.connection.registry.DimensionRegistry; import com.velocitypowered.proxy.protocol.*; import io.netty.buffer.ByteBuf; +import net.kyori.nbt.CompoundTag; +import net.kyori.nbt.ListTag; +import net.kyori.nbt.TagType; import org.checkerframework.checker.nullness.qual.Nullable; public class JoinGame implements MinecraftPacket { @@ -26,6 +29,7 @@ public class JoinGame implements MinecraftPacket { private DimensionRegistry dimensionRegistry; // 1.16+ private DimensionInfo dimensionInfo; // 1.16+ private short previousGamemode; // 1.16+ + private CompoundTag biomeRegistry; // 1.16.2+ public int getEntityId() { return entityId; @@ -127,6 +131,14 @@ public class JoinGame implements MinecraftPacket { this.isHardcore = isHardcore; } + public CompoundTag getBiomeRegistry() { + return biomeRegistry; + } + + public void setBiomeRegistry(CompoundTag biomeRegistry) { + this.biomeRegistry = biomeRegistry; + } + @Override public String toString() { return "JoinGame{" @@ -162,7 +174,17 @@ public class JoinGame implements MinecraftPacket { if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { this.previousGamemode = buf.readByte(); ImmutableSet levelNames = ImmutableSet.copyOf(ProtocolUtils.readStringArray(buf)); - ImmutableSet readData = DimensionRegistry.fromGameData(ProtocolUtils.readCompoundTag(buf)); + CompoundTag registryContainer = ProtocolUtils.readCompoundTag(buf); + ListTag dimensionRegistryContainer = null; + if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { + dimensionRegistryContainer = registryContainer.getCompound("minecraft:dimension_type") + .getList("value", TagType.COMPOUND); + this.biomeRegistry = registryContainer.getCompound("minecraft:worldgen/biome"); + } else { + dimensionRegistryContainer = registryContainer.getList("dimension", TagType.COMPOUND); + } + ImmutableSet readData = + DimensionRegistry.fromGameData(dimensionRegistryContainer); this.dimensionRegistry = new DimensionRegistry(readData, levelNames); dimensionIdentifier = ProtocolUtils.readString(buf); levelName = ProtocolUtils.readString(buf); @@ -212,7 +234,18 @@ public class JoinGame implements MinecraftPacket { buf.writeByte(previousGamemode); ProtocolUtils.writeStringArray(buf, dimensionRegistry.getLevelNames().toArray( new String[dimensionRegistry.getLevelNames().size()])); - ProtocolUtils.writeCompoundTag(buf, dimensionRegistry.encodeRegistry()); + CompoundTag registryContainer = new CompoundTag(); + ListTag encodedDimensionRegistry = dimensionRegistry.encodeRegistry(); + if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { + CompoundTag dimensionRegistryDummy = new CompoundTag(); + dimensionRegistryDummy.putString("type", "minecraft:dimension_type"); + dimensionRegistryDummy.put("value", encodedDimensionRegistry); + registryContainer.put("minecraft:dimension_type", dimensionRegistryDummy); + registryContainer.put("minecraft:worldgen/biome", biomeRegistry); + } else { + registryContainer.put("dimension", encodedDimensionRegistry); + } + ProtocolUtils.writeCompoundTag(buf, registryContainer); ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier()); ProtocolUtils.writeString(buf, dimensionInfo.getLevelName()); } else if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) { From 608fcf416379c8b977f4fb7e9f49a142bab7e8dd Mon Sep 17 00:00:00 2001 From: "Five (Xer)" Date: Wed, 15 Jul 2020 18:02:13 +0200 Subject: [PATCH 3/3] Changes 20w29a --- .../java/com/velocitypowered/api/network/ProtocolVersion.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d65771644..6d694ebd1 100644 --- a/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java +++ b/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java @@ -37,7 +37,7 @@ public enum ProtocolVersion { MINECRAFT_1_15_2(578, "1.15.2"), MINECRAFT_1_16(735, "1.16"), MINECRAFT_1_16_1(736, "1.16.1"), - MINECRAFT_1_16_2(740, "1.16.2"); + MINECRAFT_1_16_2(741, "1.16.2"); private final int protocol; private final String name;