3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-12-24 15:20:35 +01:00

Merge from indev: 1.16-pre2

From indev: 1.16-pre2
Dieser Commit ist enthalten in:
FivePB (Xer) 2020-06-05 16:02:05 +02:00 committet von GitHub
Commit a213429735
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
10 geänderte Dateien mit 428 neuen und 115 gelöschten Zeilen

Datei anzeigen

@ -35,7 +35,7 @@ public enum ProtocolVersion {
MINECRAFT_1_15(573, "1.15"),
MINECRAFT_1_15_1(575, "1.15.1"),
MINECRAFT_1_15_2(578, "1.15.2"),
MINECRAFT_1_16(718, "1.16");
MINECRAFT_1_16(722, "1.16");
private final int protocol;
private final String name;

Datei anzeigen

@ -12,7 +12,6 @@ import static com.velocitypowered.proxy.network.Connections.READ_TIMEOUT;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.ConnectionRequestBuilder;
import com.velocitypowered.api.proxy.ServerConnection;
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
import com.velocitypowered.api.proxy.server.ServerInfo;
@ -23,6 +22,7 @@ import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl;
import com.velocitypowered.proxy.connection.registry.DimensionRegistry;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder;
@ -53,6 +53,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
private BackendConnectionPhase connectionPhase = BackendConnectionPhases.UNKNOWN;
private long lastPingId;
private long lastPingSent;
private @Nullable DimensionRegistry activeDimensionRegistry;
/**
* Initializes a new server connection.
@ -297,4 +298,11 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
return hasCompletedJoin;
}
public DimensionRegistry getActiveDimensionRegistry() {
return activeDimensionRegistry;
}
public void setActiveDimensionRegistry(DimensionRegistry activeDimensionRegistry) {
this.activeDimensionRegistry = activeDimensionRegistry;
}
}

Datei anzeigen

@ -32,11 +32,9 @@ import io.netty.buffer.ByteBuf;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Queue;
import java.util.Set;
import java.util.UUID;
import net.kyori.text.TextComponent;
import net.kyori.text.format.TextColor;
@ -313,8 +311,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
if (!spawned) {
// Nothing special to do with regards to spawning the player
spawned = true;
destination.setActiveDimensionRegistry(joinGame.getDimensionRegistry()); // 1.16
player.getMinecraftConnection().delayedWrite(joinGame);
// Required for Legacy Forge
player.getPhase().onFirstJoin(player);
} else {
@ -334,20 +332,22 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
// to perform entity ID rewrites, eliminating potential issues from rewriting packets and
// improving compatibility with mods.
player.getMinecraftConnection().delayedWrite(joinGame);
// Since 1.16 this dynamic changed:
// We don't need to send two dimension swiches anymore!
if (player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_16) < 0) {
int tempDim = joinGame.getDimension() == 0 ? -1 : 0;
player.getMinecraftConnection().delayedWrite(
new Respawn(tempDim, joinGame.getPartialHashedSeed(), joinGame.getDifficulty(),
joinGame.getGamemode(), joinGame.getLevelType(),
joinGame.getShouldKeepPlayerData(),
joinGame.getIsDebug(), joinGame.getIsFlat(),
joinGame.getDimensionRegistryName()));
false, joinGame.getDimensionInfo()));
}
player.getMinecraftConnection().delayedWrite(
new Respawn(joinGame.getDimension(), joinGame.getPartialHashedSeed(),
joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(),
joinGame.getShouldKeepPlayerData(), joinGame.getIsDebug(), joinGame.getIsFlat(),
joinGame.getDimensionRegistryName()));
false, joinGame.getDimensionInfo()));
destination.setActiveDimensionRegistry(joinGame.getDimensionRegistry()); // 1.16
}
// Remove previous boss bars. These don't get cleared when sending JoinGame, thus the need to

Datei anzeigen

@ -0,0 +1,129 @@
package com.velocitypowered.proxy.connection.registry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.kyori.nbt.CompoundTag;
public class DimensionData {
private final @Nonnull String registryIdentifier;
private final boolean isNatural;
private final float ambientLight;
private final boolean isShrunk;
private final boolean isUltrawarm;
private final boolean hasCeiling;
private final boolean hasSkylight;
private final @Nullable Long fixedTime;
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,
float ambientLight, boolean isShrunk, boolean isUltrawarm,
boolean hasCeiling, boolean hasSkylight,
@Nullable Long fixedTime, @Nullable Boolean hasEnderdragonFight) {
this.registryIdentifier = registryIdentifier;
this.isNatural = isNatural;
this.ambientLight = ambientLight;
this.isShrunk = isShrunk;
this.isUltrawarm = isUltrawarm;
this.hasCeiling = hasCeiling;
this.hasSkylight = hasSkylight;
this.fixedTime = fixedTime;
this.hasEnderdragonFight = hasEnderdragonFight;
}
public @Nonnull String getRegistryIdentifier() {
return registryIdentifier;
}
public boolean isNatural() {
return isNatural;
}
public float getAmbientLight() {
return ambientLight;
}
public boolean isShrunk() {
return isShrunk;
}
public boolean isUltrawarm() {
return isUltrawarm;
}
public boolean isHasCeiling() {
return hasCeiling;
}
public boolean isHasSkylight() {
return hasSkylight;
}
public @Nullable Long getFixedTime() {
return fixedTime;
}
public @Nullable Boolean getHasEnderdragonFight() {
return hasEnderdragonFight;
}
/**
* 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) {
throw new IllegalArgumentException("CompoundTag cannot be null");
}
String registryIdentifier = toRead.getString("key");
CompoundTag values = toRead.getCompound("element");
boolean isNatural = values.getBoolean("natural");
float ambientLight = values.getFloat("ambient_light");
boolean isShrunk = values.getBoolean("shrunk");
boolean isUltrawarm = values.getBoolean("ultrawarm");
boolean hasCeiling = values.getBoolean("has_ceiling");
boolean hasSkylight = values.getBoolean("has_skylight");
Long fixedTime = values.contains("fixed_time") ? values.getLong("fixed_time") : null;
Boolean hasEnderdragonFight = values.contains("has_enderdragon_fight")
? values.getBoolean("has_enderdragon_fight") : null;
return new DimensionData(
registryIdentifier, isNatural, ambientLight, isShrunk,
isUltrawarm, hasCeiling, hasSkylight, fixedTime, hasEnderdragonFight);
}
/**
* Encodes the Dimension data as CompoundTag.
* @return compound containing the dimension data
*/
public CompoundTag encodeAsCompundTag() {
CompoundTag ret = new CompoundTag();
ret.putString("key", registryIdentifier);
CompoundTag values = new CompoundTag();
values.putBoolean("natural", isNatural);
values.putFloat("ambient_light", ambientLight);
values.putBoolean("shrunk", isShrunk);
values.putBoolean("ultrawarm", isUltrawarm);
values.putBoolean("has_ceiling", hasCeiling);
values.putBoolean("has_skylight", hasSkylight);
if (fixedTime != null) {
values.putLong("fixed_time", fixedTime);
}
if (hasEnderdragonFight != null) {
values.putBoolean("has_enderdragon_fight", hasEnderdragonFight);
}
ret.put("element", values);
return ret;
}
}

