mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-14 15:35:31 +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 $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[]
|
* @return Tile[]
|
||||||
*/
|
*/
|
||||||
|
@ -537,12 +537,10 @@ class LevelDB extends BaseLevelProvider{
|
|||||||
|
|
||||||
/** @var CompoundTag[] $entities */
|
/** @var CompoundTag[] $entities */
|
||||||
$entities = [];
|
$entities = [];
|
||||||
foreach($chunk->getEntities() as $entity){
|
foreach($chunk->getSavableEntities() as $entity){
|
||||||
if($entity->canSaveWithChunk() and !$entity->isClosed()){
|
|
||||||
$entity->saveNBT();
|
$entity->saveNBT();
|
||||||
$entities[] = $entity->namedtag;
|
$entities[] = $entity->namedtag;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
$this->writeTags($entities, $index . self::TAG_ENTITY);
|
$this->writeTags($entities, $index . self::TAG_ENTITY);
|
||||||
|
|
||||||
$this->db->delete($index . self::TAG_DATA_2D_LEGACY);
|
$this->db->delete($index . self::TAG_DATA_2D_LEGACY);
|
||||||
|
@ -66,12 +66,10 @@ class Anvil extends McRegion{
|
|||||||
|
|
||||||
$entities = [];
|
$entities = [];
|
||||||
|
|
||||||
foreach($chunk->getEntities() as $entity){
|
foreach($chunk->getSavableEntities() as $entity){
|
||||||
if($entity->canSaveWithChunk() and !$entity->isClosed()){
|
|
||||||
$entity->saveNBT();
|
$entity->saveNBT();
|
||||||
$entities[] = $entity->namedtag;
|
$entities[] = $entity->namedtag;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$nbt->setTag(new ListTag("Entities", $entities, NBT::TAG_Compound));
|
$nbt->setTag(new ListTag("Entities", $entities, NBT::TAG_Compound));
|
||||||
|
|
||||||
|
@ -87,12 +87,10 @@ class McRegion extends BaseLevelProvider{
|
|||||||
|
|
||||||
$entities = [];
|
$entities = [];
|
||||||
|
|
||||||
foreach($chunk->getEntities() as $entity){
|
foreach($chunk->getSavableEntities() as $entity){
|
||||||
if($entity->canSaveWithChunk() and !$entity->isClosed()){
|
|
||||||
$entity->saveNBT();
|
$entity->saveNBT();
|
||||||
$entities[] = $entity->namedtag;
|
$entities[] = $entity->namedtag;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$nbt->setTag(new ListTag("Entities", $entities, NBT::TAG_Compound));
|
$nbt->setTag(new ListTag("Entities", $entities, NBT::TAG_Compound));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user