From 18e595397660ea6651bb4c86e1bb3a6addf1dd24 Mon Sep 17 00:00:00 2001 From: Lechner Markus Date: Thu, 4 Jun 2020 15:36:58 +0200 Subject: [PATCH] Save progress --- .../backend/VelocityServerConnection.java | 9 ++ .../client/ClientPlaySessionHandler.java | 55 +++++++-- .../proxy/protocol/DimensionInfo.java | 40 +++++++ .../proxy/protocol/DimensionRegistry.java | 113 ++++++++++++++++++ .../proxy/protocol/ProtocolUtils.java | 33 ++++- .../proxy/protocol/packet/JoinGame.java | 78 +++++------- .../proxy/protocol/packet/Respawn.java | 56 +++------ 7 files changed, 289 insertions(+), 95 deletions(-) create mode 100644 proxy/src/main/java/com/velocitypowered/proxy/protocol/DimensionInfo.java create mode 100644 proxy/src/main/java/com/velocitypowered/proxy/protocol/DimensionRegistry.java diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java index a8b97c028..7d1d5832f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java @@ -23,6 +23,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.protocol.DimensionRegistry; import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; @@ -53,6 +54,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 +299,11 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, return hasCompletedJoin; } + public DimensionRegistry getActiveDimensionRegistry() { + return activeDimensionRegistry; + } + + public void setActiveDimensionRegistry(DimensionRegistry activeDimensionRegistry) { + this.activeDimensionRegistry = activeDimensionRegistry; + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java index d8e3d3718..5a0820cd9 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java @@ -13,6 +13,8 @@ import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.backend.BackendConnectionPhases; import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; +import com.velocitypowered.proxy.protocol.DimensionInfo; +import com.velocitypowered.proxy.protocol.DimensionRegistry; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.packet.BossBar; @@ -313,8 +315,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 +336,59 @@ 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); + int tempDim = joinGame.getDimension() == 0 ? -1 : 0; + // Since 1.16 this dynamic changed: + // The respawn packet has a keepMetadata flag which should + // be true for dimension switches, so by double switching + // we can keep the flow of the game + // There is a problem here though: By only sending one dimension + // in the registry we can't do that, so we need to run an *unclean* switch. + // NOTE! We can't just send a fake dimension in the registry either + // to get two dimensions, as modded games will break with this. + final DimensionRegistry dimensionRegistry = joinGame.getDimensionRegistry(); + DimensionInfo dimensionInfo = joinGame.getDimensionInfo(); // 1.16+ + // The doubleSwitch variable doubles as keepMetadata flag for an unclean switch as + // well as to indicate the second switch. + boolean doubleSwitch; + // This is not ONE if because this will all be null in < 1.16 if (player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_16) < 0) { - int tempDim = joinGame.getDimension() == 0 ? -1 : 0; + if(dimensionRegistry.getWorldNames().size() > 1 && dimensionRegistry.getDimensionRegistry().size() > 1){ + String tmpDimLevelName = null; + for(String s : dimensionRegistry.getWorldNames()){ + if(!s.equals(dimensionInfo.getDimensionLevelName())){ + tmpDimLevelName = s; + break; + } + } + String tmpDimIdentifier = null; + for(String s : dimensionRegistry.getDimensionRegistry().keySet()){ + if(!s.equals(dimensionInfo.getDimensionIdentifier())){ + tmpDimIdentifier = s; + break; + } + } + dimensionInfo = new DimensionInfo(tmpDimIdentifier, tmpDimLevelName, true, false); + doubleSwitch = true; + } else { + doubleSwitch = false; + // We should add a warning here. + } + } else { + doubleSwitch = true; + } + if(doubleSwitch) { player.getMinecraftConnection().delayedWrite( new Respawn(tempDim, joinGame.getPartialHashedSeed(), joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(), - joinGame.getShouldKeepPlayerData(), - joinGame.getIsDebug(), joinGame.getIsFlat(), - joinGame.getDimensionRegistryName())); + false, dimensionInfo)); } + player.getMinecraftConnection().delayedWrite( new Respawn(joinGame.getDimension(), joinGame.getPartialHashedSeed(), joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(), - joinGame.getShouldKeepPlayerData(), joinGame.getIsDebug(), joinGame.getIsFlat(), - joinGame.getDimensionRegistryName())); + doubleSwitch, joinGame.getDimensionInfo())); + + destination.setActiveDimensionRegistry(joinGame.getDimensionRegistry()); // 1.16 } // Remove previous boss bars. These don't get cleared when sending JoinGame, thus the need to diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/DimensionInfo.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/DimensionInfo.java new file mode 100644 index 000000000..3e98da366 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/DimensionInfo.java @@ -0,0 +1,40 @@ +package com.velocitypowered.proxy.protocol; + +import javax.annotation.Nonnull; + +public class DimensionInfo { + + private final @Nonnull String dimensionIdentifier; + private final @Nonnull String dimensionLevelName; + private final boolean isFlat; + private final boolean isDebugType; + + public DimensionInfo(@Nonnull String dimensionIdentifier, @Nonnull String dimensionLevelName, boolean isFlat, boolean isDebugType) { + if(dimensionIdentifier == null || dimensionIdentifier.isEmpty() || dimensionIdentifier.isBlank()) { + throw new IllegalArgumentException("DimensionRegistryName may not be empty or null"); + } + this.dimensionIdentifier = dimensionIdentifier; + if(dimensionLevelName == null || dimensionLevelName.isEmpty() || dimensionLevelName.isBlank()) { + throw new IllegalArgumentException("DimensionLevelName may not be empty or null"); + } + this.dimensionLevelName = dimensionLevelName; + this.isFlat = isFlat; + this.isDebugType = isDebugType; + } + + public boolean isDebugType() { + return isDebugType; + } + + public boolean isFlat() { + return isFlat; + } + + public @Nonnull String getDimensionLevelName() { + return dimensionLevelName; + } + + public @Nonnull String getDimensionIdentifier() { + return dimensionIdentifier; + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/DimensionRegistry.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/DimensionRegistry.java new file mode 100644 index 000000000..d4305f540 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/DimensionRegistry.java @@ -0,0 +1,113 @@ +package com.velocitypowered.proxy.protocol; + +import net.kyori.nbt.CompoundTag; +import net.kyori.nbt.ListTag; +import net.kyori.nbt.Tag; +import net.kyori.nbt.TagType; + +import javax.annotation.Nonnull; +import java.util.*; + +public class DimensionRegistry { + + private final @Nonnull Map dimensionRegistry; + private final @Nonnull Set worldNames; + + public DimensionRegistry(Map dimensionRegistry, Set worldNames) { + if(dimensionRegistry == null || dimensionRegistry.isEmpty() || worldNames == null || worldNames.isEmpty()) { + throw new IllegalArgumentException("DimensionRegistry requires valid arguments, not null and not empty"); + } + this.dimensionRegistry = dimensionRegistry; + this.worldNames = worldNames; + } + + public @Nonnull Map getDimensionRegistry() { + return dimensionRegistry; + } + + public @Nonnull Set getWorldNames() { + return worldNames; + } + + public @Nonnull String getDimensionIdentifier(@Nonnull String dimensionName) { + if (dimensionName == null) { + throw new IllegalArgumentException("DimensionName cannot be null!"); + } + if (dimensionName == null || !dimensionRegistry.containsKey(dimensionName)) { + throw new NoSuchElementException("DimensionName " + dimensionName + " doesn't exist in this Registry!"); + } + return dimensionRegistry.get(dimensionName); + } + + public @Nonnull String getDimensionName(@Nonnull String dimensionIdentifier) { + if (dimensionIdentifier == null) { + throw new IllegalArgumentException("DimensionIdentifier cannot be null!"); + } + for (Map.Entry entry : dimensionRegistry.entrySet()){ + if(entry.getValue().equals(dimensionIdentifier)){ + return entry.getKey(); + } + } + throw new NoSuchElementException("DimensionIdentifier " + dimensionIdentifier + " doesn't exist in this Registry!"); + } + + public boolean isValidFor(@Nonnull DimensionInfo toValidate) { + if(toValidate == null) { + throw new IllegalArgumentException("DimensionInfo cannot be null"); + } + try{ + if (!worldNames.contains(toValidate.getDimensionLevelName())){ + return false; + } + getDimensionName(toValidate.getDimensionIdentifier()); + return true; + + } catch(NoSuchElementException thrown){ + return false; + } + + } + + public CompoundTag encodeToCompoundTag(){ + CompoundTag ret = new CompoundTag(); + ListTag list = new ListTag(TagType.COMPOUND); + for(Map.Entry entry : dimensionRegistry.entrySet()){ + CompoundTag item = new CompoundTag(); + item.putString("key", entry.getKey()); + item.putString("element", entry.getValue()); + list.add(item); + } + ret.put("dimension", list); + return ret; + } + + public static Map parseToMapping(@Nonnull CompoundTag toParse){ + if(toParse == null) { + throw new IllegalArgumentException("CompoundTag cannot be null"); + } + if(!toParse.contains("dimension", TagType.LIST)){ + throw new IllegalStateException("CompoundTag does not contain a dimension List"); + } + ListTag dimensions = toParse.getList("dimension"); + Map mappings = new HashMap(); + for(Tag iter : dimensions){ + if(iter instanceof CompoundTag){ + throw new IllegalStateException("DimensionList in CompoundTag contains an invalid entry"); + } + CompoundTag mapping = (CompoundTag) iter; + String key = mapping.getString("key", null); + String element = mapping.getString("element", null); + if(element == null || key == null){ + throw new IllegalStateException("DimensionList in CompoundTag contains an mapping"); + } + if(mappings.containsKey(key) || mappings.containsValue(element)) { + throw new IllegalStateException("Dimension mappings may not have identifier/name duplicates"); + } + mappings.put(key, element); + } + if(mappings.isEmpty()){ + throw new IllegalStateException("Dimension mapping cannot be empty"); + } + return mappings; + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java index cfedec888..e2b55c544 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java @@ -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 diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java index ef5315701..8ea5cbeb6 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java @@ -2,12 +2,17 @@ package com.velocitypowered.proxy.protocol.packet; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; +import com.velocitypowered.proxy.protocol.DimensionInfo; +import com.velocitypowered.proxy.protocol.DimensionRegistry; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; import net.kyori.nbt.CompoundTag; import org.checkerframework.checker.nullness.qual.Nullable; +import java.util.Map; +import java.util.Set; + public class JoinGame implements MinecraftPacket { private int entityId; @@ -20,11 +25,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 +99,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 +127,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 +136,14 @@ 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); + Map dimensionMapping = DimensionRegistry.parseToMapping(ProtocolUtils.readCompoundTag(buf)); + this.dimensionRegistry = new DimensionRegistry(dimensionMapping, Set.of(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 +169,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 +180,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.getWorldNames().toArray(new String[dimensionRegistry.getWorldNames().size()])); + ProtocolUtils.writeCompoundTag(buf, dimensionRegistry.encodeToCompoundTag()); + ProtocolUtils.writeString(buf, dimensionInfo.getDimensionIdentifier()); + ProtocolUtils.writeString(buf, dimensionInfo.getDimensionLevelName()); } else if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) { buf.writeInt(dimension); } else { @@ -226,8 +210,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()); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java index 0f988a5f9..67fafb7f7 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java @@ -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.protocol.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,8 +110,9 @@ public class Respawn implements MinecraftPacket { } this.gamemode = buf.readUnsignedByte(); 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); 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.getDimensionIdentifier()); + ProtocolUtils.writeString(buf, dimensionInfo.getDimensionLevelName()); } 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);