Update for 1.16.2-pre1

This commit is contained in:
Andrew Steinborn
2020-08-05 11:18:52 -04:00
parent b8a2d97935
commit f205ac19be
5 changed files with 76 additions and 37 deletions

View File

@@ -37,7 +37,7 @@ public enum ProtocolVersion {
MINECRAFT_1_15_2(578, "1.15.2"), MINECRAFT_1_15_2(578, "1.15.2"),
MINECRAFT_1_16(735, "1.16"), 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(741, "1.16.2"); MINECRAFT_1_16_2(744, "1.16.2");
private final int protocol; private final int protocol;
private final String name; private final String name;

View File

@@ -1,11 +1,13 @@
package com.velocitypowered.proxy.connection.registry; package com.velocitypowered.proxy.connection.registry;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ProtocolVersion;
import net.kyori.nbt.CompoundTag; import net.kyori.nbt.CompoundTag;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public final class DimensionData { public final class DimensionData {
private final String registryIdentifier; private final String registryIdentifier;
private final @Nullable Integer dimensionId;
private final boolean isNatural; private final boolean isNatural;
private final float ambientLight; private final float ambientLight;
private final boolean isShrunk; private final boolean isShrunk;
@@ -24,6 +26,7 @@ public final class DimensionData {
/** /**
* Initializes a new {@link DimensionData} instance. * Initializes a new {@link DimensionData} instance.
* @param registryIdentifier the identifier for the dimension from the registry. * @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 isNatural indicates if the dimension use natural world generation (e.g. overworld)
* @param ambientLight the light level the client sees without external lighting * @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) * @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 fixedTime optional. If set to any game daytime value will deactivate time cycle
* @param createDragonFight optional. Internal flag used in the end dimension * @param createDragonFight optional. Internal flag used in the end dimension
*/ */
public DimensionData(String registryIdentifier, boolean isNatural, public DimensionData(String registryIdentifier,
float ambientLight, boolean isShrunk, boolean isUltrawarm, @Nullable Integer dimensionId,
boolean hasCeiling, boolean hasSkylight, boolean isNatural,
boolean isPiglinSafe, boolean doBedsWork, float ambientLight, boolean isShrunk, boolean isUltrawarm,
boolean doRespawnAnchorsWork, boolean hasRaids, boolean hasCeiling, boolean hasSkylight,
int logicalHeight, String burningBehaviourIdentifier, boolean isPiglinSafe, boolean doBedsWork,
@Nullable Long fixedTime, @Nullable Boolean createDragonFight) { boolean doRespawnAnchorsWork, boolean hasRaids,
int logicalHeight, String burningBehaviourIdentifier,
@Nullable Long fixedTime, @Nullable Boolean createDragonFight) {
Preconditions.checkNotNull( Preconditions.checkNotNull(
registryIdentifier, "registryIdentifier cannot be null"); registryIdentifier, "registryIdentifier cannot be null");
Preconditions.checkArgument(registryIdentifier.length() > 0, Preconditions.checkArgument(registryIdentifier.length() > 0,
@@ -56,6 +61,7 @@ public final class DimensionData {
Preconditions.checkArgument(burningBehaviourIdentifier.length() > 0, Preconditions.checkArgument(burningBehaviourIdentifier.length() > 0,
"burningBehaviourIdentifier cannot be empty"); "burningBehaviourIdentifier cannot be empty");
this.registryIdentifier = registryIdentifier; this.registryIdentifier = registryIdentifier;
this.dimensionId = dimensionId;
this.isNatural = isNatural; this.isNatural = isNatural;
this.ambientLight = ambientLight; this.ambientLight = ambientLight;
this.isShrunk = isShrunk; this.isShrunk = isShrunk;
@@ -76,6 +82,10 @@ public final class DimensionData {
return registryIdentifier; return registryIdentifier;
} }
public Integer getDimensionId() {
return dimensionId;
}
public boolean isNatural() { public boolean isNatural() {
return isNatural; return isNatural;
} }
@@ -134,41 +144,68 @@ public final class DimensionData {
/** /**
* Parses a given CompoundTag to a DimensionData instance. * 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 * @return game dimension data
*/ */
public static DimensionData decodeCompoundTag(CompoundTag toRead) { public static DimensionData decodeCompoundTag(CompoundTag dimTag, ProtocolVersion version) {
Preconditions.checkNotNull(toRead, "CompoundTag cannot be null"); Preconditions.checkNotNull(dimTag, "CompoundTag cannot be null");
String registryIdentifier = toRead.getString("name"); String registryIdentifier = dimTag.getString("name");
boolean isNatural = toRead.getBoolean("natural"); CompoundTag details;
float ambientLight = toRead.getFloat("ambient_light"); Integer dimensionId = null;
boolean isShrunk = toRead.getBoolean("shrunk"); if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
boolean isUltrawarm = toRead.getBoolean("ultrawarm"); dimensionId = dimTag.getInt("id");
boolean hasCeiling = toRead.getBoolean("has_ceiling"); details = dimTag.getCompound("element");
boolean hasSkylight = toRead.getBoolean("has_skylight"); } else {
boolean isPiglinSafe = toRead.getBoolean("piglin_safe"); details = dimTag;
boolean doBedsWork = toRead.getBoolean("bed_works"); }
boolean doRespawnAnchorsWork = toRead.getBoolean("respawn_anchor_works"); boolean isNatural = details.getBoolean("natural");
boolean hasRaids = toRead.getBoolean("has_raids"); float ambientLight = details.getFloat("ambient_light");
int logicalHeight = toRead.getInt("logical_height"); boolean isShrunk = details.getBoolean("shrunk");
String burningBehaviourIdentifier = toRead.getString("infiniburn"); boolean isUltrawarm = details.getBoolean("ultrawarm");
Long fixedTime = toRead.contains("fixed_time") boolean hasCeiling = details.getBoolean("has_ceiling");
? toRead.getLong("fixed_time") : null; boolean hasSkylight = details.getBoolean("has_skylight");
Boolean hasEnderdragonFight = toRead.contains("has_enderdragon_fight") boolean isPiglinSafe = details.getBoolean("piglin_safe");
? toRead.getBoolean("has_enderdragon_fight") : null; 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( return new DimensionData(
registryIdentifier, isNatural, ambientLight, isShrunk, registryIdentifier, dimensionId, isNatural, ambientLight, isShrunk,
isUltrawarm, hasCeiling, hasSkylight, isPiglinSafe, doBedsWork, doRespawnAnchorsWork, isUltrawarm, hasCeiling, hasSkylight, isPiglinSafe, doBedsWork, doRespawnAnchorsWork,
hasRaids, logicalHeight, burningBehaviourIdentifier, fixedTime, hasEnderdragonFight); hasRaids, logicalHeight, burningBehaviourIdentifier, fixedTime, hasEnderdragonFight);
} }
/** /**
* Encodes the Dimension data as CompoundTag. * Encodes the Dimension data as CompoundTag.
* @param version the version to serialize as
* @return compound containing the dimension data * @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(); CompoundTag ret = new CompoundTag();
ret.putString("name", registryIdentifier);
ret.putBoolean("natural", isNatural); ret.putBoolean("natural", isNatural);
ret.putFloat("ambient_light", ambientLight); ret.putFloat("ambient_light", ambientLight);
ret.putBoolean("shrunk", isShrunk); ret.putBoolean("shrunk", isShrunk);

View File

@@ -4,6 +4,7 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.velocitypowered.api.network.ProtocolVersion;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@@ -79,10 +80,10 @@ public final class DimensionRegistry {
* Encodes the stored Dimension registry as CompoundTag. * Encodes the stored Dimension registry as CompoundTag.
* @return the CompoundTag containing identifier:type mappings * @return the CompoundTag containing identifier:type mappings
*/ */
public ListTag encodeRegistry() { public ListTag encodeRegistry(ProtocolVersion version) {
ListTag list = new ListTag(TagType.COMPOUND); ListTag list = new ListTag(TagType.COMPOUND);
for (DimensionData iter : registeredDimensions.values()) { for (DimensionData iter : registeredDimensions.values()) {
list.add(iter.encodeAsCompundTag()); list.add(iter.encodeAsCompoundTag(version));
} }
return list; return list;
} }
@@ -91,12 +92,12 @@ public final class DimensionRegistry {
* Decodes a CompoundTag storing a dimension registry. * Decodes a CompoundTag storing a dimension registry.
* @param toParse CompoundTag containing a dimension registry * @param toParse CompoundTag containing a dimension registry
*/ */
public static ImmutableSet<DimensionData> fromGameData(ListTag toParse) { public static ImmutableSet<DimensionData> fromGameData(ListTag toParse, ProtocolVersion version) {
Preconditions.checkNotNull(toParse, "ListTag cannot be null"); Preconditions.checkNotNull(toParse, "ListTag cannot be null");
ImmutableSet.Builder<DimensionData> mappings = ImmutableSet.builder(); ImmutableSet.Builder<DimensionData> mappings = ImmutableSet.builder();
for (Tag iter : toParse) { for (Tag iter : toParse) {
if (iter instanceof CompoundTag) { if (iter instanceof CompoundTag) {
mappings.add(DimensionData.decodeCompoundTag((CompoundTag) iter)); mappings.add(DimensionData.decodeCompoundTag((CompoundTag) iter, version));
} }
} }
return mappings.build(); return mappings.build();

View File

@@ -184,7 +184,7 @@ public class JoinGame implements MinecraftPacket {
dimensionRegistryContainer = registryContainer.getList("dimension", TagType.COMPOUND); dimensionRegistryContainer = registryContainer.getList("dimension", TagType.COMPOUND);
} }
ImmutableSet<DimensionData> readData = ImmutableSet<DimensionData> readData =
DimensionRegistry.fromGameData(dimensionRegistryContainer); DimensionRegistry.fromGameData(dimensionRegistryContainer, version);
this.dimensionRegistry = new DimensionRegistry(readData, levelNames); this.dimensionRegistry = new DimensionRegistry(readData, levelNames);
dimensionIdentifier = ProtocolUtils.readString(buf); dimensionIdentifier = ProtocolUtils.readString(buf);
levelName = ProtocolUtils.readString(buf); levelName = ProtocolUtils.readString(buf);
@@ -235,7 +235,7 @@ public class JoinGame implements MinecraftPacket {
ProtocolUtils.writeStringArray(buf, dimensionRegistry.getLevelNames().toArray( ProtocolUtils.writeStringArray(buf, dimensionRegistry.getLevelNames().toArray(
new String[dimensionRegistry.getLevelNames().size()])); new String[dimensionRegistry.getLevelNames().size()]));
CompoundTag registryContainer = new CompoundTag(); CompoundTag registryContainer = new CompoundTag();
ListTag encodedDimensionRegistry = dimensionRegistry.encodeRegistry(); ListTag encodedDimensionRegistry = dimensionRegistry.encodeRegistry(version);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
CompoundTag dimensionRegistryDummy = new CompoundTag(); CompoundTag dimensionRegistryDummy = new CompoundTag();
dimensionRegistryDummy.putString("type", "minecraft:dimension_type"); dimensionRegistryDummy.putString("type", "minecraft:dimension_type");

View File

@@ -135,5 +135,6 @@ public class ArgumentPropertyRegistry {
dummy("minecraft:float_range", DUMMY); dummy("minecraft:float_range", DUMMY);
dummy("minecraft:time", DUMMY); // added in 1.14 dummy("minecraft:time", DUMMY); // added in 1.14
dummy("minecraft:uuid", DUMMY); // added in 1.16 dummy("minecraft:uuid", DUMMY); // added in 1.16
dummy("minecraft:angle", DUMMY); // added in 1.16.2
} }
} }