40 use StaticSupportTrait;
42 protected bool $ready =
false;
44 private SaplingType $saplingType;
47 parent::__construct($idInfo, $name, $typeInfo);
48 $this->saplingType = $saplingType;
52 $w->bool($this->ready);
55 public function isReady() : bool{ return $this->ready; }
59 $this->ready = $ready;
63 private function canBeSupportedAt(
Block $block) : bool{
64 $supportBlock = $block->getSide(
Facing::DOWN);
65 return $supportBlock->
hasTypeTag(BlockTypeTags::DIRT) || $supportBlock->hasTypeTag(BlockTypeTags::MUD);
69 if($item instanceof
Fertilizer && $this->grow($player)){
83 $world = $this->position->getWorld();
84 if($world->getFullLightAt($this->position->getFloorX(), $this->position->getFloorY(), $this->position->getFloorZ()) >= 8 && mt_rand(1, 7) === 1){
89 $world->setBlock($this->position, $this);
94 private function grow(?
Player $player) : bool{
95 $random = new Random(mt_rand());
96 $tree = TreeFactory::get($random, $this->saplingType->getTreeType());
97 $transaction = $tree?->getBlockTransaction($this->position->getWorld(), $this->position->getFloorX(), $this->position->getFloorY(), $this->position->getFloorZ(), $random);
98 if($transaction ===
null){
102 $ev =
new StructureGrowEvent($this, $transaction, $player);
104 if(!$ev->isCancelled()){
105 return $transaction->apply();