boundedInt(3, 0, self::MAX_BITES, $this->bites); } /** * @return AxisAlignedBB[] */ protected function recalculateCollisionBoxes() : array{ return [ AxisAlignedBB::one() ->contract(1 / 16, 0, 1 / 16) ->trim(Facing::UP, 0.5) ->trim(Facing::WEST, $this->bites / 8) ]; } public function getBites() : int{ return $this->bites; } /** @return $this */ public function setBites(int $bites) : self{ if($bites < 0 || $bites > self::MAX_BITES){ throw new \InvalidArgumentException("Bites must be in range 0 ... " . self::MAX_BITES); } $this->bites = $bites; return $this; } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($this->bites === 0 && $item instanceof ItemBlock){ $block = $item->getBlock(); $resultBlock = null; if($block->getTypeId() === BlockTypeIds::CANDLE){ $resultBlock = VanillaBlocks::CAKE_WITH_CANDLE(); }elseif($block instanceof DyedCandle){ $resultBlock = VanillaBlocks::CAKE_WITH_DYED_CANDLE()->setColor($block->getColor()); } if($resultBlock !== null){ $this->position->getWorld()->setBlock($this->position, $resultBlock); $item->pop(); return true; } } return parent::onInteract($item, $face, $clickVector, $player, $returnedItems); } public function getDropsForCompatibleTool(Item $item) : array{ return []; } public function getResidue() : Block{ $clone = clone $this; $clone->bites++; if($clone->bites > self::MAX_BITES){ $clone = VanillaBlocks::AIR(); } return $clone; } }