mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-05 17:36:12 +00:00
Added API to allow flagging an entity not to be saved to disk when its chunk is saved (#1452)
This commit is contained in:
@ -509,32 +509,38 @@ class LevelDB extends BaseLevelProvider{
|
||||
//TODO: use this properly
|
||||
$this->db->put($index . self::TAG_STATE_FINALISATION, chr(self::FINALISATION_DONE));
|
||||
|
||||
$this->writeTags($chunk->getTiles(), $index . self::TAG_BLOCK_ENTITY);
|
||||
$this->writeTags(array_filter($chunk->getEntities(), function(Entity $entity) : bool{
|
||||
return !($entity instanceof Player);
|
||||
}), $index . self::TAG_ENTITY);
|
||||
/** @var CompoundTag[] $tiles */
|
||||
$tiles = [];
|
||||
foreach($chunk->getTiles() as $tile){
|
||||
if(!$tile->isClosed()){
|
||||
$tile->saveNBT();
|
||||
$tiles[] = $tile->namedtag;
|
||||
}
|
||||
}
|
||||
$this->writeTags($tiles, $index . self::TAG_BLOCK_ENTITY);
|
||||
|
||||
/** @var CompoundTag[] $entities */
|
||||
$entities = [];
|
||||
foreach($chunk->getEntities() as $entity){
|
||||
if($entity->canSaveWithChunk() and !$entity->isClosed()){
|
||||
$entity->saveNBT();
|
||||
$entities[] = $entity->namedtag;
|
||||
}
|
||||
}
|
||||
$this->writeTags($entities, $index . self::TAG_ENTITY);
|
||||
|
||||
$this->db->delete($index . self::TAG_DATA_2D_LEGACY);
|
||||
$this->db->delete($index . self::TAG_LEGACY_TERRAIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Entity[]|Tile[] $targets
|
||||
* @param string $index
|
||||
* @param CompoundTag[] $targets
|
||||
* @param string $index
|
||||
*/
|
||||
private function writeTags(array $targets, string $index){
|
||||
$nbt = new NBT(NBT::LITTLE_ENDIAN);
|
||||
$out = [];
|
||||
/** @var Entity|Tile $target */
|
||||
foreach($targets as $target){
|
||||
if(!$target->isClosed()){
|
||||
$target->saveNBT();
|
||||
$out[] = $target->namedtag;
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($targets)){
|
||||
$nbt->setData($out);
|
||||
$nbt = new NBT(NBT::LITTLE_ENDIAN);
|
||||
$nbt->setData($targets);
|
||||
$this->db->put($index, $nbt->write());
|
||||
}else{
|
||||
$this->db->delete($index);
|
||||
|
Reference in New Issue
Block a user