mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
generalized conditions for saving entities with chunks
This commit is contained in:
parent
19dc22d6b3
commit
a9df383346
@ -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[]
|
||||
*/
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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));
|
||||
|
@ -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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user