Datei anzeigen

@ -0,0 +1,50 @@
package com.velocitypowered.proxy.connection.registry;
import javax.annotation.Nonnull;
public class DimensionInfo {
private final @Nonnull String registryIdentifier;
private final @Nonnull String levelName;
private final boolean isFlat;
private final boolean isDebugType;
/**
* Initializes a new {@link DimensionInfo} instance.
* @param registryIdentifier the identifier for the dimension from the registry
* @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 isDebugType if true constrains the world to the very limited debug-type world
*/
public DimensionInfo(@Nonnull String registryIdentifier, @Nonnull String levelName,
boolean isFlat, boolean isDebugType) {
if (registryIdentifier == null || registryIdentifier.isEmpty()
|| registryIdentifier.isBlank()) {
throw new IllegalArgumentException("Dimension registry identifier may not be empty or null");
}
this.registryIdentifier = registryIdentifier;
if (levelName == null || levelName.isEmpty()
|| levelName.isBlank()) {
throw new IllegalArgumentException("dimensions level name may not be empty or null");
}
this.levelName = levelName;
this.isFlat = isFlat;
this.isDebugType = isDebugType;
}
public boolean isDebugType() {
return isDebugType;
}
public boolean isFlat() {
return isFlat;
}
public @Nonnull String getLevelName() {
return levelName;
}
public @Nonnull String getRegistryIdentifier() {
return registryIdentifier;
}
}

