From 4ba8996fedba6f7a2dc96bb11d879a335361c046 Mon Sep 17 00:00:00 2001 From: Lechner Markus Date: Wed, 1 Jul 2020 22:01:33 +0200 Subject: [PATCH 01/13] 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 02/13] 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 03/13] 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; From f205ac19bec2df6e837de1c64b191710a3eaeaa8 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Wed, 5 Aug 2020 11:18:52 -0400 Subject: [PATCH 04/13] Update for 1.16.2-pre1 --- .../api/network/ProtocolVersion.java | 2 +- .../connection/registry/DimensionData.java | 97 +++++++++++++------ .../registry/DimensionRegistry.java | 9 +- .../proxy/protocol/packet/JoinGame.java | 4 +- .../brigadier/ArgumentPropertyRegistry.java | 1 + 5 files changed, 76 insertions(+), 37 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 6d694ebd1..a1d8fd1fc 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(741, "1.16.2"); + MINECRAFT_1_16_2(744, "1.16.2"); private final int protocol; private final String name; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java index b5c7193c4..7dfbfec0e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java @@ -1,11 +1,13 @@ package com.velocitypowered.proxy.connection.registry; import com.google.common.base.Preconditions; +import com.velocitypowered.api.network.ProtocolVersion; import net.kyori.nbt.CompoundTag; import org.checkerframework.checker.nullness.qual.Nullable; public final class DimensionData { private final String registryIdentifier; + private final @Nullable Integer dimensionId; private final boolean isNatural; private final float ambientLight; private final boolean isShrunk; @@ -24,6 +26,7 @@ public final class DimensionData { /** * Initializes a new {@link DimensionData} instance. * @param registryIdentifier the identifier for the dimension from the registry. + * @param dimensionId the dimension ID contained in the registry (the "id" tag) * @param isNatural indicates if the dimension use natural world generation (e.g. overworld) * @param ambientLight the light level the client sees without external lighting * @param isShrunk indicates if the world is shrunk, aka not the full 256 blocks (e.g. nether) @@ -39,13 +42,15 @@ public final class DimensionData { * @param fixedTime optional. If set to any game daytime value will deactivate time cycle * @param createDragonFight optional. Internal flag used in the end dimension */ - public DimensionData(String registryIdentifier, boolean isNatural, - float ambientLight, boolean isShrunk, boolean isUltrawarm, - boolean hasCeiling, boolean hasSkylight, - boolean isPiglinSafe, boolean doBedsWork, - boolean doRespawnAnchorsWork, boolean hasRaids, - int logicalHeight, String burningBehaviourIdentifier, - @Nullable Long fixedTime, @Nullable Boolean createDragonFight) { + public DimensionData(String registryIdentifier, + @Nullable Integer dimensionId, + boolean isNatural, + float ambientLight, boolean isShrunk, boolean isUltrawarm, + boolean hasCeiling, boolean hasSkylight, + boolean isPiglinSafe, boolean doBedsWork, + boolean doRespawnAnchorsWork, boolean hasRaids, + int logicalHeight, String burningBehaviourIdentifier, + @Nullable Long fixedTime, @Nullable Boolean createDragonFight) { Preconditions.checkNotNull( registryIdentifier, "registryIdentifier cannot be null"); Preconditions.checkArgument(registryIdentifier.length() > 0, @@ -56,6 +61,7 @@ public final class DimensionData { Preconditions.checkArgument(burningBehaviourIdentifier.length() > 0, "burningBehaviourIdentifier cannot be empty"); this.registryIdentifier = registryIdentifier; + this.dimensionId = dimensionId; this.isNatural = isNatural; this.ambientLight = ambientLight; this.isShrunk = isShrunk; @@ -76,6 +82,10 @@ public final class DimensionData { return registryIdentifier; } + public Integer getDimensionId() { + return dimensionId; + } + public boolean isNatural() { return isNatural; } @@ -134,41 +144,68 @@ public final class DimensionData { /** * Parses a given CompoundTag to a DimensionData instance. - * @param toRead the compound from the registry to read + * @param dimTag the compound from the registry to read + * @param version the protocol version from the registry * @return game dimension data */ - public static DimensionData decodeCompoundTag(CompoundTag toRead) { - Preconditions.checkNotNull(toRead, "CompoundTag cannot be null"); - String registryIdentifier = toRead.getString("name"); - boolean isNatural = toRead.getBoolean("natural"); - float ambientLight = toRead.getFloat("ambient_light"); - boolean isShrunk = toRead.getBoolean("shrunk"); - boolean isUltrawarm = toRead.getBoolean("ultrawarm"); - boolean hasCeiling = toRead.getBoolean("has_ceiling"); - boolean hasSkylight = toRead.getBoolean("has_skylight"); - boolean isPiglinSafe = toRead.getBoolean("piglin_safe"); - boolean doBedsWork = toRead.getBoolean("bed_works"); - boolean doRespawnAnchorsWork = toRead.getBoolean("respawn_anchor_works"); - boolean hasRaids = toRead.getBoolean("has_raids"); - int logicalHeight = toRead.getInt("logical_height"); - String burningBehaviourIdentifier = toRead.getString("infiniburn"); - Long fixedTime = toRead.contains("fixed_time") - ? toRead.getLong("fixed_time") : null; - Boolean hasEnderdragonFight = toRead.contains("has_enderdragon_fight") - ? toRead.getBoolean("has_enderdragon_fight") : null; + public static DimensionData decodeCompoundTag(CompoundTag dimTag, ProtocolVersion version) { + Preconditions.checkNotNull(dimTag, "CompoundTag cannot be null"); + String registryIdentifier = dimTag.getString("name"); + CompoundTag details; + Integer dimensionId = null; + if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { + dimensionId = dimTag.getInt("id"); + details = dimTag.getCompound("element"); + } else { + details = dimTag; + } + boolean isNatural = details.getBoolean("natural"); + float ambientLight = details.getFloat("ambient_light"); + boolean isShrunk = details.getBoolean("shrunk"); + boolean isUltrawarm = details.getBoolean("ultrawarm"); + boolean hasCeiling = details.getBoolean("has_ceiling"); + boolean hasSkylight = details.getBoolean("has_skylight"); + boolean isPiglinSafe = details.getBoolean("piglin_safe"); + boolean doBedsWork = details.getBoolean("bed_works"); + boolean doRespawnAnchorsWork = details.getBoolean("respawn_anchor_works"); + boolean hasRaids = details.getBoolean("has_raids"); + int logicalHeight = details.getInt("logical_height"); + String burningBehaviourIdentifier = details.getString("infiniburn"); + Long fixedTime = details.contains("fixed_time") + ? details.getLong("fixed_time") : null; + Boolean hasEnderdragonFight = details.contains("has_enderdragon_fight") + ? details.getBoolean("has_enderdragon_fight") : null; return new DimensionData( - registryIdentifier, isNatural, ambientLight, isShrunk, + registryIdentifier, dimensionId, isNatural, ambientLight, isShrunk, isUltrawarm, hasCeiling, hasSkylight, isPiglinSafe, doBedsWork, doRespawnAnchorsWork, hasRaids, logicalHeight, burningBehaviourIdentifier, fixedTime, hasEnderdragonFight); } /** * Encodes the Dimension data as CompoundTag. + * @param version the version to serialize as * @return compound containing the dimension data */ - public CompoundTag encodeAsCompundTag() { + public CompoundTag encodeAsCompoundTag(ProtocolVersion version) { + CompoundTag details = serializeDimensionDetails(); + if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { + CompoundTag parent = new CompoundTag(); + parent.putString("name", registryIdentifier); + if (dimensionId == null) { + throw new IllegalStateException("Tried to serialize a 1.16.2+ dimension registry entry " + + "without an ID"); + } + parent.putInt("id", dimensionId); + parent.put("element", details); + return parent; + } else { + details.putString("name", registryIdentifier); + return details; + } + } + + private CompoundTag serializeDimensionDetails() { CompoundTag ret = new CompoundTag(); - ret.putString("name", registryIdentifier); ret.putBoolean("natural", isNatural); ret.putFloat("ambient_light", ambientLight); ret.putBoolean("shrunk", isShrunk); 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 6fdf4d88d..233d17ec7 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 @@ -4,6 +4,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; +import com.velocitypowered.api.network.ProtocolVersion; import java.util.Map; import java.util.Set; @@ -79,10 +80,10 @@ public final class DimensionRegistry { * Encodes the stored Dimension registry as CompoundTag. * @return the CompoundTag containing identifier:type mappings */ - public ListTag encodeRegistry() { + public ListTag encodeRegistry(ProtocolVersion version) { ListTag list = new ListTag(TagType.COMPOUND); for (DimensionData iter : registeredDimensions.values()) { - list.add(iter.encodeAsCompundTag()); + list.add(iter.encodeAsCompoundTag(version)); } return list; } @@ -91,12 +92,12 @@ public final class DimensionRegistry { * Decodes a CompoundTag storing a dimension registry. * @param toParse CompoundTag containing a dimension registry */ - public static ImmutableSet fromGameData(ListTag toParse) { + public static ImmutableSet fromGameData(ListTag toParse, ProtocolVersion version) { Preconditions.checkNotNull(toParse, "ListTag cannot be null"); ImmutableSet.Builder mappings = ImmutableSet.builder(); for (Tag iter : toParse) { if (iter instanceof CompoundTag) { - mappings.add(DimensionData.decodeCompoundTag((CompoundTag) iter)); + mappings.add(DimensionData.decodeCompoundTag((CompoundTag) iter, version)); } } return mappings.build(); 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 468d2f4e8..cc40434e2 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 @@ -184,7 +184,7 @@ public class JoinGame implements MinecraftPacket { dimensionRegistryContainer = registryContainer.getList("dimension", TagType.COMPOUND); } ImmutableSet readData = - DimensionRegistry.fromGameData(dimensionRegistryContainer); + DimensionRegistry.fromGameData(dimensionRegistryContainer, version); this.dimensionRegistry = new DimensionRegistry(readData, levelNames); dimensionIdentifier = ProtocolUtils.readString(buf); levelName = ProtocolUtils.readString(buf); @@ -235,7 +235,7 @@ public class JoinGame implements MinecraftPacket { ProtocolUtils.writeStringArray(buf, dimensionRegistry.getLevelNames().toArray( new String[dimensionRegistry.getLevelNames().size()])); CompoundTag registryContainer = new CompoundTag(); - ListTag encodedDimensionRegistry = dimensionRegistry.encodeRegistry(); + ListTag encodedDimensionRegistry = dimensionRegistry.encodeRegistry(version); if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { CompoundTag dimensionRegistryDummy = new CompoundTag(); dimensionRegistryDummy.putString("type", "minecraft:dimension_type"); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/ArgumentPropertyRegistry.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/ArgumentPropertyRegistry.java index 7c9b8fb9c..4baa0a3cd 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/ArgumentPropertyRegistry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/ArgumentPropertyRegistry.java @@ -135,5 +135,6 @@ public class ArgumentPropertyRegistry { dummy("minecraft:float_range", DUMMY); dummy("minecraft:time", DUMMY); // added in 1.14 dummy("minecraft:uuid", DUMMY); // added in 1.16 + dummy("minecraft:angle", DUMMY); // added in 1.16.2 } } From db83ade45ef6dcd2d54ec73309f247eeeb8b64e4 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Wed, 5 Aug 2020 11:21:43 -0400 Subject: [PATCH 05/13] This is nullable --- .../proxy/connection/registry/DimensionData.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java index 7dfbfec0e..b7e149930 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java @@ -82,7 +82,7 @@ public final class DimensionData { return registryIdentifier; } - public Integer getDimensionId() { + public @Nullable Integer getDimensionId() { return dimensionId; } From 32e90a1969e0cf1d3a4c4130fc2e8536eb00c63e Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Wed, 5 Aug 2020 15:34:27 -0400 Subject: [PATCH 06/13] 1.16.2-pre2 --- .../api/network/ProtocolVersion.java | 2 +- .../connection/registry/DimensionData.java | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 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 a1d8fd1fc..0cf18ccb9 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(744, "1.16.2"); + MINECRAFT_1_16_2(746, "1.16.2"); private final int protocol; private final String name; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java index b7e149930..23061c477 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java @@ -22,6 +22,7 @@ public final class DimensionData { private final String burningBehaviourIdentifier; private final @Nullable Long fixedTime; private final @Nullable Boolean createDragonFight; + private final @Nullable Double coordinateScale; /** * Initializes a new {@link DimensionData} instance. @@ -41,6 +42,7 @@ public final class DimensionData { * @param burningBehaviourIdentifier the identifier for how burning blocks work in the dimension * @param fixedTime optional. If set to any game daytime value will deactivate time cycle * @param createDragonFight optional. Internal flag used in the end dimension + * @param coordinateScale optional, unknown purpose */ public DimensionData(String registryIdentifier, @Nullable Integer dimensionId, @@ -50,7 +52,8 @@ public final class DimensionData { boolean isPiglinSafe, boolean doBedsWork, boolean doRespawnAnchorsWork, boolean hasRaids, int logicalHeight, String burningBehaviourIdentifier, - @Nullable Long fixedTime, @Nullable Boolean createDragonFight) { + @Nullable Long fixedTime, @Nullable Boolean createDragonFight, + @Nullable Double coordinateScale) { Preconditions.checkNotNull( registryIdentifier, "registryIdentifier cannot be null"); Preconditions.checkArgument(registryIdentifier.length() > 0, @@ -76,6 +79,7 @@ public final class DimensionData { this.burningBehaviourIdentifier = burningBehaviourIdentifier; this.fixedTime = fixedTime; this.createDragonFight = createDragonFight; + this.coordinateScale = coordinateScale; } public String getRegistryIdentifier() { @@ -142,6 +146,10 @@ public final class DimensionData { return createDragonFight; } + public @Nullable Double getCoordinateScale() { + return coordinateScale; + } + /** * Parses a given CompoundTag to a DimensionData instance. * @param dimTag the compound from the registry to read @@ -175,10 +183,13 @@ public final class DimensionData { ? details.getLong("fixed_time") : null; Boolean hasEnderdragonFight = details.contains("has_enderdragon_fight") ? details.getBoolean("has_enderdragon_fight") : null; + Double coordinateScale = details.contains("coordinate_scale") + ? details.getDouble("coordinate_scale") : null; return new DimensionData( registryIdentifier, dimensionId, isNatural, ambientLight, isShrunk, isUltrawarm, hasCeiling, hasSkylight, isPiglinSafe, doBedsWork, doRespawnAnchorsWork, - hasRaids, logicalHeight, burningBehaviourIdentifier, fixedTime, hasEnderdragonFight); + hasRaids, logicalHeight, burningBehaviourIdentifier, fixedTime, hasEnderdragonFight, + coordinateScale); } /** @@ -224,6 +235,9 @@ public final class DimensionData { if (createDragonFight != null) { ret.putBoolean("has_enderdragon_fight", createDragonFight); } + if (coordinateScale != null) { + ret.putDouble("coordinate_scale", coordinateScale); + } return ret; } } From a081c35fdbb5836636ffd55646c36c0734f5699f Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 6 Aug 2020 15:00:15 -0400 Subject: [PATCH 07/13] 1.16.2-pre3 --- .../api/network/ProtocolVersion.java | 2 +- .../client/ClientPlaySessionHandler.java | 9 ++- .../connection/registry/DimensionData.java | 78 ++++++++++++++----- .../connection/registry/DimensionInfo.java | 16 ++-- .../registry/DimensionRegistry.java | 2 +- .../proxy/protocol/packet/JoinGame.java | 25 +++++- .../proxy/protocol/packet/Respawn.java | 31 ++++++-- 7 files changed, 115 insertions(+), 48 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 0cf18ccb9..f2944250e 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(746, "1.16.2"); + MINECRAFT_1_16_2(748, "1.16.2"); private final int protocol; private final String name; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java index f583d76a5..cbcb95366 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java @@ -341,15 +341,16 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { int tempDim = joinGame.getDimension() == 0 ? -1 : 0; player.getMinecraftConnection().delayedWrite( new Respawn(tempDim, joinGame.getPartialHashedSeed(), joinGame.getDifficulty(), - joinGame.getGamemode(), joinGame.getLevelType(), - false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode())); + joinGame.getGamemode(), joinGame.getLevelType(), + false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode(), + joinGame.getCurrentDimensionData())); } player.getMinecraftConnection().delayedWrite( new Respawn(joinGame.getDimension(), joinGame.getPartialHashedSeed(), joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(), - false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode())); - + false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode(), + joinGame.getCurrentDimensionData())); destination.setActiveDimensionRegistry(joinGame.getDimensionRegistry()); // 1.16 } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java index 23061c477..55880e9c5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java @@ -6,6 +6,8 @@ import net.kyori.nbt.CompoundTag; import org.checkerframework.checker.nullness.qual.Nullable; public final class DimensionData { + private static final String UNKNOWN_DIMENSION_ID = "velocity:unknown_dimension"; + private final String registryIdentifier; private final @Nullable Integer dimensionId; private final boolean isNatural; @@ -151,22 +153,34 @@ public final class DimensionData { } /** - * Parses a given CompoundTag to a DimensionData instance. - * @param dimTag the compound from the registry to read - * @param version the protocol version from the registry + * Returns a fresh {@link DimensionData} with the specified {@code registryIdentifier} + * and {@code dimensionId}. + * + * @param registryIdentifier the identifier for the dimension from the registry + * @param dimensionId optional, dimension ID + * @return a new {@link DimensionData} + */ + public DimensionData annotateWith(String registryIdentifier, + @Nullable Integer dimensionId) { + return new DimensionData(registryIdentifier, dimensionId, isNatural, ambientLight, isShrunk, + isUltrawarm, hasCeiling, hasSkylight, isPiglinSafe, doBedsWork, doRespawnAnchorsWork, + hasRaids, logicalHeight, burningBehaviourIdentifier, fixedTime, createDragonFight, + coordinateScale); + } + + public boolean isUnannotated() { + return this.registryIdentifier.equalsIgnoreCase(UNKNOWN_DIMENSION_ID); + } + + /** + * Parses a given CompoundTag to a DimensionData instance. Assumes the data only contains + * dimension details. + * + * @param details the compound from the registry to read + * @param version the protocol version * @return game dimension data */ - public static DimensionData decodeCompoundTag(CompoundTag dimTag, ProtocolVersion version) { - Preconditions.checkNotNull(dimTag, "CompoundTag cannot be null"); - String registryIdentifier = dimTag.getString("name"); - CompoundTag details; - Integer dimensionId = null; - if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { - dimensionId = dimTag.getInt("id"); - details = dimTag.getCompound("element"); - } else { - details = dimTag; - } + public static DimensionData decodeBaseCompoundTag(CompoundTag details, ProtocolVersion version) { boolean isNatural = details.getBoolean("natural"); float ambientLight = details.getFloat("ambient_light"); boolean isShrunk = details.getBoolean("shrunk"); @@ -180,16 +194,38 @@ public final class DimensionData { int logicalHeight = details.getInt("logical_height"); String burningBehaviourIdentifier = details.getString("infiniburn"); Long fixedTime = details.contains("fixed_time") - ? details.getLong("fixed_time") : null; + ? details.getLong("fixed_time") : null; Boolean hasEnderdragonFight = details.contains("has_enderdragon_fight") - ? details.getBoolean("has_enderdragon_fight") : null; + ? details.getBoolean("has_enderdragon_fight") : null; Double coordinateScale = details.contains("coordinate_scale") ? details.getDouble("coordinate_scale") : null; return new DimensionData( - registryIdentifier, dimensionId, isNatural, ambientLight, isShrunk, - isUltrawarm, hasCeiling, hasSkylight, isPiglinSafe, doBedsWork, doRespawnAnchorsWork, - hasRaids, logicalHeight, burningBehaviourIdentifier, fixedTime, hasEnderdragonFight, - coordinateScale); + UNKNOWN_DIMENSION_ID, null, isNatural, ambientLight, isShrunk, + isUltrawarm, hasCeiling, hasSkylight, isPiglinSafe, doBedsWork, doRespawnAnchorsWork, + hasRaids, logicalHeight, burningBehaviourIdentifier, fixedTime, hasEnderdragonFight, + coordinateScale); + } + + /** + * Parses a given CompoundTag to a DimensionData instance. Assumes the data is part of a + * dimension registry. + * @param dimTag the compound from the registry to read + * @param version the protocol version + * @return game dimension data + */ + public static DimensionData decodeRegistryEntry(CompoundTag dimTag, ProtocolVersion version) { + String registryIdentifier = dimTag.getString("name"); + CompoundTag details; + Integer dimensionId = null; + if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { + dimensionId = dimTag.getInt("id"); + details = dimTag.getCompound("element"); + } else { + details = dimTag; + } + + DimensionData deserializedDetails = decodeBaseCompoundTag(details, version); + return deserializedDetails.annotateWith(registryIdentifier, dimensionId); } /** @@ -215,7 +251,7 @@ public final class DimensionData { } } - private CompoundTag serializeDimensionDetails() { + public CompoundTag serializeDimensionDetails() { CompoundTag ret = new CompoundTag(); ret.putBoolean("natural", isNatural); ret.putFloat("ambient_light", ambientLight); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionInfo.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionInfo.java index ac5670194..5b7cba13f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionInfo.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionInfo.java @@ -1,6 +1,7 @@ package com.velocitypowered.proxy.connection.registry; import com.google.common.base.Preconditions; +import org.checkerframework.checker.nullness.qual.Nullable; public final class DimensionInfo { @@ -16,18 +17,13 @@ public final class DimensionInfo { * @param isFlat if true will set world lighting below surface-level to not display fog * @param isDebugType if true constrains the world to the very limited debug-type world */ - public DimensionInfo(String registryIdentifier, String levelName, + public DimensionInfo(String registryIdentifier, @Nullable String levelName, boolean isFlat, boolean isDebugType) { this.registryIdentifier = Preconditions.checkNotNull( - registryIdentifier, "registryIdentifier cannot be null"); - Preconditions.checkArgument( - registryIdentifier.length() > 0, - "registryIdentifier cannot be empty"); - this.levelName = Preconditions.checkNotNull( - levelName, "levelName cannot be null"); - Preconditions.checkArgument( - levelName.length() > 0, + registryIdentifier, "registryIdentifier cannot be null"); + Preconditions.checkArgument(registryIdentifier.length() > 0, "registryIdentifier cannot be empty"); + this.levelName = levelName; this.isFlat = isFlat; this.isDebugType = isDebugType; } @@ -40,7 +36,7 @@ public final class DimensionInfo { return isFlat; } - public String getLevelName() { + public @Nullable String getLevelName() { return levelName; } 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 233d17ec7..f517e83a8 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 @@ -97,7 +97,7 @@ public final class DimensionRegistry { ImmutableSet.Builder mappings = ImmutableSet.builder(); for (Tag iter : toParse) { if (iter instanceof CompoundTag) { - mappings.add(DimensionData.decodeCompoundTag((CompoundTag) iter, version)); + mappings.add(DimensionData.decodeRegistryEntry((CompoundTag) iter, version)); } } return mappings.build(); 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 cc40434e2..009dd570a 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 @@ -28,6 +28,7 @@ public class JoinGame implements MinecraftPacket { private boolean showRespawnScreen; private DimensionRegistry dimensionRegistry; // 1.16+ private DimensionInfo dimensionInfo; // 1.16+ + private DimensionData currentDimensionData; // 1.16.2+ private short previousGamemode; // 1.16+ private CompoundTag biomeRegistry; // 1.16.2+ @@ -139,6 +140,10 @@ public class JoinGame implements MinecraftPacket { this.biomeRegistry = biomeRegistry; } + public DimensionData getCurrentDimensionData() { + return currentDimensionData; + } + @Override public String toString() { return "JoinGame{" @@ -186,8 +191,15 @@ public class JoinGame implements MinecraftPacket { ImmutableSet readData = DimensionRegistry.fromGameData(dimensionRegistryContainer, version); this.dimensionRegistry = new DimensionRegistry(readData, levelNames); - dimensionIdentifier = ProtocolUtils.readString(buf); - levelName = ProtocolUtils.readString(buf); + if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { + CompoundTag currentDimDataTag = ProtocolUtils.readCompoundTag(buf); + dimensionIdentifier = ProtocolUtils.readString(buf); + this.currentDimensionData = DimensionData.decodeBaseCompoundTag(currentDimDataTag, version) + .annotateWith(dimensionIdentifier, null); + } else { + dimensionIdentifier = ProtocolUtils.readString(buf); + levelName = ProtocolUtils.readString(buf); + } } else if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) { this.dimension = buf.readInt(); } else { @@ -246,8 +258,13 @@ public class JoinGame implements MinecraftPacket { registryContainer.put("dimension", encodedDimensionRegistry); } ProtocolUtils.writeCompoundTag(buf, registryContainer); - ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier()); - ProtocolUtils.writeString(buf, dimensionInfo.getLevelName()); + if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { + ProtocolUtils.writeCompoundTag(buf, currentDimensionData.serializeDimensionDetails()); + ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier()); + } else { + ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier()); + ProtocolUtils.writeString(buf, dimensionInfo.getLevelName()); + } } else if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) { buf.writeInt(dimension); } else { 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 d14e9f8c8..aef9a7a19 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 @@ -2,10 +2,12 @@ package com.velocitypowered.proxy.protocol.packet; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; +import com.velocitypowered.proxy.connection.registry.DimensionData; import com.velocitypowered.proxy.connection.registry.DimensionInfo; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; +import net.kyori.nbt.CompoundTag; public class Respawn implements MinecraftPacket { @@ -15,15 +17,16 @@ public class Respawn implements MinecraftPacket { private short gamemode; private String levelType = ""; private boolean shouldKeepPlayerData; // 1.16+ - private DimensionInfo dimensionInfo; // 1.16+ + private DimensionInfo dimensionInfo; // 1.16-1.16.1 private short previousGamemode; // 1.16+ + private DimensionData currentDimensionData; // 1.16.2+ public Respawn() { } public Respawn(int dimension, long partialHashedSeed, short difficulty, short gamemode, String levelType, boolean shouldKeepPlayerData, DimensionInfo dimensionInfo, - short previousGamemode) { + short previousGamemode, DimensionData currentDimensionData) { this.dimension = dimension; this.partialHashedSeed = partialHashedSeed; this.difficulty = difficulty; @@ -32,6 +35,7 @@ public class Respawn implements MinecraftPacket { this.shouldKeepPlayerData = shouldKeepPlayerData; this.dimensionInfo = dimensionInfo; this.previousGamemode = previousGamemode; + this.currentDimensionData = currentDimensionData; } public int getDimension() { @@ -99,8 +103,9 @@ public class Respawn implements MinecraftPacket { + ", gamemode=" + gamemode + ", levelType='" + levelType + '\'' + ", shouldKeepPlayerData=" + shouldKeepPlayerData - + ", dimensionRegistryName='" + dimensionInfo.toString() + '\'' + + ", dimensionInfo=" + dimensionInfo + ", previousGamemode=" + previousGamemode + + ", dimensionData=" + currentDimensionData + '}'; } @@ -109,8 +114,15 @@ public class Respawn implements MinecraftPacket { String dimensionIdentifier = null; String levelName = null; if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { - dimensionIdentifier = ProtocolUtils.readString(buf); - levelName = ProtocolUtils.readString(buf); + if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { + CompoundTag dimDataTag = ProtocolUtils.readCompoundTag(buf); + dimensionIdentifier = ProtocolUtils.readString(buf); + this.currentDimensionData = DimensionData.decodeBaseCompoundTag(dimDataTag, version) + .annotateWith(dimensionIdentifier, null); + } else { + dimensionIdentifier = ProtocolUtils.readString(buf); + levelName = ProtocolUtils.readString(buf); + } } else { this.dimension = buf.readInt(); } @@ -135,8 +147,13 @@ public class Respawn implements MinecraftPacket { @Override public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { - ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier()); - ProtocolUtils.writeString(buf, dimensionInfo.getLevelName()); + if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { + ProtocolUtils.writeCompoundTag(buf, currentDimensionData.serializeDimensionDetails()); + ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier()); + } else { + ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier()); + ProtocolUtils.writeString(buf, dimensionInfo.getLevelName()); + } } else { buf.writeInt(dimension); } From c157b6c51bcccf9733d6055a34b836f9b515a934 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 6 Aug 2020 15:02:11 -0400 Subject: [PATCH 08/13] Fix checkstyle --- .../proxy/connection/registry/DimensionData.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java index 55880e9c5..9de8b51fc 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java @@ -251,6 +251,10 @@ public final class DimensionData { } } + /** + * Serializes details of this dimension. + * @return serialized details of this dimension + */ public CompoundTag serializeDimensionDetails() { CompoundTag ret = new CompoundTag(); ret.putBoolean("natural", isNatural); From 411ea637ce91e78d57a5cd820acd29e131ef21a9 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 6 Aug 2020 17:30:42 -0400 Subject: [PATCH 09/13] Switch to adventure-nbt for consistency with 1.1.0 --- proxy/build.gradle | 2 +- .../connection/registry/DimensionData.java | 80 ++++++++++--------- .../registry/DimensionRegistry.java | 27 ++++--- .../proxy/protocol/ProtocolUtils.java | 19 ++--- .../proxy/protocol/packet/JoinGame.java | 36 +++++---- .../proxy/protocol/packet/Respawn.java | 4 +- 6 files changed, 85 insertions(+), 83 deletions(-) diff --git a/proxy/build.gradle b/proxy/build.gradle index 91a434a11..ceda94504 100644 --- a/proxy/build.gradle +++ b/proxy/build.gradle @@ -63,7 +63,7 @@ dependencies { compile 'it.unimi.dsi:fastutil:8.2.2' compile 'net.kyori:event-method-asm:3.0.0' - compile 'net.kyori:nbt:1.12-1.0.0-SNAPSHOT' + compile 'net.kyori:adventure-nbt:4.0.0-SNAPSHOT' compile 'com.mojang:brigadier:1.0.17' diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java index 9de8b51fc..720c0bac2 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java @@ -2,7 +2,7 @@ package com.velocitypowered.proxy.connection.registry; import com.google.common.base.Preconditions; import com.velocitypowered.api.network.ProtocolVersion; -import net.kyori.nbt.CompoundTag; +import net.kyori.adventure.nbt.CompoundBinaryTag; import org.checkerframework.checker.nullness.qual.Nullable; public final class DimensionData { @@ -180,24 +180,25 @@ public final class DimensionData { * @param version the protocol version * @return game dimension data */ - public static DimensionData decodeBaseCompoundTag(CompoundTag details, ProtocolVersion version) { - boolean isNatural = details.getBoolean("natural"); + public static DimensionData decodeBaseCompoundTag(CompoundBinaryTag details, + ProtocolVersion version) { + boolean isNatural = details.getByte("natural") >= 1; float ambientLight = details.getFloat("ambient_light"); - boolean isShrunk = details.getBoolean("shrunk"); - boolean isUltrawarm = details.getBoolean("ultrawarm"); - boolean hasCeiling = details.getBoolean("has_ceiling"); - boolean hasSkylight = details.getBoolean("has_skylight"); - boolean isPiglinSafe = details.getBoolean("piglin_safe"); - boolean doBedsWork = details.getBoolean("bed_works"); - boolean doRespawnAnchorsWork = details.getBoolean("respawn_anchor_works"); - boolean hasRaids = details.getBoolean("has_raids"); + boolean isShrunk = details.getByte("shrunk") >= 1; + boolean isUltrawarm = details.getByte("ultrawarm") >= 1; + boolean hasCeiling = details.getByte("has_ceiling") >= 1; + boolean hasSkylight = details.getByte("has_skylight") >= 1; + boolean isPiglinSafe = details.getByte("piglin_safe") >= 1; + boolean doBedsWork = details.getByte("bed_works") >= 1; + boolean doRespawnAnchorsWork = details.getByte("respawn_anchor_works") >= 1; + boolean hasRaids = details.getByte("has_raids") >= 1; int logicalHeight = details.getInt("logical_height"); String burningBehaviourIdentifier = details.getString("infiniburn"); - Long fixedTime = details.contains("fixed_time") + Long fixedTime = details.keySet().contains("fixed_time") ? details.getLong("fixed_time") : null; - Boolean hasEnderdragonFight = details.contains("has_enderdragon_fight") - ? details.getBoolean("has_enderdragon_fight") : null; - Double coordinateScale = details.contains("coordinate_scale") + Boolean hasEnderdragonFight = details.keySet().contains("has_enderdragon_fight") + ? details.getByte("has_enderdragon_fight") >= 1 : null; + Double coordinateScale = details.keySet().contains("coordinate_scale") ? details.getDouble("coordinate_scale") : null; return new DimensionData( UNKNOWN_DIMENSION_ID, null, isNatural, ambientLight, isShrunk, @@ -213,9 +214,10 @@ public final class DimensionData { * @param version the protocol version * @return game dimension data */ - public static DimensionData decodeRegistryEntry(CompoundTag dimTag, ProtocolVersion version) { + public static DimensionData decodeRegistryEntry(CompoundBinaryTag dimTag, + ProtocolVersion version) { String registryIdentifier = dimTag.getString("name"); - CompoundTag details; + CompoundBinaryTag details; Integer dimensionId = null; if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { dimensionId = dimTag.getInt("id"); @@ -233,21 +235,21 @@ public final class DimensionData { * @param version the version to serialize as * @return compound containing the dimension data */ - public CompoundTag encodeAsCompoundTag(ProtocolVersion version) { - CompoundTag details = serializeDimensionDetails(); + public CompoundBinaryTag encodeAsCompoundTag(ProtocolVersion version) { + CompoundBinaryTag details = serializeDimensionDetails(); if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { - CompoundTag parent = new CompoundTag(); - parent.putString("name", registryIdentifier); if (dimensionId == null) { throw new IllegalStateException("Tried to serialize a 1.16.2+ dimension registry entry " + "without an ID"); } - parent.putInt("id", dimensionId); - parent.put("element", details); - return parent; + + return CompoundBinaryTag.builder() + .putString("name", registryIdentifier) + .putInt("id", dimensionId) + .put("element", details) + .build(); } else { - details.putString("name", registryIdentifier); - return details; + return details.putString("name", registryIdentifier); } } @@ -255,29 +257,29 @@ public final class DimensionData { * Serializes details of this dimension. * @return serialized details of this dimension */ - public CompoundTag serializeDimensionDetails() { - CompoundTag ret = new CompoundTag(); - ret.putBoolean("natural", isNatural); + public CompoundBinaryTag serializeDimensionDetails() { + CompoundBinaryTag.Builder ret = CompoundBinaryTag.builder(); + ret.putByte("natural", (byte) (isNatural ? 1 : 0)); ret.putFloat("ambient_light", ambientLight); - ret.putBoolean("shrunk", isShrunk); - ret.putBoolean("ultrawarm", isUltrawarm); - ret.putBoolean("has_ceiling", hasCeiling); - ret.putBoolean("has_skylight", hasSkylight); - ret.putBoolean("piglin_safe", isPiglinSafe); - ret.putBoolean("bed_works", doBedsWork); - ret.putBoolean("respawn_anchor_works", doRespawnAnchorsWork); - ret.putBoolean("has_raids", hasRaids); + ret.putByte("shrunk", (byte) (isShrunk ? 1 : 0)); + ret.putByte("ultrawarm", (byte) (isUltrawarm ? 1 : 0)); + ret.putByte("has_ceiling", (byte) (hasCeiling ? 1 : 0)); + ret.putByte("has_skylight", (byte) (hasSkylight ? 1 : 0)); + ret.putByte("piglin_safe", (byte) (isPiglinSafe ? 1 : 0)); + ret.putByte("bed_works", (byte) (doBedsWork ? 1 : 0)); + ret.putByte("respawn_anchor_works", (byte) (doBedsWork ? 1 : 0)); + ret.putByte("has_raids", (byte) (hasRaids ? 1 : 0)); ret.putInt("logical_height", logicalHeight); ret.putString("infiniburn", burningBehaviourIdentifier); if (fixedTime != null) { ret.putLong("fixed_time", fixedTime); } if (createDragonFight != null) { - ret.putBoolean("has_enderdragon_fight", createDragonFight); + ret.putByte("has_enderdragon_fight", (byte) (createDragonFight ? 1 : 0)); } if (coordinateScale != null) { ret.putDouble("coordinate_scale", coordinateScale); } - return ret; + return ret.build(); } } 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 f517e83a8..bdc9ae1ca 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 @@ -8,13 +8,12 @@ import com.velocitypowered.api.network.ProtocolVersion; import java.util.Map; import java.util.Set; -import net.kyori.nbt.CompoundTag; -import net.kyori.nbt.ListTag; -import net.kyori.nbt.Tag; -import net.kyori.nbt.TagType; +import net.kyori.adventure.nbt.BinaryTag; +import net.kyori.adventure.nbt.BinaryTagTypes; +import net.kyori.adventure.nbt.CompoundBinaryTag; +import net.kyori.adventure.nbt.ListBinaryTag; import org.checkerframework.checker.nullness.qual.Nullable; - public final class DimensionRegistry { private final Map registeredDimensions; @@ -80,24 +79,26 @@ public final class DimensionRegistry { * Encodes the stored Dimension registry as CompoundTag. * @return the CompoundTag containing identifier:type mappings */ - public ListTag encodeRegistry(ProtocolVersion version) { - ListTag list = new ListTag(TagType.COMPOUND); + public ListBinaryTag encodeRegistry(ProtocolVersion version) { + ListBinaryTag.Builder listBuilder = ListBinaryTag + .builder(BinaryTagTypes.COMPOUND); for (DimensionData iter : registeredDimensions.values()) { - list.add(iter.encodeAsCompoundTag(version)); + listBuilder.add(iter.encodeAsCompoundTag(version)); } - return list; + return listBuilder.build(); } /** * Decodes a CompoundTag storing a dimension registry. * @param toParse CompoundTag containing a dimension registry */ - public static ImmutableSet fromGameData(ListTag toParse, ProtocolVersion version) { + public static ImmutableSet fromGameData(ListBinaryTag toParse, + ProtocolVersion version) { Preconditions.checkNotNull(toParse, "ListTag cannot be null"); ImmutableSet.Builder mappings = ImmutableSet.builder(); - for (Tag iter : toParse) { - if (iter instanceof CompoundTag) { - mappings.add(DimensionData.decodeRegistryEntry((CompoundTag) iter, version)); + for (BinaryTag iter : toParse) { + if (iter instanceof CompoundBinaryTag) { + mappings.add(DimensionData.decodeRegistryEntry((CompoundBinaryTag) iter, version)); } } return mappings.build(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java index bb7516aa3..7b9764a71 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java @@ -12,17 +12,14 @@ import io.netty.buffer.ByteBufUtil; import io.netty.handler.codec.DecoderException; import io.netty.handler.codec.EncoderException; -import java.io.DataInput; -import java.io.DataOutput; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.UUID; -import net.kyori.nbt.CompoundTag; -import net.kyori.nbt.TagIO; -import net.kyori.nbt.TagType; +import net.kyori.adventure.nbt.BinaryTagIO; +import net.kyori.adventure.nbt.CompoundBinaryTag; public enum ProtocolUtils { ; @@ -192,11 +189,11 @@ public enum ProtocolUtils { } /** - * Reads a {@link net.kyori.nbt.CompoundTag} from the {@code buf}. + * Reads a {@link net.kyori.adventure.nbt.CompoundBinaryTag} from the {@code buf}. * @param buf the buffer to read from - * @return {@link net.kyori.nbt.CompoundTag} the CompoundTag from the buffer + * @return {@link net.kyori.adventure.nbt.CompoundBinaryTag} the CompoundTag from the buffer */ - public static CompoundTag readCompoundTag(ByteBuf buf) { + public static CompoundBinaryTag readCompoundTag(ByteBuf buf) { int indexBefore = buf.readerIndex(); byte startType = buf.readByte(); if (startType == 0) { @@ -204,7 +201,7 @@ public enum ProtocolUtils { } buf.readerIndex(indexBefore); try { - return TagIO.readDataInput(new ByteBufInputStream(buf)); + return BinaryTagIO.readDataInput(new ByteBufInputStream(buf)); } catch (IOException thrown) { throw new DecoderException( "Unable to parse NBT CompoundTag, full error: " + thrown.getMessage()); @@ -216,13 +213,13 @@ public enum ProtocolUtils { * @param buf the buffer to write to * @param compoundTag the CompoundTag to write */ - public static void writeCompoundTag(ByteBuf buf, CompoundTag compoundTag) { + public static void writeCompoundTag(ByteBuf buf, CompoundBinaryTag compoundTag) { if (compoundTag == null) { buf.writeByte(0); return; } try { - TagIO.writeDataOutput(compoundTag, new ByteBufOutputStream(buf)); + BinaryTagIO.writeDataOutput(compoundTag, new ByteBufOutputStream(buf)); } catch (IOException e) { throw new EncoderException("Unable to encode NBT CompoundTag"); } 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 009dd570a..b2e1353e4 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 @@ -6,11 +6,12 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.registry.DimensionData; import com.velocitypowered.proxy.connection.registry.DimensionInfo; import com.velocitypowered.proxy.connection.registry.DimensionRegistry; -import com.velocitypowered.proxy.protocol.*; +import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; -import net.kyori.nbt.CompoundTag; -import net.kyori.nbt.ListTag; -import net.kyori.nbt.TagType; +import net.kyori.adventure.nbt.BinaryTagTypes; +import net.kyori.adventure.nbt.CompoundBinaryTag; +import net.kyori.adventure.nbt.ListBinaryTag; import org.checkerframework.checker.nullness.qual.Nullable; public class JoinGame implements MinecraftPacket { @@ -30,7 +31,7 @@ public class JoinGame implements MinecraftPacket { private DimensionInfo dimensionInfo; // 1.16+ private DimensionData currentDimensionData; // 1.16.2+ private short previousGamemode; // 1.16+ - private CompoundTag biomeRegistry; // 1.16.2+ + private CompoundBinaryTag biomeRegistry; // 1.16.2+ public int getEntityId() { return entityId; @@ -132,11 +133,11 @@ public class JoinGame implements MinecraftPacket { this.isHardcore = isHardcore; } - public CompoundTag getBiomeRegistry() { + public CompoundBinaryTag getBiomeRegistry() { return biomeRegistry; } - public void setBiomeRegistry(CompoundTag biomeRegistry) { + public void setBiomeRegistry(CompoundBinaryTag biomeRegistry) { this.biomeRegistry = biomeRegistry; } @@ -179,20 +180,21 @@ public class JoinGame implements MinecraftPacket { if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { this.previousGamemode = buf.readByte(); ImmutableSet levelNames = ImmutableSet.copyOf(ProtocolUtils.readStringArray(buf)); - CompoundTag registryContainer = ProtocolUtils.readCompoundTag(buf); - ListTag dimensionRegistryContainer = null; + CompoundBinaryTag registryContainer = ProtocolUtils.readCompoundTag(buf); + ListBinaryTag dimensionRegistryContainer = null; if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { dimensionRegistryContainer = registryContainer.getCompound("minecraft:dimension_type") - .getList("value", TagType.COMPOUND); + .getList("value", BinaryTagTypes.COMPOUND); this.biomeRegistry = registryContainer.getCompound("minecraft:worldgen/biome"); } else { - dimensionRegistryContainer = registryContainer.getList("dimension", TagType.COMPOUND); + dimensionRegistryContainer = registryContainer.getList("dimension", + BinaryTagTypes.COMPOUND); } ImmutableSet readData = DimensionRegistry.fromGameData(dimensionRegistryContainer, version); this.dimensionRegistry = new DimensionRegistry(readData, levelNames); if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { - CompoundTag currentDimDataTag = ProtocolUtils.readCompoundTag(buf); + CompoundBinaryTag currentDimDataTag = ProtocolUtils.readCompoundTag(buf); dimensionIdentifier = ProtocolUtils.readString(buf); this.currentDimensionData = DimensionData.decodeBaseCompoundTag(currentDimDataTag, version) .annotateWith(dimensionIdentifier, null); @@ -246,18 +248,18 @@ public class JoinGame implements MinecraftPacket { buf.writeByte(previousGamemode); ProtocolUtils.writeStringArray(buf, dimensionRegistry.getLevelNames().toArray( new String[dimensionRegistry.getLevelNames().size()])); - CompoundTag registryContainer = new CompoundTag(); - ListTag encodedDimensionRegistry = dimensionRegistry.encodeRegistry(version); + CompoundBinaryTag.Builder registryContainer = CompoundBinaryTag.builder(); + ListBinaryTag encodedDimensionRegistry = dimensionRegistry.encodeRegistry(version); if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { - CompoundTag dimensionRegistryDummy = new CompoundTag(); + CompoundBinaryTag.Builder dimensionRegistryDummy = CompoundBinaryTag.builder(); dimensionRegistryDummy.putString("type", "minecraft:dimension_type"); dimensionRegistryDummy.put("value", encodedDimensionRegistry); - registryContainer.put("minecraft:dimension_type", dimensionRegistryDummy); + registryContainer.put("minecraft:dimension_type", dimensionRegistryDummy.build()); registryContainer.put("minecraft:worldgen/biome", biomeRegistry); } else { registryContainer.put("dimension", encodedDimensionRegistry); } - ProtocolUtils.writeCompoundTag(buf, registryContainer); + ProtocolUtils.writeCompoundTag(buf, registryContainer.build()); if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { ProtocolUtils.writeCompoundTag(buf, currentDimensionData.serializeDimensionDetails()); ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier()); 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 aef9a7a19..3a4fdb4af 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 @@ -7,7 +7,7 @@ import com.velocitypowered.proxy.connection.registry.DimensionInfo; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; -import net.kyori.nbt.CompoundTag; +import net.kyori.adventure.nbt.CompoundBinaryTag; public class Respawn implements MinecraftPacket { @@ -115,7 +115,7 @@ public class Respawn implements MinecraftPacket { String levelName = null; if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { - CompoundTag dimDataTag = ProtocolUtils.readCompoundTag(buf); + CompoundBinaryTag dimDataTag = ProtocolUtils.readCompoundTag(buf); dimensionIdentifier = ProtocolUtils.readString(buf); this.currentDimensionData = DimensionData.decodeBaseCompoundTag(dimDataTag, version) .annotateWith(dimensionIdentifier, null); From 3e8110834f99964bbe2bd64132c0db1b5e00e61e Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Fri, 7 Aug 2020 13:36:18 -0400 Subject: [PATCH 10/13] 1.16.2-rc1 --- .../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 f2944250e..abc03f4a0 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(748, "1.16.2"); + MINECRAFT_1_16_2(749, "1.16.2"); private final int protocol; private final String name; From 52c36a5d0fc737a72883800215564a66e3b9bdb8 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Fri, 7 Aug 2020 14:30:54 -0400 Subject: [PATCH 11/13] Add missing DimensionData field --- .../connection/registry/DimensionData.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java index 720c0bac2..d55463995 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionData.java @@ -25,6 +25,7 @@ public final class DimensionData { private final @Nullable Long fixedTime; private final @Nullable Boolean createDragonFight; private final @Nullable Double coordinateScale; + private final @Nullable String effects; /** * Initializes a new {@link DimensionData} instance. @@ -45,6 +46,7 @@ public final class DimensionData { * @param fixedTime optional. If set to any game daytime value will deactivate time cycle * @param createDragonFight optional. Internal flag used in the end dimension * @param coordinateScale optional, unknown purpose + * @param effects optional, unknown purpose */ public DimensionData(String registryIdentifier, @Nullable Integer dimensionId, @@ -55,14 +57,15 @@ public final class DimensionData { boolean doRespawnAnchorsWork, boolean hasRaids, int logicalHeight, String burningBehaviourIdentifier, @Nullable Long fixedTime, @Nullable Boolean createDragonFight, - @Nullable Double coordinateScale) { + @Nullable Double coordinateScale, + @Nullable String effects) { Preconditions.checkNotNull( - registryIdentifier, "registryIdentifier cannot be null"); + registryIdentifier, "registryIdentifier cannot be null"); Preconditions.checkArgument(registryIdentifier.length() > 0, - "registryIdentifier cannot be empty"); + "registryIdentifier cannot be empty"); Preconditions.checkArgument(logicalHeight >= 0, "localHeight must be >= 0"); Preconditions.checkNotNull( - burningBehaviourIdentifier, "burningBehaviourIdentifier cannot be null"); + burningBehaviourIdentifier, "burningBehaviourIdentifier cannot be null"); Preconditions.checkArgument(burningBehaviourIdentifier.length() > 0, "burningBehaviourIdentifier cannot be empty"); this.registryIdentifier = registryIdentifier; @@ -82,6 +85,7 @@ public final class DimensionData { this.fixedTime = fixedTime; this.createDragonFight = createDragonFight; this.coordinateScale = coordinateScale; + this.effects = effects; } public String getRegistryIdentifier() { @@ -165,7 +169,7 @@ public final class DimensionData { return new DimensionData(registryIdentifier, dimensionId, isNatural, ambientLight, isShrunk, isUltrawarm, hasCeiling, hasSkylight, isPiglinSafe, doBedsWork, doRespawnAnchorsWork, hasRaids, logicalHeight, burningBehaviourIdentifier, fixedTime, createDragonFight, - coordinateScale); + coordinateScale, effects); } public boolean isUnannotated() { @@ -200,11 +204,13 @@ public final class DimensionData { ? details.getByte("has_enderdragon_fight") >= 1 : null; Double coordinateScale = details.keySet().contains("coordinate_scale") ? details.getDouble("coordinate_scale") : null; + String effects = details.keySet().contains("effects") ? details.getString("effects") + : null; return new DimensionData( UNKNOWN_DIMENSION_ID, null, isNatural, ambientLight, isShrunk, isUltrawarm, hasCeiling, hasSkylight, isPiglinSafe, doBedsWork, doRespawnAnchorsWork, hasRaids, logicalHeight, burningBehaviourIdentifier, fixedTime, hasEnderdragonFight, - coordinateScale); + coordinateScale, effects); } /** @@ -280,6 +286,9 @@ public final class DimensionData { if (coordinateScale != null) { ret.putDouble("coordinate_scale", coordinateScale); } + if (effects != null) { + ret.putString("effects", effects); + } return ret.build(); } } From 9f38134b500c5ef1edeb66993f3583a2b39750e9 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 10 Aug 2020 12:53:39 -0400 Subject: [PATCH 12/13] 1.16.2-rc2 --- .../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 abc03f4a0..8c73ed3a1 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(749, "1.16.2"); + MINECRAFT_1_16_2(750, "1.16.2"); private final int protocol; private final String name; From ddf0e238e0ed436140743ac50704898c5a782b37 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 10 Aug 2020 21:45:59 -0400 Subject: [PATCH 13/13] Cross our fingers and hope this is 1.16.2 --- .../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 8c73ed3a1..96360503a 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(750, "1.16.2"); + MINECRAFT_1_16_2(751, "1.16.2"); private final int protocol; private final String name;