3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-16 21:10:30 +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_16(735, "1.16"),
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 String name;

Datei anzeigen

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

Datei anzeigen

@ -6,6 +6,8 @@ import net.kyori.nbt.CompoundTag;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class DimensionData {
private static final String UNKNOWN_DIMENSION_ID = "velocity:unknown_dimension";
private final String registryIdentifier;
private final @Nullable Integer dimensionId;
private final boolean isNatural;
@ -151,22 +153,34 @@ public final class DimensionData {
}
/**
* Parses a given CompoundTag to a DimensionData instance.
* @param dimTag the compound from the registry to read
* @param version the protocol version from the registry
* Returns a fresh {@link DimensionData} with the specified {@code registryIdentifier}
* and {@code dimensionId}.
*
* @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
*/
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;
}
public static DimensionData decodeBaseCompoundTag(CompoundTag details, ProtocolVersion version) {
boolean isNatural = details.getBoolean("natural");
float ambientLight = details.getFloat("ambient_light");
boolean isShrunk = details.getBoolean("shrunk");
@ -180,16 +194,38 @@ public final class DimensionData {
int logicalHeight = details.getInt("logical_height");
String burningBehaviourIdentifier = details.getString("infiniburn");
Long fixedTime = details.contains("fixed_time")
? details.getLong("fixed_time") : null;
? details.getLong("fixed_time") : null;
Boolean hasEnderdragonFight = details.contains("has_enderdragon_fight")
? details.getBoolean("has_enderdragon_fight") : null;
? details.getBoolean("has_enderdragon_fight") : null;
Double coordinateScale = details.contains("coordinate_scale")
? details.getDouble("coordinate_scale") : null;
return new DimensionData(
registryIdentifier, dimensionId, isNatural, ambientLight, isShrunk,
isUltrawarm, hasCeiling, hasSkylight, isPiglinSafe, doBedsWork, doRespawnAnchorsWork,
hasRaids, logicalHeight, burningBehaviourIdentifier, fixedTime, hasEnderdragonFight,
coordinateScale);
UNKNOWN_DIMENSION_ID, null, isNatural, ambientLight, isShrunk,
isUltrawarm, hasCeiling, hasSkylight, isPiglinSafe, doBedsWork, doRespawnAnchorsWork,
hasRaids, logicalHeight, burningBehaviourIdentifier, fixedTime, hasEnderdragonFight,
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);
}
/**
@ -215,7 +251,7 @@ public final class DimensionData {
}
}
private CompoundTag serializeDimensionDetails() {
public CompoundTag serializeDimensionDetails() {
CompoundTag ret = new CompoundTag();
ret.putBoolean("natural", isNatural);
ret.putFloat("ambient_light", ambientLight);

Datei anzeigen

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

Datei anzeigen

@ -97,7 +97,7 @@ public final class DimensionRegistry {
ImmutableSet.Builder<DimensionData> mappings = ImmutableSet.builder();
for (Tag iter : toParse) {
if (iter instanceof CompoundTag) {
mappings.add(DimensionData.decodeCompoundTag((CompoundTag) iter, version));
mappings.add(DimensionData.decodeRegistryEntry((CompoundTag) iter, version));
}
}
return mappings.build();

Datei anzeigen

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

Datei anzeigen

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