mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-23 20:04:02 +00:00
Chunk: add getNBTentities() and getNBTtiles()
this shit is horrible, but it's needed for now...
This commit is contained in:
parent
93cd00ae8f
commit
6e00ab2069
@ -38,6 +38,7 @@ use pocketmine\tile\TileFactory;
|
|||||||
use pocketmine\utils\BinaryStream;
|
use pocketmine\utils\BinaryStream;
|
||||||
use function array_fill;
|
use function array_fill;
|
||||||
use function array_filter;
|
use function array_filter;
|
||||||
|
use function array_map;
|
||||||
use function array_values;
|
use function array_values;
|
||||||
use function assert;
|
use function assert;
|
||||||
use function chr;
|
use function chr;
|
||||||
@ -590,6 +591,20 @@ class Chunk{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return CompoundTag[]
|
||||||
|
*/
|
||||||
|
public function getNBTtiles() : array{
|
||||||
|
return $this->NBTtiles ?? array_map(function(Tile $tile) : CompoundTag{ return $tile->saveNBT(); }, $this->tiles);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return CompoundTag[]
|
||||||
|
*/
|
||||||
|
public function getNBTentities() : array{
|
||||||
|
return $this->NBTentities ?? array_map(function(Entity $entity) : CompoundTag{ return $entity->saveNBT(); }, $this->getSavableEntities());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deserializes tiles and entities from NBT
|
* Deserializes tiles and entities from NBT
|
||||||
*
|
*
|
||||||
|
@ -343,19 +343,8 @@ class LevelDB extends BaseLevelProvider{
|
|||||||
//TODO: use this properly
|
//TODO: use this properly
|
||||||
$this->db->put($index . self::TAG_STATE_FINALISATION, chr(self::FINALISATION_DONE));
|
$this->db->put($index . self::TAG_STATE_FINALISATION, chr(self::FINALISATION_DONE));
|
||||||
|
|
||||||
/** @var CompoundTag[] $tiles */
|
$this->writeTags($chunk->getNBTtiles(), $index . self::TAG_BLOCK_ENTITY);
|
||||||
$tiles = [];
|
$this->writeTags($chunk->getNBTentities(), $index . self::TAG_ENTITY);
|
||||||
foreach($chunk->getTiles() as $tile){
|
|
||||||
$tiles[] = $tile->saveNBT();
|
|
||||||
}
|
|
||||||
$this->writeTags($tiles, $index . self::TAG_BLOCK_ENTITY);
|
|
||||||
|
|
||||||
/** @var CompoundTag[] $entities */
|
|
||||||
$entities = [];
|
|
||||||
foreach($chunk->getSavableEntities() as $entity){
|
|
||||||
$entities[] = $entity->saveNBT();
|
|
||||||
}
|
|
||||||
$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);
|
||||||
$this->db->delete($index . self::TAG_LEGACY_TERRAIN);
|
$this->db->delete($index . self::TAG_LEGACY_TERRAIN);
|
||||||
|
@ -73,20 +73,8 @@ trait LegacyAnvilChunkTrait{
|
|||||||
$nbt->setByteArray("Biomes", $chunk->getBiomeIdArray());
|
$nbt->setByteArray("Biomes", $chunk->getBiomeIdArray());
|
||||||
$nbt->setIntArray("HeightMap", $chunk->getHeightMapArray());
|
$nbt->setIntArray("HeightMap", $chunk->getHeightMapArray());
|
||||||
|
|
||||||
$entities = [];
|
$nbt->setTag(new ListTag("Entities", $chunk->getNBTentities(), NBT::TAG_Compound));
|
||||||
|
$nbt->setTag(new ListTag("TileEntities", $chunk->getNBTtiles(), NBT::TAG_Compound));
|
||||||
foreach($chunk->getSavableEntities() as $entity){
|
|
||||||
$entities[] = $entity->saveNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
$nbt->setTag(new ListTag("Entities", $entities, NBT::TAG_Compound));
|
|
||||||
|
|
||||||
$tiles = [];
|
|
||||||
foreach($chunk->getTiles() as $tile){
|
|
||||||
$tiles[] = $tile->saveNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
$nbt->setTag(new ListTag("TileEntities", $tiles, NBT::TAG_Compound));
|
|
||||||
|
|
||||||
//TODO: TileTicks
|
//TODO: TileTicks
|
||||||
|
|
||||||
|
@ -81,20 +81,8 @@ class McRegion extends RegionLevelProvider{
|
|||||||
$nbt->setByteArray("Biomes", $chunk->getBiomeIdArray()); //doesn't exist in regular McRegion, this is here for PocketMine-MP only
|
$nbt->setByteArray("Biomes", $chunk->getBiomeIdArray()); //doesn't exist in regular McRegion, this is here for PocketMine-MP only
|
||||||
$nbt->setByteArray("HeightMap", pack("C*", ...$chunk->getHeightMapArray())); //this is ByteArray in McRegion, but IntArray in Anvil (due to raised build height)
|
$nbt->setByteArray("HeightMap", pack("C*", ...$chunk->getHeightMapArray())); //this is ByteArray in McRegion, but IntArray in Anvil (due to raised build height)
|
||||||
|
|
||||||
$entities = [];
|
$nbt->setTag(new ListTag("Entities", $chunk->getNBTentities(), NBT::TAG_Compound));
|
||||||
|
$nbt->setTag(new ListTag("TileEntities", $chunk->getNBTtiles(), NBT::TAG_Compound));
|
||||||
foreach($chunk->getSavableEntities() as $entity){
|
|
||||||
$entities[] = $entity->saveNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
$nbt->setTag(new ListTag("Entities", $entities, NBT::TAG_Compound));
|
|
||||||
|
|
||||||
$tiles = [];
|
|
||||||
foreach($chunk->getTiles() as $tile){
|
|
||||||
$tiles[] = $tile->saveNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
$nbt->setTag(new ListTag("TileEntities", $tiles, NBT::TAG_Compound));
|
|
||||||
|
|
||||||
$writer = new BigEndianNbtSerializer();
|
$writer = new BigEndianNbtSerializer();
|
||||||
return $writer->writeCompressed(new CompoundTag("", [$nbt]), ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL);
|
return $writer->writeCompressed(new CompoundTag("", [$nbt]), ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user