Merge remote-tracking branch 'Kebab11noel/position-cleanup' into position-cleanup

This commit is contained in:
TheMode 2021-05-10 00:31:29 +02:00
commit 71a6d88338

View File

@ -655,6 +655,8 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
super.setInstance(instance, spawnPosition); super.setInstance(instance, spawnPosition);
refreshVisibleChunks();
if (differentSpawnPos && !firstSpawn) { if (differentSpawnPos && !firstSpawn) {
// Player changed instance at a different position // Player changed instance at a different position
teleport(spawnPosition); teleport(spawnPosition);
@ -1547,27 +1549,25 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
final int[] oldChunks = ArrayUtils.getDifferencesBetweenArray(lastVisibleChunks, updatedVisibleChunks); final int[] oldChunks = ArrayUtils.getDifferencesBetweenArray(lastVisibleChunks, updatedVisibleChunks);
final int[] newChunks = ArrayUtils.getDifferencesBetweenArray(updatedVisibleChunks, lastVisibleChunks); final int[] newChunks = ArrayUtils.getDifferencesBetweenArray(updatedVisibleChunks, lastVisibleChunks);
// Update client render distance
updateViewPosition(newChunk.getChunkX(), newChunk.getChunkZ());
// Unload old chunks // Unload old chunks
for (int index : oldChunks) { for (int index : oldChunks) {
final long chunkIndex = lastVisibleChunks[index]; final long chunkIndex = lastVisibleChunks[index];
final int chunkX = ChunkUtils.getChunkCoordX(chunkIndex); final int chunkX = ChunkUtils.getChunkCoordX(chunkIndex);
final int chunkZ = ChunkUtils.getChunkCoordZ(chunkIndex); final int chunkZ = ChunkUtils.getChunkCoordZ(chunkIndex);
// TODO prevent the client from getting lag spikes when re-loading large chunks final UnloadChunkPacket unloadChunkPacket = new UnloadChunkPacket();
// Probably by having a distinction between visible and loaded (cache) chunks
/*UnloadChunkPacket unloadChunkPacket = new UnloadChunkPacket();
unloadChunkPacket.chunkX = chunkX; unloadChunkPacket.chunkX = chunkX;
unloadChunkPacket.chunkZ = chunkZ; unloadChunkPacket.chunkZ = chunkZ;
playerConnection.sendPacket(unloadChunkPacket);*/ playerConnection.sendPacket(unloadChunkPacket);
final Chunk chunk = instance.getChunk(chunkX, chunkZ); final Chunk chunk = instance.getChunk(chunkX, chunkZ);
if (chunk != null) if (chunk != null)
chunk.removeViewer(this); chunk.removeViewer(this);
} }
// Update client render distance
updateViewPosition(newChunk.getChunkX(), newChunk.getChunkZ());
// Load new chunks // Load new chunks
for (int index : newChunks) { for (int index : newChunks) {
final long chunkIndex = updatedVisibleChunks[index]; final long chunkIndex = updatedVisibleChunks[index];
@ -2595,6 +2595,10 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
private byte displayedSkinParts; private byte displayedSkinParts;
private MainHand mainHand; private MainHand mainHand;
public PlayerSettings() {
viewDistance = 2;
}
/** /**
* The player game language. * The player game language.
* *