mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-30 21:17:53 +01:00
Unload all chunks when changing instance
This commit is contained in:
parent
de944edf42
commit
6a86e92999
@ -513,7 +513,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
*
|
||||
* @param instance the new player instance
|
||||
* @param spawnPosition the new position of the player
|
||||
* @return
|
||||
* @return a future called once the player instance changed
|
||||
*/
|
||||
@Override
|
||||
public CompletableFuture<Void> setInstance(@NotNull Instance instance, @NotNull Pos spawnPosition) {
|
||||
@ -579,6 +579,9 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
super.setInstance(instance, spawnPosition);
|
||||
|
||||
if (updateChunks) {
|
||||
// Warning: loop to remove once `refreshVisibleChunks` manage it
|
||||
this.viewableChunks.forEach(chunk ->
|
||||
playerConnection.sendPacket(new UnloadChunkPacket(chunk.getChunkX(), chunk.getChunkZ())));
|
||||
refreshVisibleChunks();
|
||||
}
|
||||
|
||||
@ -1199,12 +1202,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
ArrayUtils.forDifferencesBetweenArray(lastVisibleChunks, updatedVisibleChunks, chunkIndex -> {
|
||||
final int chunkX = ChunkUtils.getChunkCoordX(chunkIndex);
|
||||
final int chunkZ = ChunkUtils.getChunkCoordZ(chunkIndex);
|
||||
|
||||
final UnloadChunkPacket unloadChunkPacket = new UnloadChunkPacket();
|
||||
unloadChunkPacket.chunkX = chunkX;
|
||||
unloadChunkPacket.chunkZ = chunkZ;
|
||||
//playerConnection.sendPacket(unloadChunkPacket);
|
||||
|
||||
//playerConnection.sendPacket(new UnloadChunkPacket(chunkX, chunkZ));
|
||||
final Chunk chunk = instance.getChunk(chunkX, chunkZ);
|
||||
if (chunk != null) {
|
||||
chunk.removeViewer(this);
|
||||
|
@ -10,10 +10,14 @@ public class UnloadChunkPacket implements ServerPacket {
|
||||
|
||||
public int chunkX, chunkZ;
|
||||
|
||||
/**
|
||||
* Default constructor, required for reflection operations.
|
||||
*/
|
||||
public UnloadChunkPacket() {}
|
||||
public UnloadChunkPacket(int chunkX, int chunkZ) {
|
||||
this.chunkX = chunkX;
|
||||
this.chunkZ = chunkZ;
|
||||
}
|
||||
|
||||
public UnloadChunkPacket() {
|
||||
this(0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
|
Loading…
Reference in New Issue
Block a user