13
0
geforkt von Mirrors/Velocity
Dieser Commit ist enthalten in:
Andrew Steinborn 2020-08-06 15:08:50 -04:00
Ursprung d79c1d0407
Commit b34b198064
7 geänderte Dateien mit 114 neuen und 44 gelöschten Zeilen

Datei anzeigen

@ -39,7 +39,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(746, "1.16.2"); MINECRAFT_1_16_2(748, "1.16.2");
private final int protocol; private final int protocol;
private final String name; private final String name;

Datei anzeigen

@ -336,15 +336,16 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
int tempDim = joinGame.getDimension() == 0 ? -1 : 0; int tempDim = joinGame.getDimension() == 0 ? -1 : 0;
player.getConnection().delayedWrite( player.getConnection().delayedWrite(
new Respawn(tempDim, joinGame.getPartialHashedSeed(), joinGame.getDifficulty(), new Respawn(tempDim, joinGame.getPartialHashedSeed(), joinGame.getDifficulty(),
joinGame.getGamemode(), joinGame.getLevelType(), joinGame.getGamemode(), joinGame.getLevelType(),
false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode())); false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode(),
joinGame.getCurrentDimensionData()));
} }
player.getConnection().delayedWrite( player.getConnection().delayedWrite(
new Respawn(joinGame.getDimension(), joinGame.getPartialHashedSeed(), new Respawn(joinGame.getDimension(), joinGame.getPartialHashedSeed(),
joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(), joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(),
false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode())); false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode(),
joinGame.getCurrentDimensionData()));
destination.setActiveDimensionRegistry(joinGame.getDimensionRegistry()); // 1.16 destination.setActiveDimensionRegistry(joinGame.getDimensionRegistry()); // 1.16
} }

Datei anzeigen

@ -6,6 +6,8 @@ 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 static final String UNKNOWN_DIMENSION_ID = "velocity:unknown_dimension";
private final String registryIdentifier; private final String registryIdentifier;
private final @Nullable Integer dimensionId; private final @Nullable Integer dimensionId;
private final boolean isNatural; private final boolean isNatural;
@ -151,22 +153,34 @@ public final class DimensionData {
} }
/** /**
* Parses a given CompoundTag to a DimensionData instance. * Returns a fresh {@link DimensionData} with the specified {@code registryIdentifier}
* @param dimTag the compound from the registry to read * and {@code dimensionId}.
* @param version the protocol version from the registry *
* @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 * @return game dimension data
*/ */
public static DimensionData decodeCompoundTag(CompoundTag dimTag, ProtocolVersion version) { public static DimensionData decodeBaseCompoundTag(CompoundTag details, 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"); boolean isNatural = details.getBoolean("natural");
float ambientLight = details.getFloat("ambient_light"); float ambientLight = details.getFloat("ambient_light");
boolean isShrunk = details.getBoolean("shrunk"); boolean isShrunk = details.getBoolean("shrunk");
@ -186,12 +200,34 @@ public final class DimensionData {
Double coordinateScale = details.contains("coordinate_scale") Double coordinateScale = details.contains("coordinate_scale")
? details.getDouble("coordinate_scale") : null; ? details.getDouble("coordinate_scale") : null;
return new DimensionData( return new DimensionData(
registryIdentifier, dimensionId, isNatural, ambientLight, isShrunk, UNKNOWN_DIMENSION_ID, null, 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,
coordinateScale); 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);
}
/** /**
* Encodes the Dimension data as CompoundTag. * Encodes the Dimension data as CompoundTag.
* @param version the version to serialize as * @param version the version to serialize as
@ -215,7 +251,11 @@ public final class DimensionData {
} }
} }
private CompoundTag serializeDimensionDetails() { /**
* Serializes details of this dimension.
* @return serialized details of this dimension
*/
public CompoundTag serializeDimensionDetails() {
CompoundTag ret = new CompoundTag(); CompoundTag ret = new CompoundTag();
ret.putBoolean("natural", isNatural); ret.putBoolean("natural", isNatural);
ret.putFloat("ambient_light", ambientLight); ret.putFloat("ambient_light", ambientLight);

Datei anzeigen

@ -1,6 +1,7 @@
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 org.checkerframework.checker.nullness.qual.Nullable;
public final class DimensionInfo { 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 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(String registryIdentifier, String levelName, public DimensionInfo(String registryIdentifier, @Nullable String levelName,
boolean isFlat, boolean isDebugType) { boolean isFlat, boolean isDebugType) {
this.registryIdentifier = Preconditions.checkNotNull( this.registryIdentifier = Preconditions.checkNotNull(
registryIdentifier, "registryIdentifier cannot be null"); registryIdentifier, "registryIdentifier cannot be null");
Preconditions.checkArgument( Preconditions.checkArgument(registryIdentifier.length() > 0,
registryIdentifier.length() > 0, "registryIdentifier cannot be empty");
"registryIdentifier cannot be empty"); this.levelName = levelName;
this.levelName = Preconditions.checkNotNull(
levelName, "levelName cannot be null");
Preconditions.checkArgument(
levelName.length() > 0,
"registryIdentifier cannot be empty");
this.isFlat = isFlat; this.isFlat = isFlat;
this.isDebugType = isDebugType; this.isDebugType = isDebugType;
} }
@ -40,7 +36,7 @@ public final class DimensionInfo {
return isFlat; return isFlat;
} }
public String getLevelName() { public @Nullable String getLevelName() {
return levelName; return levelName;
} }

Datei anzeigen

@ -97,7 +97,7 @@ public final class DimensionRegistry {
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, version)); mappings.add(DimensionData.decodeRegistryEntry((CompoundTag) iter, version));
} }
} }
return mappings.build(); return mappings.build();