Datei anzeigen

@ -0,0 +1,128 @@
package com.velocitypowered.proxy.connection.registry;
import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.Set;
import javax.annotation.Nonnull;
import net.kyori.nbt.CompoundTag;
import net.kyori.nbt.ListTag;
import net.kyori.nbt.Tag;
import net.kyori.nbt.TagType;
public class DimensionRegistry {
private final @Nonnull Set<DimensionData> dimensionRegistry;
private final @Nonnull String[] levelNames;
/**
* Initializes a new {@link DimensionRegistry} instance.
* This registry is required for 1.16+ clients/servers to communicate,
* it constrains the dimension types and names the client can be sent
* in a Respawn action (dimension change).
* @param dimensionRegistry a populated set containing dimension data types
* @param levelNames a populated {@link Set} of the dimension level names the server offers
*/
public DimensionRegistry(Set<DimensionData> dimensionRegistry,
String[] levelNames) {
if (dimensionRegistry == null || dimensionRegistry.isEmpty()
|| levelNames == null || levelNames.length == 0) {
throw new IllegalArgumentException(
"Dimension registry requires valid arguments, not null and not empty");
}
this.dimensionRegistry = dimensionRegistry;
this.levelNames = levelNames;
}
public @Nonnull Set<DimensionData> getDimensionRegistry() {
return dimensionRegistry;
}
public @Nonnull String[] getLevelNames() {
return levelNames;
}
/**
* Returns the internal dimension data type as used by the game.
* @param dimensionIdentifier how the dimension is identified by the connection
* @return game dimension data
*/
public @Nonnull DimensionData getDimensionData(@Nonnull String dimensionIdentifier) {
if (dimensionIdentifier == null) {
throw new IllegalArgumentException("Dimension identifier cannot be null!");
}
for (DimensionData iter : dimensionRegistry) {
if (iter.getRegistryIdentifier().equals(dimensionIdentifier)) {
return iter;
}
}
throw new NoSuchElementException("Dimension with identifier " + dimensionIdentifier
+ " doesn't exist in this Registry!");
}
/**
* Checks a {@link DimensionInfo} against this registry.
* @param toValidate the {@link DimensionInfo} to validate
* @return true: the dimension information is valid for this registry
*/
public boolean isValidFor(@Nonnull DimensionInfo toValidate) {
if (toValidate == null) {
throw new IllegalArgumentException("Dimension info cannot be null");
}
try {
getDimensionData(toValidate.getRegistryIdentifier());
for (int i = 0; i < levelNames.length; i++) {
if (levelNames[i].equals(toValidate.getRegistryIdentifier())) {
return true;
}
}
return false;
} catch (NoSuchElementException thrown) {
return false;
}
}
/**
* Encodes the stored Dimension registry as CompoundTag.
* @return the CompoundTag containing identifier:type mappings
*/
public CompoundTag encodeRegistry() {
CompoundTag ret = new CompoundTag();
ListTag list = new ListTag(TagType.COMPOUND);
for (DimensionData iter : dimensionRegistry) {
list.add(iter.encodeAsCompundTag());
}
ret.put("dimension", list);
return ret;
}
/**
* Decodes a CompoundTag storing a dimension registry.
* @param toParse CompoundTag containing a dimension registry
* @param levelNames world level names
*/
public static DimensionRegistry fromGameData(
@Nonnull CompoundTag toParse, @Nonnull String[] levelNames) {
if (toParse == null) {
throw new IllegalArgumentException("CompoundTag cannot be null");
}
if (levelNames == null || levelNames.length == 0) {
throw new IllegalArgumentException("Level names cannot be null or empty");
}
if (!toParse.contains("dimension", TagType.LIST)) {
throw new IllegalStateException("CompoundTag does not contain a dimension List");
}
ListTag dimensions = toParse.getList("dimension");
Set<DimensionData> mappings = new HashSet<DimensionData>();
for (Tag iter : dimensions) {
if (!(iter instanceof CompoundTag)) {
throw new IllegalStateException("DimensionList in CompoundTag contains an invalid entry");
}
mappings.add(DimensionData.fromCompoundTag((CompoundTag) iter));
}
if (mappings.isEmpty()) {
throw new IllegalStateException("Dimension mapping cannot be empty");
}
return new DimensionRegistry(mappings, levelNames);
}
}

