Re-enable chunk unloading, corrected packet order

This commit is contained in:
Németh Noel 2021-05-07 00:54:38 +02:00
parent d360904f77
commit de7241ef6c

View File

@ -1547,27 +1547,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];