39 use StaticSupportTrait;
41 private bool $ready =
false;
44 $w->bool($this->ready);
47 public function isReady() : bool{ return $this->ready; }
51 $this->ready = $ready;
55 private function canBeSupportedAt(
Block $block) : bool{
56 $supportBlock = $block->getSide(
Facing::DOWN);
58 $supportBlock->
getTypeId() === BlockTypeIds::GRAVEL ||
59 $supportBlock->hasTypeTag(BlockTypeTags::DIRT) ||
60 $supportBlock->hasTypeTag(BlockTypeTags::MUD) ||
61 $supportBlock->hasTypeTag(BlockTypeTags::SAND);
65 if($item instanceof
Fertilizer || $item instanceof ItemBamboo){
66 if($this->grow($player)){
74 private function grow(?
Player $player) : bool{
75 $world = $this->position->getWorld();
76 if(!$world->getBlock($this->position->up())->canBeReplaced()){
80 $tx =
new BlockTransaction($world);
81 $bamboo = VanillaBlocks::BAMBOO();
82 $tx->addBlock($this->position, $bamboo)
83 ->addBlock($this->position->up(), (clone $bamboo)->setLeafSize(Bamboo::SMALL_LEAVES));
85 $ev =
new StructureGrowEvent($this, $tx, $player);
87 if($ev->isCancelled()){
99 $world = $this->position->getWorld();
101 $this->ready =
false;
102 if($world->getFullLight($this->position) < 9 || !$this->grow(
null)){
103 $world->setBlock($this->position, $this);
105 }elseif($world->getBlock($this->position->up())->canBeReplaced()){
107 $world->setBlock($this->position, $this);