mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-20 15:41:33 +00:00
World: Track entities separately from chunks
this allows entities to exist outside of generated chunks, with one caveat: they won't be saved in such cases. Obviously, for player entities, this doesn't matter. fixes #3947
This commit is contained in:
@@ -630,12 +630,9 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
$world = $world ?? $this->getWorld();
|
||||
$index = World::chunkHash($x, $z);
|
||||
if(isset($this->usedChunks[$index])){
|
||||
$chunk = $world->getChunk($x, $z);
|
||||
if($chunk !== null){ //this might be a chunk that hasn't been generated yet
|
||||
foreach($chunk->getEntities() as $entity){
|
||||
if($entity !== $this){
|
||||
$entity->despawnFrom($this);
|
||||
}
|
||||
foreach($world->getChunkEntities($x, $z) as $entity){
|
||||
if($entity !== $this){
|
||||
$entity->despawnFrom($this);
|
||||
}
|
||||
}
|
||||
$this->getNetworkSession()->stopUsingChunk($x, $z);
|
||||
@@ -656,7 +653,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
}
|
||||
|
||||
protected function spawnEntitiesOnChunk(int $chunkX, int $chunkZ) : void{
|
||||
foreach($this->getWorld()->getChunk($chunkX, $chunkZ)->getEntities() as $entity){
|
||||
foreach($this->getWorld()->getChunkEntities($chunkX, $chunkZ) as $entity){
|
||||
if($entity !== $this and !$entity->isFlaggedForDespawn()){
|
||||
$entity->spawnTo($this);
|
||||
}
|
||||
|
Reference in New Issue
Block a user