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 e0bf9dc38..9b22408b4 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 @@ -304,25 +304,19 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { // Clear tab list to avoid duplicate entries player.getTabList().clearAll(); - // In order to handle switching to another server, you will need to send three packets: + // In order to handle switching to another server, you will need to send two packets: // - // - The join game packet from the backend server - // - A respawn packet with a different dimension - // - Another respawn with the correct dimension - // - // The two respawns with different dimensions are required, otherwise the client gets - // confused. + // - The join game packet from the backend server, with a different dimension + // - A respawn with the correct dimension // // Most notably, by having the client accept the join game packet, we can work around the need // to perform entity ID rewrites, eliminating potential issues from rewriting packets and // improving compatibility with mods. + int realDim = joinGame.getDimension(); + joinGame.setDimension(getFakeTemporaryDimensionId(realDim)); player.getConnection().delayedWrite(joinGame); - int tempDim = joinGame.getDimension() == 0 ? -1 : 0; player.getConnection().delayedWrite( - new Respawn(tempDim, joinGame.getDifficulty(), joinGame.getGamemode(), - joinGame.getLevelType())); - player.getConnection().delayedWrite( - new Respawn(joinGame.getDimension(), joinGame.getDifficulty(), joinGame.getGamemode(), + new Respawn(realDim, joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType())); } @@ -360,11 +354,14 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { destination.completeJoin(); } + private static int getFakeTemporaryDimensionId(int dim) { + return dim == 0 ? -1 : 0; + } + public List getServerBossBars() { return serverBossBars; } - private boolean handleCommandTabComplete(TabCompleteRequest packet) { // In 1.13+, we need to do additional work for the richer suggestions available. String command = packet.getCommand().substring(1);