closed){ return false; } $nbt = new NBT(NBT::LITTLE_ENDIAN); $nbt->setData($this->getSpawnCompound()); $pk = new BlockEntityDataPacket(); $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; $pk->namedtag = $nbt->write(true); $player->dataPacket($pk); return true; } public function __construct(Level $level, CompoundTag $nbt){ parent::__construct($level, $nbt); $this->spawnToAll(); } public function spawnToAll(){ if($this->closed){ return; } foreach($this->getLevel()->getChunkPlayers($this->chunk->getX(), $this->chunk->getZ()) as $player){ if($player->spawned === true){ $this->spawnTo($player); } } } protected function onChanged(){ $this->spawnToAll(); if($this->chunk !== null){ $this->chunk->setChanged(); $this->level->clearChunkCache($this->chunk->getX(), $this->chunk->getZ()); } } /** * @return CompoundTag */ abstract public function getSpawnCompound(); /** * Called when a player updates a block entity's NBT data * for example when writing on a sign. * * @param CompoundTag $nbt * @param Player $player * * @return bool indication of success, will respawn the tile to the player if false. */ public function updateCompoundTag(CompoundTag $nbt, Player $player) : bool{ return false; } }