Datei anzeigen

@ -28,6 +28,7 @@ public class JoinGame implements MinecraftPacket {
private boolean showRespawnScreen; private boolean showRespawnScreen;
private DimensionRegistry dimensionRegistry; // 1.16+ private DimensionRegistry dimensionRegistry; // 1.16+
private DimensionInfo dimensionInfo; // 1.16+ private DimensionInfo dimensionInfo; // 1.16+
private DimensionData currentDimensionData; // 1.16.2+
private short previousGamemode; // 1.16+ private short previousGamemode; // 1.16+
private CompoundTag biomeRegistry; // 1.16.2+ private CompoundTag biomeRegistry; // 1.16.2+
@ -139,6 +140,9 @@ public class JoinGame implements MinecraftPacket {
this.biomeRegistry = biomeRegistry; this.biomeRegistry = biomeRegistry;
} }
public DimensionData getCurrentDimensionData() {
return currentDimensionData;
}
@Override @Override
public String toString() { public String toString() {
@ -186,8 +190,15 @@ public class JoinGame implements MinecraftPacket {
ImmutableSet<DimensionData> readData = ImmutableSet<DimensionData> readData =
DimensionRegistry.fromGameData(dimensionRegistryContainer, version); DimensionRegistry.fromGameData(dimensionRegistryContainer, version);
this.dimensionRegistry = new DimensionRegistry(readData, levelNames); this.dimensionRegistry = new DimensionRegistry(readData, levelNames);
dimensionIdentifier = ProtocolUtils.readString(buf); if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
levelName = ProtocolUtils.readString(buf); 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) { } else if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) {
this.dimension = buf.readInt(); this.dimension = buf.readInt();
} else { } else {
@ -248,8 +259,13 @@ public class JoinGame implements MinecraftPacket {
registryContainer.put("dimension", encodedDimensionRegistry); registryContainer.put("dimension", encodedDimensionRegistry);
} }
ProtocolUtils.writeCompoundTag(buf, registryContainer); ProtocolUtils.writeCompoundTag(buf, registryContainer);
ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier()); if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
ProtocolUtils.writeString(buf, dimensionInfo.getLevelName()); 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) { } else if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) {
buf.writeInt(dimension); buf.writeInt(dimension);
} else { } else {

Datei anzeigen

@ -2,10 +2,12 @@ package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; 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.DimensionInfo;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.kyori.nbt.CompoundTag;
public class Respawn implements MinecraftPacket { public class Respawn implements MinecraftPacket {
@ -15,15 +17,16 @@ public class Respawn implements MinecraftPacket {
private short gamemode; private short gamemode;
private String levelType = ""; private String levelType = "";
private boolean shouldKeepPlayerData; // 1.16+ private boolean shouldKeepPlayerData; // 1.16+
private DimensionInfo dimensionInfo; // 1.16+ private DimensionInfo dimensionInfo; // 1.16-1.16.1
private short previousGamemode; // 1.16+ private short previousGamemode; // 1.16+
private DimensionData currentDimensionData; // 1.16.2+
public Respawn() { public Respawn() {
} }
public Respawn(int dimension, long partialHashedSeed, short difficulty, short gamemode, public Respawn(int dimension, long partialHashedSeed, short difficulty, short gamemode,
String levelType, boolean shouldKeepPlayerData, DimensionInfo dimensionInfo, String levelType, boolean shouldKeepPlayerData, DimensionInfo dimensionInfo,
short previousGamemode) { short previousGamemode, DimensionData currentDimensionData) {
this.dimension = dimension; this.dimension = dimension;
this.partialHashedSeed = partialHashedSeed; this.partialHashedSeed = partialHashedSeed;
this.difficulty = difficulty; this.difficulty = difficulty;
@ -100,7 +103,9 @@ public class Respawn implements MinecraftPacket {
+ ", levelType='" + levelType + '\'' + ", levelType='" + levelType + '\''
+ ", shouldKeepPlayerData=" + shouldKeepPlayerData + ", shouldKeepPlayerData=" + shouldKeepPlayerData
+ ", dimensionRegistryName='" + dimensionInfo.toString() + '\'' + ", dimensionRegistryName='" + dimensionInfo.toString() + '\''
+ ", dimensionInfo=" + dimensionInfo
+ ", previousGamemode=" + previousGamemode + ", previousGamemode=" + previousGamemode
+ ", dimensionData=" + currentDimensionData
+ '}'; + '}';
} }
@ -109,8 +114,15 @@ public class Respawn implements MinecraftPacket {
String dimensionIdentifier = null; String dimensionIdentifier = null;
String levelName = null; String levelName = null;
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
dimensionIdentifier = ProtocolUtils.readString(buf); if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
levelName = ProtocolUtils.readString(buf); 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 { } else {
this.dimension = buf.readInt(); this.dimension = buf.readInt();
} }
@ -135,8 +147,13 @@ 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.getRegistryIdentifier()); if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
ProtocolUtils.writeString(buf, dimensionInfo.getLevelName()); ProtocolUtils.writeCompoundTag(buf, currentDimensionData.serializeDimensionDetails());
ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier());
} else {
ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier());
ProtocolUtils.writeString(buf, dimensionInfo.getLevelName());
}
} else { } else {
buf.writeInt(dimension); buf.writeInt(dimension);
} }