generalized conditions for saving entities with chunks

This commit is contained in:
Dylan K. Taylor 2017-11-19 18:06:38 +00:00
parent 19dc22d6b3
commit a9df383346
4 changed files with 16 additions and 15 deletions

View File

@ -667,6 +667,13 @@ class Chunk{
return $this->entities;
}
/**
* @return Entity[]
*/
public function getSavableEntities() : array{
return array_filter($this->entities, function(Entity $entity) : bool{ return $entity->canSaveWithChunk() and !$entity->isClosed(); });
}
/**
* @return Tile[]
*/

View File

@ -537,11 +537,9 @@ class LevelDB extends BaseLevelProvider{
/** @var CompoundTag[] $entities */
$entities = [];
foreach($chunk->getEntities() as $entity){
if($entity->canSaveWithChunk() and !$entity->isClosed()){
$entity->saveNBT();
$entities[] = $entity->namedtag;
}
foreach($chunk->getSavableEntities() as $entity){
$entity->saveNBT();
$entities[] = $entity->namedtag;
}
$this->writeTags($entities, $index . self::TAG_ENTITY);

View File

@ -66,11 +66,9 @@ class Anvil extends McRegion{
$entities = [];
foreach($chunk->getEntities() as $entity){
if($entity->canSaveWithChunk() and !$entity->isClosed()){
$entity->saveNBT();
$entities[] = $entity->namedtag;
}
foreach($chunk->getSavableEntities() as $entity){
$entity->saveNBT();
$entities[] = $entity->namedtag;
}
$nbt->setTag(new ListTag("Entities", $entities, NBT::TAG_Compound));

View File

@ -87,11 +87,9 @@ class McRegion extends BaseLevelProvider{
$entities = [];
foreach($chunk->getEntities() as $entity){
if($entity->canSaveWithChunk() and !$entity->isClosed()){
$entity->saveNBT();
$entities[] = $entity->namedtag;
}
foreach($chunk->getSavableEntities() as $entity){
$entity->saveNBT();
$entities[] = $entity->namedtag;
}
$nbt->setTag(new ListTag("Entities", $entities, NBT::TAG_Compound));