mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +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 instance the new player instance
|
||||||
* @param spawnPosition the new position of the player
|
* @param spawnPosition the new position of the player
|
||||||
* @return
|
* @return a future called once the player instance changed
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> setInstance(@NotNull Instance instance, @NotNull Pos spawnPosition) {
|
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);
|
super.setInstance(instance, spawnPosition);
|
||||||
|
|
||||||
if (updateChunks) {
|
if (updateChunks) {
|
||||||
|
// Warning: loop to remove once `refreshVisibleChunks` manage it
|
||||||
|
this.viewableChunks.forEach(chunk ->
|
||||||
|
playerConnection.sendPacket(new UnloadChunkPacket(chunk.getChunkX(), chunk.getChunkZ())));
|
||||||
refreshVisibleChunks();
|
refreshVisibleChunks();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1199,12 +1202,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
ArrayUtils.forDifferencesBetweenArray(lastVisibleChunks, updatedVisibleChunks, chunkIndex -> {
|
ArrayUtils.forDifferencesBetweenArray(lastVisibleChunks, updatedVisibleChunks, chunkIndex -> {
|
||||||
final int chunkX = ChunkUtils.getChunkCoordX(chunkIndex);
|
final int chunkX = ChunkUtils.getChunkCoordX(chunkIndex);
|
||||||
final int chunkZ = ChunkUtils.getChunkCoordZ(chunkIndex);
|
final int chunkZ = ChunkUtils.getChunkCoordZ(chunkIndex);
|
||||||
|
//playerConnection.sendPacket(new UnloadChunkPacket(chunkX, chunkZ));
|
||||||
final UnloadChunkPacket unloadChunkPacket = new UnloadChunkPacket();
|
|
||||||
unloadChunkPacket.chunkX = chunkX;
|
|
||||||
unloadChunkPacket.chunkZ = chunkZ;
|
|
||||||
//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);
|
||||||
|
@ -10,10 +10,14 @@ public class UnloadChunkPacket implements ServerPacket {
|
|||||||
|
|
||||||
public int chunkX, chunkZ;
|
public int chunkX, chunkZ;
|
||||||
|
|
||||||
/**
|
public UnloadChunkPacket(int chunkX, int chunkZ) {
|
||||||
* Default constructor, required for reflection operations.
|
this.chunkX = chunkX;
|
||||||
*/
|
this.chunkZ = chunkZ;
|
||||||
public UnloadChunkPacket() {}
|
}
|
||||||
|
|
||||||
|
public UnloadChunkPacket() {
|
||||||
|
this(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(@NotNull BinaryWriter writer) {
|
public void write(@NotNull BinaryWriter writer) {
|
||||||
|
Loading…
Reference in New Issue
Block a user