generation; } /** * Sets the generation of a book. * * @return $this */ public function setGeneration(int $generation) : self{ if($generation < 0 || $generation > 3){ throw new \InvalidArgumentException("Generation \"$generation\" is out of range"); } $this->generation = $generation; return $this; } /** * Returns the author of this book. * This is not a reliable way to get the name of the player who signed this book. * The author can be set to anything when signing a book. */ public function getAuthor() : string{ return $this->author; } /** * Sets the author of this book. * * @return $this */ public function setAuthor(string $authorName) : self{ if(strlen($authorName) > Limits::INT16_MAX){ throw new \InvalidArgumentException(sprintf("Author must be at most %d bytes, but have %d bytes", Limits::INT16_MAX, strlen($authorName))); } Utils::checkUTF8($authorName); $this->author = $authorName; return $this; } /** * Returns the title of this book. */ public function getTitle() : string{ return $this->title; } /** * Sets the author of this book. * * @return $this */ public function setTitle(string $title) : self{ if(strlen($title) > Limits::INT16_MAX){ throw new \InvalidArgumentException(sprintf("Title must be at most %d bytes, but have %d bytes", Limits::INT16_MAX, strlen($title))); } Utils::checkUTF8($title); $this->title = $title; return $this; } protected function deserializeCompoundTag(CompoundTag $tag) : void{ parent::deserializeCompoundTag($tag); $this->generation = $tag->getInt(self::TAG_GENERATION, $this->generation); $this->author = $tag->getString(self::TAG_AUTHOR, $this->author); $this->title = $tag->getString(self::TAG_TITLE, $this->title); } protected function serializeCompoundTag(CompoundTag $tag) : void{ parent::serializeCompoundTag($tag); $tag->setInt(self::TAG_GENERATION, $this->generation); $tag->setString(self::TAG_AUTHOR, $this->author); $tag->setString(self::TAG_TITLE, $this->title); } }