From 824ae0a25bf6bcdb9124234c80d4a14bbca69593 Mon Sep 17 00:00:00 2001 From: Matt Worzala <35708499+mworzala@users.noreply.github.com> Date: Tue, 4 Jul 2023 18:02:13 -0400 Subject: [PATCH] Fix slow dimension changes (#1892) * only send spawn point on dimension change --- src/main/java/net/minestom/server/entity/Player.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index 5149b5e91..33f4fe1d6 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -489,6 +489,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable, * Sends necessary packets to synchronize player data after a {@link RespawnPacket} */ private void refreshClientStateAfterRespawn() { + sendPacket(new ServerDifficultyPacket(MinecraftServer.getDifficulty(), false)); sendPacket(new UpdateHealthPacket(this.getHealth(), food, foodSaturation)); sendPacket(new SetExperiencePacket(exp, level, 0)); triggerStatus((byte) (24 + permissionLevel)); // Set permission level @@ -653,7 +654,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable, */ private void spawnPlayer(@NotNull Instance instance, @NotNull Pos spawnPosition, boolean firstSpawn, boolean dimensionChange, boolean updateChunks) { - if (!firstSpawn) { + if (!firstSpawn && !dimensionChange) { // Player instance changed, clear current viewable collections if (updateChunks) ChunkUtils.forChunksInRange(spawnPosition, MinecraftServer.getChunkViewDistance(), chunkRemover); @@ -674,8 +675,15 @@ public class Player extends LivingEntity implements CommandSender, Localizable, synchronizePosition(true); // So the player doesn't get stuck + if (dimensionChange) { + sendPacket(new SpawnPositionPacket(spawnPosition, 0)); // Without this the client gets stuck on loading terrain for a while + instance.getWorldBorder().init(this); + sendPacket(new TimeUpdatePacket(instance.getWorldAge(), instance.getTime())); + } + if (dimensionChange || firstSpawn) { this.inventory.update(); + sendPacket(new HeldItemChangePacket(heldSlot)); } EventDispatcher.call(new PlayerSpawnEvent(this, instance, firstSpawn));