Fix slow dimension changes (#1892)

* only send spawn point on dimension change
This commit is contained in:
Matt Worzala 2023-07-04 18:02:13 -04:00 committed by GitHub
parent 954e8b3915
commit 824ae0a25b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -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));