facing) | ($this->open ? BlockLegacyMetadata::FENCE_GATE_FLAG_OPEN : 0) | ($this->inWall ? BlockLegacyMetadata::FENCE_GATE_FLAG_IN_WALL : 0); } public function readStateFromData(int $id, int $stateMeta) : void{ $this->facing = BlockDataSerializer::readLegacyHorizontalFacing($stateMeta & 0x03); $this->open = ($stateMeta & BlockLegacyMetadata::FENCE_GATE_FLAG_OPEN) !== 0; $this->inWall = ($stateMeta & BlockLegacyMetadata::FENCE_GATE_FLAG_IN_WALL) !== 0; } public function getStateBitmask() : int{ return 0b1111; } /** * @return AxisAlignedBB[] */ protected function recalculateCollisionBoxes() : array{ return $this->open ? [] : [AxisAlignedBB::one()->extend(Facing::UP, 0.5)->squash(Facing::axis($this->facing), 6 / 16)]; } private function checkInWall() : bool{ return ( $this->getSide(Facing::rotateY($this->facing, false)) instanceof Wall or $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->pos->getWorld()->setBlock($this->pos, $this); } } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->open = !$this->open; if($this->open and $player !== null){ $playerFacing = $player->getHorizontalFacing(); if($playerFacing === Facing::opposite($this->facing)){ $this->facing = $playerFacing; } } $this->pos->getWorld()->setBlock($this->pos, $this); $this->pos->getWorld()->addSound($this->pos, new DoorSound()); return true; } public function getFuelTime() : int{ return 300; } public function getFlameEncouragement() : int{ return 5; } public function getFlammability() : int{ return 20; } }