treeType = $treeType; } public function describeState(RuntimeDataDescriber $w) : void{ $w->bool($this->ready); } public function isReady() : bool{ return $this->ready; } /** @return $this */ public function setReady(bool $ready) : self{ $this->ready = $ready; return $this; } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $down = $this->getSide(Facing::DOWN); if($down->hasTypeTag(BlockTypeTags::DIRT) || $down->hasTypeTag(BlockTypeTags::MUD)){ return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } return false; } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($item instanceof Fertilizer && $this->grow($player)){ $item->pop(); return true; } return false; } public function onNearbyBlockChange() : void{ $down = $this->getSide(Facing::DOWN); if(!$down->hasTypeTag(BlockTypeTags::DIRT) && !$down->hasTypeTag(BlockTypeTags::MUD)){ $this->position->getWorld()->useBreakOn($this->position); } } public function ticksRandomly() : bool{ return true; } public function onRandomTick() : void{ $world = $this->position->getWorld(); if($world->getFullLightAt($this->position->getFloorX(), $this->position->getFloorY(), $this->position->getFloorZ()) >= 8 && mt_rand(1, 7) === 1){ if($this->ready){ $this->grow(null); }else{ $this->ready = true; $world->setBlock($this->position, $this); } } } private function grow(?Player $player) : bool{ $random = new Random(mt_rand()); $tree = TreeFactory::get($random, $this->treeType); $transaction = $tree?->getBlockTransaction($this->position->getWorld(), $this->position->getFloorX(), $this->position->getFloorY(), $this->position->getFloorZ(), $random); if($transaction === null){ return false; } $ev = new StructureGrowEvent($this, $transaction, $player); $ev->call(); if(!$ev->isCancelled()){ return $transaction->apply(); } return false; } public function getFuelTime() : int{ return 100; } }