mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-29 06:57:28 +02:00
Remove entities other than players when unloading a chunk
This commit is contained in:
parent
895a4fd4bd
commit
50373505b3
@ -105,6 +105,10 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
public abstract void loadOptionalChunk(int chunkX, int chunkZ, Consumer<Chunk> callback);
|
||||
|
||||
/**
|
||||
* Unload a chunk
|
||||
* <p>
|
||||
* WARNING: all entities other than {@link Player} will be removed
|
||||
*
|
||||
* @param chunk the chunk to unload
|
||||
*/
|
||||
public abstract void unloadChunk(Chunk chunk);
|
||||
|
@ -313,6 +313,13 @@ public class InstanceContainer extends Instance {
|
||||
chunk.removeViewer(viewer);
|
||||
}
|
||||
|
||||
// Remove all entities in chunk
|
||||
getChunkEntities(chunk).forEach(entity -> {
|
||||
if (!(entity instanceof Player))
|
||||
entity.remove();
|
||||
});
|
||||
|
||||
// Clear cache
|
||||
this.chunks.remove(index);
|
||||
this.chunkEntities.remove(index);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user