bool($this->ready); } public function isReady() : bool{ return $this->ready; } /** @return $this */ public function setReady(bool $ready) : self{ $this->ready = $ready; return $this; } private function canBeSupportedAt(Block $block) : bool{ $supportBlock = $block->getSide(Facing::DOWN); return $supportBlock->getTypeId() === BlockTypeIds::GRAVEL || $supportBlock->hasTypeTag(BlockTypeTags::DIRT) || $supportBlock->hasTypeTag(BlockTypeTags::MUD) || $supportBlock->hasTypeTag(BlockTypeTags::SAND); } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($item instanceof Fertilizer || $item instanceof ItemBamboo){ if($this->grow($player)){ $item->pop(); return true; } } return false; } private function grow(?Player $player) : bool{ $world = $this->position->getWorld(); if(!$world->getBlock($this->position->up())->canBeReplaced()){ return false; } $tx = new BlockTransaction($world); $bamboo = VanillaBlocks::BAMBOO(); $tx->addBlock($this->position, $bamboo) ->addBlock($this->position->up(), (clone $bamboo)->setLeafSize(Bamboo::SMALL_LEAVES)); $ev = new StructureGrowEvent($this, $tx, $player); $ev->call(); if($ev->isCancelled()){ return false; } return $tx->apply(); } public function ticksRandomly() : bool{ return true; } public function onRandomTick() : void{ $world = $this->position->getWorld(); if($this->ready){ $this->ready = false; if($world->getFullLight($this->position) < 9 || !$this->grow(null)){ $world->setBlock($this->position, $this); } }elseif($world->getBlock($this->position->up())->canBeReplaced()){ $this->ready = true; $world->setBlock($this->position, $this); } } public function asItem() : Item{ return VanillaItems::BAMBOO(); } }