mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 18:32:55 +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:
@ -30,10 +30,7 @@ use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockLegacyIds;
|
||||
use pocketmine\block\tile\Tile;
|
||||
use pocketmine\data\bedrock\BiomeIds;
|
||||
use pocketmine\entity\Entity;
|
||||
use pocketmine\player\Player;
|
||||
use function array_fill;
|
||||
use function array_filter;
|
||||
use function array_map;
|
||||
|
||||
class Chunk{
|
||||
@ -59,9 +56,6 @@ class Chunk{
|
||||
/** @var Tile[] */
|
||||
protected $tiles = [];
|
||||
|
||||
/** @var Entity[] */
|
||||
protected $entities = [];
|
||||
|
||||
/** @var HeightArray */
|
||||
protected $heightMap;
|
||||
|
||||
@ -191,17 +185,6 @@ class Chunk{
|
||||
$this->terrainDirtyFlags |= self::DIRTY_FLAG_TERRAIN;
|
||||
}
|
||||
|
||||
public function addEntity(Entity $entity) : void{
|
||||
if($entity->isClosed()){
|
||||
throw new \InvalidArgumentException("Attempted to add a garbage closed Entity to a chunk");
|
||||
}
|
||||
$this->entities[$entity->getId()] = $entity;
|
||||
}
|
||||
|
||||
public function removeEntity(Entity $entity) : void{
|
||||
unset($this->entities[$entity->getId()]);
|
||||
}
|
||||
|
||||
public function addTile(Tile $tile) : void{
|
||||
if($tile->isClosed()){
|
||||
throw new \InvalidArgumentException("Attempted to add a garbage closed Tile to a chunk");
|
||||
@ -219,22 +202,6 @@ class Chunk{
|
||||
unset($this->tiles[Chunk::blockHash($pos->x, $pos->y, $pos->z)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of entities currently using this chunk.
|
||||
*
|
||||
* @return Entity[]
|
||||
*/
|
||||
public function getEntities() : array{
|
||||
return $this->entities;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Entity[]
|
||||
*/
|
||||
public function getSavableEntities() : array{
|
||||
return array_filter($this->entities, function(Entity $entity) : bool{ return $entity->canSaveWithChunk(); });
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Tile[]
|
||||
*/
|
||||
@ -257,13 +224,6 @@ class Chunk{
|
||||
* Called when the chunk is unloaded, closing entities and tiles.
|
||||
*/
|
||||
public function onUnload() : void{
|
||||
foreach($this->getEntities() as $entity){
|
||||
if($entity instanceof Player){
|
||||
continue;
|
||||
}
|
||||
$entity->close();
|
||||
}
|
||||
|
||||
foreach($this->getTiles() as $tile){
|
||||
$tile->close();
|
||||
}
|
||||
|
Reference in New Issue
Block a user