From f205ac19bec2df6e837de1c64b191710a3eaeaa8 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Wed, 5 Aug 2020 11:18:52 -0400 Subject: [PATCH] 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 } }