mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 10:22:56 +00:00
making tile spawn compound cache use CacheableNbt instead of strings
This commit is contained in:
@ -24,12 +24,15 @@ declare(strict_types=1);
|
||||
namespace pocketmine\block\tile;
|
||||
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\nbt\TreeRoot;
|
||||
use pocketmine\network\mcpe\protocol\serializer\NetworkNbtSerializer;
|
||||
use pocketmine\network\mcpe\protocol\types\CacheableNbt;
|
||||
use function get_class;
|
||||
|
||||
abstract class Spawnable extends Tile{
|
||||
/** @var string|null */
|
||||
/**
|
||||
* @var CacheableNbt|null
|
||||
* @phpstan-var CacheableNbt<\pocketmine\nbt\tag\CompoundTag>|null
|
||||
*/
|
||||
private $spawnCompoundCache = null;
|
||||
/** @var bool */
|
||||
private $dirty = true; //default dirty, until it's been spawned appropriately on the world
|
||||
@ -55,15 +58,11 @@ abstract class Spawnable extends Tile{
|
||||
* Returns encoded NBT (varint, little-endian) used to spawn this tile to clients. Uses cache where possible,
|
||||
* populates cache if it is null.
|
||||
*
|
||||
* @return string encoded NBT
|
||||
* @phpstan-return CacheableNbt<\pocketmine\nbt\tag\CompoundTag>
|
||||
*/
|
||||
final public function getSerializedSpawnCompound() : string{
|
||||
final public function getSerializedSpawnCompound() : CacheableNbt{
|
||||
if($this->spawnCompoundCache === null){
|
||||
if(self::$nbtWriter === null){
|
||||
self::$nbtWriter = new NetworkNbtSerializer();
|
||||
}
|
||||
|
||||
$this->spawnCompoundCache = self::$nbtWriter->write(new TreeRoot($this->getSpawnCompound()));
|
||||
$this->spawnCompoundCache = new CacheableNbt($this->getSpawnCompound());
|
||||
}
|
||||
|
||||
return $this->spawnCompoundCache;
|
||||
|
Reference in New Issue
Block a user