facingExcept($this->facing, Facing::DOWN); } public function getFacing() : int{ return $this->facing; } /** @return $this */ public function setFacing(int $facing) : self{ if($facing === Facing::DOWN){ throw new \InvalidArgumentException("Torch may not face DOWN"); } $this->facing = $facing; return $this; } public function getLightLevel() : int{ return 14; } public function onNearbyBlockChange() : void{ $face = Facing::opposite($this->facing); if(!$this->canBeSupportedBy($this->getSide($face), $this->facing)){ $this->position->getWorld()->useBreakOn($this->position); } } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($face !== Facing::DOWN && $this->canBeSupportedBy($blockReplace->getSide(Facing::opposite($face)), $face)){ $this->facing = $face; return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); }else{ foreach([ Facing::SOUTH, Facing::WEST, Facing::NORTH, Facing::EAST, Facing::DOWN ] as $side){ $block = $this->getSide($side); if($this->canBeSupportedBy($block, Facing::opposite($side))){ $this->facing = Facing::opposite($side); return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } } } return false; } private function canBeSupportedBy(Block $support, int $face) : bool{ return ($face === Facing::UP && $support->getSupportType($face)->hasCenterSupport()) || (Facing::axis($face) !== Axis::Y && $support->getSupportType($face)->equals(SupportType::FULL())); } }