46 public const MAX_AGE = 1;
50 $this->describeAge($w);
61 ->trim(Facing::UP, 11 / 16)
62 ->squash(Axis::X, 3 / 16)
63 ->squash(Axis::Z, 3 / 16)
64 ->extend(Facing::DOWN, 1 / 16)
68 private function grow(?
Player $player) : bool{
69 if($this->age >= self::MAX_AGE){
73 $bottom = $this->top ? $this->getSide(Facing::DOWN) : $this;
74 $top = $this->top ? $this : $this->getSide(Facing::UP);
75 if($top->getTypeId() !== BlockTypeIds::AIR && !$top->hasSameTypeId($this)){
79 $newState = (clone $this)->setAge($this->age + 1);
81 $tx =
new BlockTransaction($this->position->getWorld());
82 $tx->addBlock($bottom->position, (clone $newState)->setTop(
false));
83 $tx->addBlock($top->position, (clone $newState)->setTop(
true));
85 $ev =
new StructureGrowEvent($bottom, $tx, $player);
88 return !$ev->isCancelled() && $tx->apply();
93 if($item instanceof
Fertilizer && $this->grow($player)){
102 return $this->age < self::MAX_AGE && !$this->top;