viewedPage = $nbt->getInt(self::TAG_PAGE, 0); if(($itemTag = $nbt->getCompoundTag(self::TAG_BOOK)) !== null){ $book = Item::nbtDeserialize($itemTag); if($book instanceof WritableBookBase && !$book->isNull()){ $this->book = $book; } } } protected function writeSaveData(CompoundTag $nbt) : void{ $nbt->setByte(self::TAG_HAS_BOOK, $this->book !== null ? 1 : 0); $nbt->setInt(self::TAG_PAGE, $this->viewedPage); if($this->book !== null){ $nbt->setTag(self::TAG_BOOK, $this->book->nbtSerialize()); $nbt->setInt(self::TAG_TOTAL_PAGES, count($this->book->getPages())); } } public function getViewedPage() : int{ return $this->viewedPage; } public function setViewedPage(int $viewedPage) : void{ $this->viewedPage = $viewedPage; } public function getBook() : ?WritableBookBase{ return $this->book !== null ? clone $this->book : null; } public function setBook(?WritableBookBase $book) : void{ $this->book = $book !== null && !$book->isNull() ? clone $book : null; } protected function addAdditionalSpawnData(CompoundTag $nbt) : void{ $nbt->setByte(self::TAG_HAS_BOOK, $this->book !== null ? 1 : 0); $nbt->setInt(self::TAG_PAGE, $this->viewedPage); if($this->book !== null){ $nbt->setTag(self::TAG_BOOK, TypeConverter::getInstance()->getItemTranslator()->toNetworkNbt($this->book)); $nbt->setInt(self::TAG_TOTAL_PAGES, count($this->book->getPages())); } } }