Datei anzeigen

@ -21,6 +21,7 @@ import java.util.List;
import java.util.UUID;
import net.kyori.nbt.CompoundTag;
import net.kyori.nbt.TagType;
public enum ProtocolUtils {
;
@ -204,7 +205,7 @@ public enum ProtocolUtils {
try {
DataInput input = new ByteBufInputStream(buf);
byte type = input.readByte();
if (type != 10) {
if (type != TagType.COMPOUND.id()) {
throw new DecoderException("NBTTag is not a CompoundTag");
}
input.readUTF(); // Head-padding
@ -236,6 +237,36 @@ public enum ProtocolUtils {
}
}
/**
* Reads a String array from the {@code buf}.
* @param buf the buffer to read from
* @return the String array from the buffer
*/
public static String[] readStringArray(ByteBuf buf) {
int length = readVarInt(buf);
String[] ret = new String[length];
for (int i = 0; i < length; i++) {
ret[i] = readString(buf);
}
return ret;
}
/**
* Writes a String Array to the {@code buf}.
* @param buf the buffer to write to
* @param stringArray the array to write
*/
public static void writeStringArray(ByteBuf buf, String[] stringArray) {
if (stringArray == null) {
writeVarInt(buf, 0);
return;
}
writeVarInt(buf, stringArray.length);
for (int i = 0; i < stringArray.length; i++) {
writeString(buf, stringArray[i]);
}
}
/**
* Writes a list of {@link com.velocitypowered.api.util.GameProfile.Property} to the buffer.
* @param buf the buffer to write to

Datei anzeigen

@ -126,44 +126,52 @@ public enum StateRegistry {
clientbound.register(BossBar.class, BossBar::new,
map(0x0C, MINECRAFT_1_9, false),
map(0x0D, MINECRAFT_1_15, false));
map(0x0D, MINECRAFT_1_15, false),
map(0x0C, MINECRAFT_1_16, false));
clientbound.register(Chat.class, Chat::new,
map(0x02, MINECRAFT_1_8, true),
map(0x0F, MINECRAFT_1_9, true),
map(0x0E, MINECRAFT_1_13, true),
map(0x0F, MINECRAFT_1_15, true));
map(0x0F, MINECRAFT_1_15, true),
map(0x0E, MINECRAFT_1_16, true));
clientbound.register(TabCompleteResponse.class, TabCompleteResponse::new,
map(0x3A, MINECRAFT_1_8, false),
map(0x0E, MINECRAFT_1_9, false),
map(0x10, MINECRAFT_1_13, false),
map(0x11, MINECRAFT_1_15, false));
map(0x11, MINECRAFT_1_15, false),
map(0x10, MINECRAFT_1_16, false));
clientbound.register(AvailableCommands.class, AvailableCommands::new,
map(0x11, MINECRAFT_1_13, false),
map(0x12, MINECRAFT_1_15, false));
map(0x12, MINECRAFT_1_15, false),
map(0x11, MINECRAFT_1_16, false));
clientbound.register(PluginMessage.class, PluginMessage::new,
map(0x3F, MINECRAFT_1_8, false),
map(0x18, MINECRAFT_1_9, false),
map(0x19, MINECRAFT_1_13, false),
map(0x18, MINECRAFT_1_14, false),
map(0x19, MINECRAFT_1_15, false));
map(0x19, MINECRAFT_1_15, false),
map(0x18, MINECRAFT_1_16, false));
clientbound.register(Disconnect.class, Disconnect::new,
map(0x40, MINECRAFT_1_8, false),
map(0x1A, MINECRAFT_1_9, false),
map(0x1B, MINECRAFT_1_13, false),
map(0x1A, MINECRAFT_1_14, false),
map(0x1B, MINECRAFT_1_15, false));
map(0x1B, MINECRAFT_1_15, false),
map(0x1A, MINECRAFT_1_16, false));
clientbound.register(KeepAlive.class, KeepAlive::new,
map(0x00, MINECRAFT_1_8, false),
map(0x1F, MINECRAFT_1_9, false),
map(0x21, MINECRAFT_1_13, false),
map(0x20, MINECRAFT_1_14, false),
map(0x21, MINECRAFT_1_15, false));
map(0x21, MINECRAFT_1_15, false),
map(0x20, MINECRAFT_1_16, false));
clientbound.register(JoinGame.class, JoinGame::new,
map(0x01, MINECRAFT_1_8, false),
map(0x23, MINECRAFT_1_9, false),
map(0x25, MINECRAFT_1_13, false),
map(0x25, MINECRAFT_1_14, false),
map(0x26, MINECRAFT_1_15, false));
map(0x26, MINECRAFT_1_15, false),
map(0x25, MINECRAFT_1_16, false));
clientbound.register(Respawn.class, Respawn::new,
map(0x07, MINECRAFT_1_8, true),
map(0x33, MINECRAFT_1_9, true),
@ -171,7 +179,8 @@ public enum StateRegistry {
map(0x35, MINECRAFT_1_12_1, true),
map(0x38, MINECRAFT_1_13, true),
map(0x3A, MINECRAFT_1_14, true),
map(0x3B, MINECRAFT_1_15, true));
map(0x3B, MINECRAFT_1_15, true),
map(0x3A, MINECRAFT_1_16, true));
clientbound.register(ResourcePackRequest.class, ResourcePackRequest::new,
map(0x48, MINECRAFT_1_8, true),
map(0x32, MINECRAFT_1_9, true),
@ -179,7 +188,8 @@ public enum StateRegistry {
map(0x34, MINECRAFT_1_12_1, true),
map(0x37, MINECRAFT_1_13, true),
map(0x39, MINECRAFT_1_14, true),
map(0x3A, MINECRAFT_1_15, true));
map(0x3A, MINECRAFT_1_15, true),
map(0x39, MINECRAFT_1_16, true));
clientbound.register(HeaderAndFooter.class, HeaderAndFooter::new,
map(0x47, MINECRAFT_1_8, true),
map(0x48, MINECRAFT_1_9, true),
@ -188,7 +198,8 @@ public enum StateRegistry {
map(0x4A, MINECRAFT_1_12_1, true),
map(0x4E, MINECRAFT_1_13, true),
map(0x53, MINECRAFT_1_14, true),
map(0x54, MINECRAFT_1_15, true));
map(0x54, MINECRAFT_1_15, true),
map(0x53, MINECRAFT_1_16, true));
clientbound.register(TitlePacket.class, TitlePacket::new,
map(0x45, MINECRAFT_1_8, true),
map(0x45, MINECRAFT_1_9, true),
@ -196,14 +207,16 @@ public enum StateRegistry {
map(0x48, MINECRAFT_1_12_1, true),
map(0x4B, MINECRAFT_1_13, true),
map(0x4F, MINECRAFT_1_14, true),
map(0x50, MINECRAFT_1_15, true));
map(0x50, MINECRAFT_1_15, true),
map(0x4F, MINECRAFT_1_16, true));
clientbound.register(PlayerListItem.class, PlayerListItem::new,
map(0x38, MINECRAFT_1_8, false),
map(0x2D, MINECRAFT_1_9, false),
map(0x2E, MINECRAFT_1_12_1, false),
map(0x30, MINECRAFT_1_13, false),
map(0x33, MINECRAFT_1_14, false),
map(0x34, MINECRAFT_1_15, false));
map(0x34, MINECRAFT_1_15, false),
map(0x33, MINECRAFT_1_16, false));
}
},
LOGIN {

Datei anzeigen

@ -2,10 +2,10 @@ package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.connection.registry.DimensionInfo;
import com.velocitypowered.proxy.connection.registry.DimensionRegistry;
import com.velocitypowered.proxy.protocol.*;
import io.netty.buffer.ByteBuf;
import net.kyori.nbt.CompoundTag;
import org.checkerframework.checker.nullness.qual.Nullable;
public class JoinGame implements MinecraftPacket {
@ -20,11 +20,8 @@ public class JoinGame implements MinecraftPacket {
private int viewDistance; // 1.14+
private boolean reducedDebugInfo;
private boolean showRespawnScreen;
private boolean shouldKeepPlayerData; // 1.16+
private boolean isDebug; // 1.16+
private boolean isFlat; // 1.16+
private String dimensionRegistryName; // 1.16+
private CompoundTag dimensionRegistry; // 1.16+
private DimensionRegistry dimensionRegistry; // 1.16+
private DimensionInfo dimensionInfo; // 1.16+
public int getEntityId() {
return entityId;
@ -97,43 +94,19 @@ public class JoinGame implements MinecraftPacket {
this.reducedDebugInfo = reducedDebugInfo;
}
public boolean getShouldKeepPlayerData() {
return shouldKeepPlayerData;
public DimensionInfo getDimensionInfo() {
return dimensionInfo;
}
public void setShouldKeepPlayerData(boolean shouldKeepPlayerData) {
this.shouldKeepPlayerData = shouldKeepPlayerData;
public void setDimensionInfo(DimensionInfo dimensionInfo) {
this.dimensionInfo = dimensionInfo;
}
public boolean getIsDebug() {
return isDebug;
}
public void setIsDebug(boolean isDebug) {
this.isDebug = isDebug;
}
public boolean getIsFlat() {
return isFlat;
}
public void setIsFlat(boolean isFlat) {
this.isFlat = isFlat;
}
public String getDimensionRegistryName() {
return dimensionRegistryName;
}
public void setDimensionRegistryName(String dimensionRegistryName) {
this.dimensionRegistryName = dimensionRegistryName;
}
public CompoundTag getDimensionRegistry() {
public DimensionRegistry getDimensionRegistry() {
return dimensionRegistry;
}
public void setDimensionRegistry(CompoundTag dimensionRegistry) {
public void setDimensionRegistry(DimensionRegistry dimensionRegistry) {
this.dimensionRegistry = dimensionRegistry;
}
@ -149,10 +122,8 @@ public class JoinGame implements MinecraftPacket {
+ ", levelType='" + levelType + '\''
+ ", viewDistance=" + viewDistance
+ ", reducedDebugInfo=" + reducedDebugInfo
+ ", shouldKeepPlayerData=" + shouldKeepPlayerData
+ ", isDebug=" + isDebug
+ ", isFlat='" + isFlat
+ ", dimensionRegistryName='" + dimensionRegistryName + '\''
+ ", dimensionRegistry='" + dimensionRegistry.toString() + '\''
+ ", dimensionInfo='" + dimensionInfo.toString() + '\''
+ '}';
}
@ -160,9 +131,13 @@ public class JoinGame implements MinecraftPacket {
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
this.entityId = buf.readInt();
this.gamemode = buf.readUnsignedByte();
String dimensionIdentifier = null;
String levelName = null;
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
this.dimensionRegistry = ProtocolUtils.readCompoundTag(buf);
this.dimensionRegistryName = ProtocolUtils.readString(buf);
String levelNames[] = ProtocolUtils.readStringArray(buf);
this.dimensionRegistry = DimensionRegistry.fromGameData(ProtocolUtils.readCompoundTag(buf), levelNames);
dimensionIdentifier = ProtocolUtils.readString(buf);
levelName = ProtocolUtils.readString(buf);
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) {
this.dimension = buf.readInt();
} else {
@ -188,8 +163,9 @@ public class JoinGame implements MinecraftPacket {
this.showRespawnScreen = buf.readBoolean();
}
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
isDebug = buf.readBoolean();
isFlat = buf.readBoolean();
boolean isDebug = buf.readBoolean();
boolean isFlat = buf.readBoolean();
this.dimensionInfo = new DimensionInfo(dimensionIdentifier, levelName, isFlat, isDebug);
}
}
@ -198,8 +174,10 @@ public class JoinGame implements MinecraftPacket {
buf.writeInt(entityId);
buf.writeByte(gamemode);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
ProtocolUtils.writeCompoundTag(buf, dimensionRegistry);
ProtocolUtils.writeString(buf, dimensionRegistryName);
ProtocolUtils.writeStringArray(buf, dimensionRegistry.getLevelNames());
ProtocolUtils.writeCompoundTag(buf, dimensionRegistry.encodeRegistry());
ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier());
ProtocolUtils.writeString(buf, dimensionInfo.getLevelName());
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) {
buf.writeInt(dimension);
} else {
@ -226,8 +204,8 @@ public class JoinGame implements MinecraftPacket {
buf.writeBoolean(showRespawnScreen);
}
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
buf.writeBoolean(isDebug);
buf.writeBoolean(isFlat);
buf.writeBoolean(dimensionInfo.isDebugType());
buf.writeBoolean(dimensionInfo.isFlat());
}
}

Datei anzeigen

@ -2,6 +2,7 @@ package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.connection.registry.DimensionInfo;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf;
@ -14,24 +15,20 @@ public class Respawn implements MinecraftPacket {
private short gamemode;
private String levelType = "";
private boolean shouldKeepPlayerData; // 1.16+
private boolean isDebug; // 1.16+
private boolean isFlat; // 1.16+
private String dimensionRegistryName; // 1.16+
private DimensionInfo dimensionInfo;
public Respawn() {
}
public Respawn(int dimension, long partialHashedSeed, short difficulty, short gamemode,
String levelType, boolean shouldKeepPlayerData, boolean isDebug, boolean isFlat, String dimensionRegistryName) {
String levelType, boolean shouldKeepPlayerData, DimensionInfo dimensionInfo) {
this.dimension = dimension;
this.partialHashedSeed = partialHashedSeed;
this.difficulty = difficulty;
this.gamemode = gamemode;
this.levelType = levelType;
this.shouldKeepPlayerData = shouldKeepPlayerData;
this.isDebug = isDebug;
this.isFlat = isFlat;
this.dimensionRegistryName = dimensionRegistryName;
this.dimensionInfo = dimensionInfo;
}
public int getDimension() {
@ -82,30 +79,6 @@ public class Respawn implements MinecraftPacket {
this.shouldKeepPlayerData = shouldKeepPlayerData;
}
public boolean getIsDebug() {
return isDebug;
}
public void setIsDebug(boolean isDebug) {
this.isDebug = isDebug;
}
public boolean getIsFlat() {
return isFlat;
}
public void setIsFlat(boolean isFlat) {
this.isFlat = isFlat;
}
public String getDimensionRegistryName() {
return dimensionRegistryName;
}
public void setDimensionRegistryName(String dimensionRegistryName) {
this.dimensionRegistryName = dimensionRegistryName;
}
@Override
public String toString() {
return "Respawn{"
@ -115,16 +88,17 @@ public class Respawn implements MinecraftPacket {
+ ", gamemode=" + gamemode
+ ", levelType='" + levelType + '\''
+ ", shouldKeepPlayerData=" + shouldKeepPlayerData
+ ", isDebug=" + isDebug
+ ", isFlat='" + isFlat
+ ", dimensionRegistryName='" + dimensionRegistryName + '\''
+ ", dimensionRegistryName='" + dimensionInfo.toString() + '\''
+ '}';
}
@Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
String dimensionIdentifier = null;
String levelName = null;
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
this.dimensionRegistryName = ProtocolUtils.readString(buf); // Not sure what the cap on that is
dimensionIdentifier = ProtocolUtils.readString(buf);
levelName = ProtocolUtils.readString(buf);
} else {
this.dimension = buf.readInt();
}
@ -136,9 +110,10 @@ public class Respawn implements MinecraftPacket {
}
this.gamemode = buf.readUnsignedByte();
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
isDebug = buf.readBoolean();
isFlat = buf.readBoolean();
shouldKeepPlayerData = buf.readBoolean();
boolean isDebug = buf.readBoolean();
boolean isFlat = buf.readBoolean();
this.dimensionInfo = new DimensionInfo(dimensionIdentifier, levelName, isFlat, isDebug);
this.shouldKeepPlayerData = buf.readBoolean();
} else {
this.levelType = ProtocolUtils.readString(buf, 16);
}
@ -147,7 +122,8 @@ 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, dimensionRegistryName);
ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier());
ProtocolUtils.writeString(buf, dimensionInfo.getLevelName());
} else {
buf.writeInt(dimension);
}
@ -159,8 +135,8 @@ public class Respawn implements MinecraftPacket {
}
buf.writeByte(gamemode);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
buf.writeBoolean(isDebug);
buf.writeBoolean(isFlat);
buf.writeBoolean(dimensionInfo.isDebugType());
buf.writeBoolean(dimensionInfo.isFlat());
buf.writeBoolean(shouldKeepPlayerData);
} else {
ProtocolUtils.writeString(buf, levelType);