facing = $r->readHorizontalFacing(); $this->open = $r->readBool(); $this->inWall = $r->readBool(); } protected function encodeState(BlockDataWriter $w) : void{ $w->writeHorizontalFacing($this->facing); $w->writeBool($this->open); $w->writeBool($this->inWall); } public function isOpen() : bool{ return $this->open; } /** @return $this */ public function setOpen(bool $open) : self{ $this->open = $open; return $this; } public function isInWall() : bool{ return $this->inWall; } /** @return $this */ public function setInWall(bool $inWall) : self{ $this->inWall = $inWall; return $this; } /** * @return AxisAlignedBB[] */ protected function recalculateCollisionBoxes() : array{ return $this->open ? [] : [AxisAlignedBB::one()->extend(Facing::UP, 0.5)->squash(Facing::axis($this->facing), 6 / 16)]; } public function getSupportType(int $facing) : SupportType{ return SupportType::NONE(); } private function checkInWall() : bool{ return ( $this->getSide(Facing::rotateY($this->facing, false)) instanceof Wall || $this->getSide(Facing::rotateY($this->facing, true)) instanceof Wall ); } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player !== null){ $this->facing = $player->getHorizontalFacing(); } $this->inWall = $this->checkInWall(); return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function onNearbyBlockChange() : void{ $inWall = $this->checkInWall(); if($inWall !== $this->inWall){ $this->inWall = $inWall; $this->position->getWorld()->setBlock($this->position, $this); } } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->open = !$this->open; if($this->open && $player !== null){ $playerFacing = $player->getHorizontalFacing(); if($playerFacing === Facing::opposite($this->facing)){ $this->facing = $playerFacing; } } $this->position->getWorld()->setBlock($this->position, $this); $this->position->getWorld()->addSound($this->position, new DoorSound()); return true; } public function getFuelTime() : int{ return 300; } public function getFlameEncouragement() : int{ return 5; } public function getFlammability() : int{ return 20; } }