encodeLitState($w); $w->boundedIntAuto(self::MIN_COUNT, self::MAX_COUNT, $this->count); } public function getCount() : int{ return $this->count; } /** @return $this */ public function setCount(int $count) : self{ if($count < self::MIN_COUNT || $count > self::MAX_COUNT){ throw new \InvalidArgumentException("Count must be in range " . self::MIN_COUNT . " ... " . self::MAX_COUNT); } $this->count = $count; return $this; } public function getLightLevel() : int{ return $this->getBaseLightLevel() * $this->count; } protected function recalculateCollisionBoxes() : array{ return [ (match($this->count){ 1 => AxisAlignedBB::one() ->squash(Axis::X, 7 / 16) ->squash(Axis::Z, 7 / 16), 2 => AxisAlignedBB::one() ->squash(Axis::X, 5 / 16) ->trim(Facing::NORTH, 7 / 16) //0.3 thick on the Z axis ->trim(Facing::SOUTH, 6 / 16), 3 => AxisAlignedBB::one() ->trim(Facing::WEST, 5 / 16) ->trim(Facing::EAST, 6 / 16) ->trim(Facing::NORTH, 6 / 16) ->trim(Facing::SOUTH, 5 / 16), 4 => AxisAlignedBB::one() ->squash(Axis::X, 5 / 16) ->trim(Facing::NORTH, 5 / 16) ->trim(Facing::SOUTH, 6 / 16), default => throw new AssumptionFailedError("Unreachable") })->trim(Facing::UP, 10 / 16) ]; } public function getSupportType(int $facing) : SupportType{ return SupportType::NONE; } protected function getCandleIfCompatibleType(Block $block) : ?Candle{ return $block instanceof Candle && $block->hasSameTypeId($this) ? $block : null; } public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{ $candle = $this->getCandleIfCompatibleType($blockReplace); return $candle !== null ? $candle->count < self::MAX_COUNT : parent::canBePlacedAt($blockReplace, $clickVector, $face, $isClickedBlock); } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if(!$blockReplace->getAdjacentSupportType(Facing::DOWN)->hasCenterSupport()){ return false; } $existing = $this->getCandleIfCompatibleType($blockReplace); if($existing !== null){ if($existing->count >= self::MAX_COUNT){ return false; } $this->count = $existing->count + 1; $this->lit = $existing->lit; } return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function getDropsForCompatibleTool(Item $item) : array{ return [$this->asItem()->setCount($this->count)]; } }