Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-06 00:00:47 +01:00
DRY - one function to create respawn packets from JoinGame packets
Dieser Commit ist enthalten in:
Ursprung
c45597c885
Commit
c2b237f196
@ -525,7 +525,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
// Most notably, by having the client accept the join game packet, we can work around the need
|
// 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
|
// to perform entity ID rewrites, eliminating potential issues from rewriting packets and
|
||||||
// improving compatibility with mods.
|
// improving compatibility with mods.
|
||||||
int sentOldDim = joinGame.getDimension();
|
final Respawn respawn = Respawn.fromJoinGame(joinGame);
|
||||||
|
|
||||||
if (player.getProtocolVersion().compareTo(MINECRAFT_1_16) < 0) {
|
if (player.getProtocolVersion().compareTo(MINECRAFT_1_16) < 0) {
|
||||||
// Before Minecraft 1.16, we could not switch to the same dimension without sending an
|
// Before Minecraft 1.16, we could not switch to the same dimension without sending an
|
||||||
// additional respawn. On older versions of Minecraft this forces the client to perform
|
// additional respawn. On older versions of Minecraft this forces the client to perform
|
||||||
@ -533,12 +534,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
joinGame.setDimension(joinGame.getDimension() == 0 ? -1 : 0);
|
joinGame.setDimension(joinGame.getDimension() == 0 ? -1 : 0);
|
||||||
}
|
}
|
||||||
player.getConnection().delayedWrite(joinGame);
|
player.getConnection().delayedWrite(joinGame);
|
||||||
|
player.getConnection().delayedWrite(respawn);
|
||||||
player.getConnection().delayedWrite(
|
|
||||||
new Respawn(sentOldDim, joinGame.getPartialHashedSeed(),
|
|
||||||
joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(),
|
|
||||||
false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode(),
|
|
||||||
joinGame.getCurrentDimensionData(), joinGame.getLastDeathPosition()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doSafeClientServerSwitch(JoinGame joinGame) {
|
private void doSafeClientServerSwitch(JoinGame joinGame) {
|
||||||
@ -550,19 +546,13 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
player.getConnection().delayedWrite(joinGame);
|
player.getConnection().delayedWrite(joinGame);
|
||||||
|
|
||||||
// Send a respawn packet in a different dimension.
|
// Send a respawn packet in a different dimension.
|
||||||
int tempDim = joinGame.getDimension() == 0 ? -1 : 0;
|
final Respawn fakeSwitchPacket = Respawn.fromJoinGame(joinGame);
|
||||||
player.getConnection().delayedWrite(
|
fakeSwitchPacket.setDimension(joinGame.getDimension() == 0 ? -1 : 0);
|
||||||
new Respawn(tempDim, joinGame.getPartialHashedSeed(), joinGame.getDifficulty(),
|
player.getConnection().delayedWrite(fakeSwitchPacket);
|
||||||
joinGame.getGamemode(), joinGame.getLevelType(),
|
|
||||||
false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode(),
|
|
||||||
joinGame.getCurrentDimensionData(), joinGame.getLastDeathPosition()));
|
|
||||||
|
|
||||||
// Now send a respawn packet in the correct dimension.
|
// Now send a respawn packet in the correct dimension.
|
||||||
player.getConnection().delayedWrite(
|
final Respawn correctSwitchPacket = Respawn.fromJoinGame(joinGame);
|
||||||
new Respawn(joinGame.getDimension(), joinGame.getPartialHashedSeed(),
|
player.getConnection().delayedWrite(correctSwitchPacket);
|
||||||
joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(),
|
|
||||||
false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode(),
|
|
||||||
joinGame.getCurrentDimensionData(), joinGame.getLastDeathPosition()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UUID> getServerBossBars() {
|
public List<UUID> getServerBossBars() {
|
||||||
|
@ -60,6 +60,13 @@ public class Respawn implements MinecraftPacket {
|
|||||||
this.lastDeathPosition = lastDeathPosition;
|
this.lastDeathPosition = lastDeathPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Respawn fromJoinGame(JoinGame joinGame) {
|
||||||
|
return new Respawn(joinGame.getDimension(), joinGame.getPartialHashedSeed(),
|
||||||
|
joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(),
|
||||||
|
false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode(),
|
||||||
|
joinGame.getCurrentDimensionData(), joinGame.getLastDeathPosition());
|
||||||
|
}
|
||||||
|
|
||||||
public int getDimension() {
|
public int getDimension() {
|
||||||
return dimension;
|
return dimension;
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren