3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00
Dieser Commit ist enthalten in:
Andrew Steinborn 2020-08-06 15:00:15 -04:00
Ursprung 32e90a1969
Commit a081c35fdb
7 geänderte Dateien mit 115 neuen und 48 gelöschten Zeilen

Datei anzeigen

@ -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(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

@ -342,14 +342,15 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
player.getMinecraftConnection().delayedWrite( player.getMinecraftConnection().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.getMinecraftConnection().delayedWrite( player.getMinecraftConnection().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,7 @@ public final class DimensionData {
} }
} }
private CompoundTag serializeDimensionDetails() { 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");
this.levelName = Preconditions.checkNotNull(
levelName, "levelName cannot be null");
Preconditions.checkArgument(
levelName.length() > 0,
"registryIdentifier cannot be empty"); "registryIdentifier cannot be empty");
this.levelName = levelName;
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,10 @@ public class JoinGame implements MinecraftPacket {
this.biomeRegistry = biomeRegistry; this.biomeRegistry = biomeRegistry;
} }
public DimensionData getCurrentDimensionData() {
return currentDimensionData;
}
@Override @Override
public String toString() { public String toString() {
return "JoinGame{" return "JoinGame{"
@ -186,8 +191,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);
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); dimensionIdentifier = ProtocolUtils.readString(buf);
levelName = 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 {
@ -246,8 +258,13 @@ public class JoinGame implements MinecraftPacket {
registryContainer.put("dimension", encodedDimensionRegistry); registryContainer.put("dimension", encodedDimensionRegistry);
} }
ProtocolUtils.writeCompoundTag(buf, registryContainer); ProtocolUtils.writeCompoundTag(buf, registryContainer);
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.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);
} 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;
@ -32,6 +35,7 @@ public class Respawn implements MinecraftPacket {
this.shouldKeepPlayerData = shouldKeepPlayerData; this.shouldKeepPlayerData = shouldKeepPlayerData;
this.dimensionInfo = dimensionInfo; this.dimensionInfo = dimensionInfo;
this.previousGamemode = previousGamemode; this.previousGamemode = previousGamemode;
this.currentDimensionData = currentDimensionData;
} }
public int getDimension() { public int getDimension() {
@ -99,8 +103,9 @@ public class Respawn implements MinecraftPacket {
+ ", gamemode=" + gamemode + ", gamemode=" + gamemode
+ ", levelType='" + levelType + '\'' + ", levelType='" + levelType + '\''
+ ", shouldKeepPlayerData=" + shouldKeepPlayerData + ", shouldKeepPlayerData=" + shouldKeepPlayerData
+ ", 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) {
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); dimensionIdentifier = ProtocolUtils.readString(buf);
levelName = 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) {
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.getRegistryIdentifier());
ProtocolUtils.writeString(buf, dimensionInfo.getLevelName()); ProtocolUtils.writeString(buf, dimensionInfo.getLevelName());
}
} else { } else {
buf.writeInt(dimension); buf.writeInt(dimension);
} }