13
0
geforkt von Mirrors/Velocity
Dieser Commit ist enthalten in:
Lechner Markus 2020-06-05 15:45:11 +02:00
Ursprung 368d50b455
Commit aa4a8de2fd
5 geänderte Dateien mit 54 neuen und 32 gelöschten Zeilen

Datei anzeigen

@ -1,9 +1,8 @@
package com.velocitypowered.proxy.protocol; package com.velocitypowered.proxy.protocol;
import net.kyori.nbt.CompoundTag;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import net.kyori.nbt.CompoundTag;
public class DimensionData { public class DimensionData {
private final @Nonnull String registryIdentifier; private final @Nonnull String registryIdentifier;
@ -16,6 +15,18 @@ public class DimensionData {
private final @Nullable Long fixedTime; private final @Nullable Long fixedTime;
private final @Nullable Boolean hasEnderdragonFight; private final @Nullable Boolean hasEnderdragonFight;
/**
* Initializes a new {@link DimensionData} instance.
* @param registryIdentifier the identifier for the dimension from the registry.
* @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)
* @param isUltrawarm internal dimension warmth flag
* @param hasCeiling indicates if the dimension has a ceiling layer
* @param hasSkylight indicates if the dimension should display the sun
* @param fixedTime optional. If set to any game daytime value will deactivate time cycle
* @param hasEnderdragonFight optional. Internal flag used in the end dimension
*/
public DimensionData(@Nonnull String registryIdentifier, boolean isNatural, public DimensionData(@Nonnull String registryIdentifier, boolean isNatural,
float ambientLight, boolean isShrunk, boolean isUltrawarm, float ambientLight, boolean isShrunk, boolean isUltrawarm,
boolean hasCeiling, boolean hasSkylight, boolean hasCeiling, boolean hasSkylight,
@ -67,7 +78,12 @@ public class DimensionData {
return hasEnderdragonFight; return hasEnderdragonFight;
} }
public static DimensionData fromNBT(@Nonnull CompoundTag toRead) { /**
* Parses a given CompoundTag to a DimensionData instance.
* @param toRead the compound from the registry to read
* @return game dimension data
*/
public static DimensionData fromCompoundTag(@Nonnull CompoundTag toRead) {
if (toRead == null) { if (toRead == null) {
throw new IllegalArgumentException("CompoundTag cannot be null"); throw new IllegalArgumentException("CompoundTag cannot be null");
} }
@ -80,11 +96,18 @@ public class DimensionData {
boolean hasCeiling = values.getBoolean("has_ceiling"); boolean hasCeiling = values.getBoolean("has_ceiling");
boolean hasSkylight = values.getBoolean("has_skylight"); boolean hasSkylight = values.getBoolean("has_skylight");
Long fixedTime = values.contains("fixed_time") ? values.getLong("fixed_time") : null; Long fixedTime = values.contains("fixed_time") ? values.getLong("fixed_time") : null;
Boolean hasEnderdragonFight = values.contains("has_enderdragon_fight") ? values.getBoolean("has_enderdragon_fight") : null; Boolean hasEnderdragonFight = values.contains("has_enderdragon_fight")
return new DimensionData(registryIdentifier, isNatural, ambientLight, isShrunk, isUltrawarm, hasCeiling, hasSkylight, fixedTime, hasEnderdragonFight); ? values.getBoolean("has_enderdragon_fight") : null;
return new DimensionData(
registryIdentifier, isNatural, ambientLight, isShrunk,
isUltrawarm, hasCeiling, hasSkylight, fixedTime, hasEnderdragonFight);
} }
public CompoundTag encode() { /**
* Encodes the Dimension data as CompoundTag.
* @return compound containing the dimension data
*/
public CompoundTag encodeAsCompundTag() {
CompoundTag ret = new CompoundTag(); CompoundTag ret = new CompoundTag();
ret.putString("key", registryIdentifier); ret.putString("key", registryIdentifier);
CompoundTag values = new CompoundTag(); CompoundTag values = new CompoundTag();

Datei anzeigen

@ -4,28 +4,28 @@ import javax.annotation.Nonnull;
public class DimensionInfo { public class DimensionInfo {
private final @Nonnull String dimensionIdentifier; private final @Nonnull String registryIdentifier;
private final @Nonnull String levelName; private final @Nonnull String levelName;
private final boolean isFlat; private final boolean isFlat;
private final boolean isDebugType; private final boolean isDebugType;
/** /**
* Initializes a new {@link DimensionInfo} instance. * Initializes a new {@link DimensionInfo} instance.
* @param dimensionIdentifier the identifier for the dimension from the registry * @param registryIdentifier the identifier for the dimension from the registry
* @param levelName the level name as displayed in the F3 menu and logs * @param levelName the level name as displayed in the F3 menu and logs
* @param isFlat if true will set world lighting below surface-level to not display fog * @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 * @param isDebugType if true constrains the world to the very limited debug-type world
*/ */
public DimensionInfo(@Nonnull String dimensionIdentifier, @Nonnull String levelName, public DimensionInfo(@Nonnull String registryIdentifier, @Nonnull String levelName,
boolean isFlat, boolean isDebugType) { boolean isFlat, boolean isDebugType) {
if (dimensionIdentifier == null || dimensionIdentifier.isEmpty() if (registryIdentifier == null || registryIdentifier.isEmpty()
|| dimensionIdentifier.isBlank()) { || registryIdentifier.isBlank()) {
throw new IllegalArgumentException("DimensionRegistryName may not be empty or null"); throw new IllegalArgumentException("Dimension registry identifier may not be empty or null");
} }
this.dimensionIdentifier = dimensionIdentifier; this.registryIdentifier = registryIdentifier;
if (levelName == null || levelName.isEmpty() if (levelName == null || levelName.isEmpty()
|| levelName.isBlank()) { || levelName.isBlank()) {
throw new IllegalArgumentException("DimensionLevelName may not be empty or null"); throw new IllegalArgumentException("dimensions level name may not be empty or null");
} }
this.levelName = levelName; this.levelName = levelName;
this.isFlat = isFlat; this.isFlat = isFlat;
@ -44,7 +44,7 @@ public class DimensionInfo {
return levelName; return levelName;
} }
public @Nonnull String getDimensionIdentifier() { public @Nonnull String getRegistryIdentifier() {
return dimensionIdentifier; return registryIdentifier;
} }
} }

Datei anzeigen

@ -1,9 +1,10 @@
package com.velocitypowered.proxy.protocol; package com.velocitypowered.proxy.protocol;
import java.util.*; import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.Set;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import com.google.inject.internal.asm.$TypePath;
import net.kyori.nbt.CompoundTag; import net.kyori.nbt.CompoundTag;
import net.kyori.nbt.ListTag; import net.kyori.nbt.ListTag;
import net.kyori.nbt.Tag; import net.kyori.nbt.Tag;
@ -69,9 +70,9 @@ public class DimensionRegistry {
throw new IllegalArgumentException("Dimension info cannot be null"); throw new IllegalArgumentException("Dimension info cannot be null");
} }
try { try {
getDimensionData(toValidate.getDimensionIdentifier()); getDimensionData(toValidate.getRegistryIdentifier());
for (int i = 0; i < levelNames.length; i++) { for (int i = 0; i < levelNames.length; i++) {
if(levelNames[i].equals(toValidate.getDimensionIdentifier())) { if (levelNames[i].equals(toValidate.getRegistryIdentifier())) {
return true; return true;
} }
} }
@ -89,18 +90,19 @@ public class DimensionRegistry {
CompoundTag ret = new CompoundTag(); CompoundTag ret = new CompoundTag();
ListTag list = new ListTag(TagType.COMPOUND); ListTag list = new ListTag(TagType.COMPOUND);
for (DimensionData iter : dimensionRegistry) { for (DimensionData iter : dimensionRegistry) {
list.add(iter.encode()); list.add(iter.encodeAsCompundTag());
} }
ret.put("dimension", list); ret.put("dimension", list);
return ret; return ret;
} }
/** /**
* 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
* @param levelNames world level names * @param levelNames world level names
*/ */
public static DimensionRegistry fromGameData(@Nonnull CompoundTag toParse, @Nonnull String[] levelNames) { public static DimensionRegistry fromGameData(
@Nonnull CompoundTag toParse, @Nonnull String[] levelNames) {
if (toParse == null) { if (toParse == null) {
throw new IllegalArgumentException("CompoundTag cannot be null"); throw new IllegalArgumentException("CompoundTag cannot be null");
} }
@ -116,7 +118,7 @@ public class DimensionRegistry {
if (!(iter instanceof CompoundTag)) { if (!(iter instanceof CompoundTag)) {
throw new IllegalStateException("DimensionList in CompoundTag contains an invalid entry"); throw new IllegalStateException("DimensionList in CompoundTag contains an invalid entry");
} }
mappings.add(DimensionData.fromNBT((CompoundTag) iter)); mappings.add(DimensionData.fromCompoundTag((CompoundTag) iter));
} }
if (mappings.isEmpty()) { if (mappings.isEmpty()) {
throw new IllegalStateException("Dimension mapping cannot be empty"); throw new IllegalStateException("Dimension mapping cannot be empty");

Datei anzeigen

@ -6,9 +6,6 @@ import com.velocitypowered.proxy.protocol.*;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Map;
import java.util.Set;
public class JoinGame implements MinecraftPacket { public class JoinGame implements MinecraftPacket {
private int entityId; private int entityId;
@ -177,7 +174,7 @@ public class JoinGame implements MinecraftPacket {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
ProtocolUtils.writeStringArray(buf, dimensionRegistry.getLevelNames()); ProtocolUtils.writeStringArray(buf, dimensionRegistry.getLevelNames());
ProtocolUtils.writeCompoundTag(buf, dimensionRegistry.encodeRegistry()); ProtocolUtils.writeCompoundTag(buf, dimensionRegistry.encodeRegistry());
ProtocolUtils.writeString(buf, dimensionInfo.getDimensionIdentifier()); ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier());
ProtocolUtils.writeString(buf, dimensionInfo.getLevelName()); ProtocolUtils.writeString(buf, dimensionInfo.getLevelName());
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) { } else if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) {
buf.writeInt(dimension); buf.writeInt(dimension);

Datei anzeigen

@ -122,7 +122,7 @@ public class Respawn implements MinecraftPacket {
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
ProtocolUtils.writeString(buf, dimensionInfo.getDimensionIdentifier()); ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier());
ProtocolUtils.writeString(buf, dimensionInfo.getLevelName()); ProtocolUtils.writeString(buf, dimensionInfo.getLevelName());
} else { } else {
buf.writeInt(dimension); buf.writeInt(dimension);