40 use FacesOppositePlacingPlayerTrait;
42 protected int $viewedPage = 0;
45 protected bool $producingSignal =
false;
48 $w->horizontalFacing($this->facing);
49 $w->bool($this->producingSignal);
53 parent::readStateFromWorld();
54 $tile = $this->position->getWorld()->getTile($this->position);
55 if($tile instanceof TileLectern){
56 $this->viewedPage = $tile->getViewedPage();
57 $this->book = $tile->getBook();
64 parent::writeStateToWorld();
65 $tile = $this->position->getWorld()->getTile($this->position);
66 if($tile instanceof TileLectern){
67 $tile->setViewedPage($this->viewedPage);
68 $tile->setBook($this->book);
77 $drops = parent::getDrops($item);
78 if($this->book !==
null){
79 $drops[] = clone $this->book;
90 return SupportType::NONE;
93 public function isProducingSignal() : bool{ return $this->producingSignal; }
97 $this->producingSignal = $producingSignal;
101 public function getViewedPage() : int{
102 return $this->viewedPage;
107 $this->viewedPage = $viewedPage;
112 return $this->book !== null ? clone $this->book : null;
117 $this->book = $book !== null && !$book->isNull() ? (clone $book)->setCount(1) : null;
118 $this->viewedPage = 0;
124 $world = $this->position->getWorld();
125 $world->setBlock($this->position, $this->setBook($item));
133 if($this->book !== null){
134 $world = $this->position->getWorld();
135 $world->dropItem($this->position->up(), $this->book);
136 $world->setBlock($this->position, $this->setBook(
null));
141 public function onPageTurn(
int $newPage) : bool{
142 if($newPage === $this->viewedPage){
145 if($this->book ===
null || $newPage >= count($this->book->getPages()) || $newPage < 0){
149 $this->viewedPage = $newPage;
150 $world = $this->position->getWorld();
151 if(!$this->producingSignal){
152 $this->producingSignal = true;
153 $world->scheduleDelayedBlockUpdate($this->position, 1);
156 $world->setBlock($this->position, $this);
162 if($this->producingSignal){
163 $this->producingSignal =
false;
164 $this->position->getWorld()->setBlock($this->position, $this);