Do not send all chunks on logging, wait for the settings packet instead

This commit is contained in:
themode 2021-03-09 07:08:35 +01:00
parent 7241dbdcf7
commit 6a0582a950

View File

@ -709,10 +709,7 @@ public class Player extends LivingEntity implements CommandSender {
teleport(spawnPosition);
} else if (updateChunks) {
// Send newly visible chunks to player once spawned in the instance
final Chunk chunk = getChunk();
if (chunk != null) {
refreshVisibleChunks(chunk);
}
refreshVisibleChunks();
}
if (dimensionChange || firstSpawn) {
@ -1549,6 +1546,13 @@ public class Player extends LivingEntity implements CommandSender {
}
}
public void refreshVisibleChunks() {
final Chunk chunk = getChunk();
if (chunk != null) {
refreshVisibleChunks(chunk);
}
}
/**
* Refreshes the list of entities that the player should be able to see based on {@link MinecraftServer#getEntityViewDistance()}
* and {@link Entity#isAutoViewable()}.
@ -2325,7 +2329,11 @@ public class Player extends LivingEntity implements CommandSender {
final int serverRange = MinecraftServer.getChunkViewDistance();
final int playerRange = getSettings().viewDistance;
if (playerRange == 0) {
return serverRange; // Didn't receive settings packet yet (is the case on login)
// Didn't receive settings packet yet (is the case on login)
// In this case we send the smallest amount of chunks possible
// Will be updated in PlayerSettings#refresh.
// Non-compliant clients might also be stuck with this view
return 1;
} else {
return Math.min(playerRange, serverRange);
}
@ -2585,7 +2593,7 @@ public class Player extends LivingEntity implements CommandSender {
public void refresh(String locale, byte viewDistance, ChatMode chatMode, boolean chatColors,
byte displayedSkinParts, MainHand mainHand) {
final boolean viewDistanceChanged = !firstRefresh && this.viewDistance != viewDistance;
final boolean viewDistanceChanged = this.viewDistance != viewDistance;
this.locale = locale;
this.viewDistance = viewDistance;
@ -2600,10 +2608,7 @@ public class Player extends LivingEntity implements CommandSender {
// Client changed his view distance in the settings
if (viewDistanceChanged) {
final Chunk playerChunk = getChunk();
if (playerChunk != null) {
refreshVisibleChunks(playerChunk);
}
refreshVisibleChunks();
}
}