41 use FacesOppositePlacingPlayerTrait;
43 protected int $viewedPage = 0;
46 protected bool $producingSignal =
false;
49 $w->horizontalFacing($this->facing);
50 $w->bool($this->producingSignal);
54 parent::readStateFromWorld();
55 $tile = $this->position->getWorld()->getTile($this->position);
56 if($tile instanceof TileLectern){
57 $this->viewedPage = $tile->getViewedPage();
58 $this->book = $tile->getBook();
65 parent::writeStateToWorld();
66 $tile = $this->position->getWorld()->getTile($this->position);
67 if($tile instanceof TileLectern){
68 $tile->setViewedPage($this->viewedPage);
69 $tile->setBook($this->book);
78 $drops = parent::getDrops($item);
79 if($this->book !==
null){
80 $drops[] = clone $this->book;
91 return SupportType::NONE;
94 public function isProducingSignal() : bool{ return $this->producingSignal; }
98 $this->producingSignal = $producingSignal;
102 public function getViewedPage() : int{
103 return $this->viewedPage;
108 $this->viewedPage = $viewedPage;
113 return $this->book !== null ? clone $this->book : null;
118 $this->book = $book !== null && !$book->isNull() ? (clone $book)->setCount(1) : null;
119 $this->viewedPage = 0;
125 $world = $this->position->getWorld();
126 $world->setBlock($this->position, $this->setBook($item));
134 if($this->book !== null){
135 $world = $this->position->getWorld();
136 $world->dropItem($this->position->up(), $this->book);
137 $world->setBlock($this->position, $this->setBook(
null));
142 public function onPageTurn(
int $newPage) : bool{
143 if($newPage === $this->viewedPage){
146 if($this->book ===
null || $newPage >= count($this->book->getPages()) || $newPage < 0){
150 $this->viewedPage = $newPage;
151 $world = $this->position->getWorld();
152 if(!$this->producingSignal){
153 $this->producingSignal = true;
154 $world->scheduleDelayedBlockUpdate($this->position, 1);
157 $world->setBlock($this->position, $this);
163 if($this->producingSignal){
164 $this->producingSignal =
false;
165 $this->position->getWorld()->setBlock($this->position, $this);