43 use StaticSupportTrait;
45 public const MAX_AGE = 2;
47 private function canBeSupportedAt(
Block $block) :
bool{
48 return $block->
getSide(Facing::DOWN)->getTypeId() === BlockTypeIds::FARMLAND;
52 $widthTrim = $this->age === 0 ? 5 : 3;
53 $heightTrim = $this->age === 0 ? 13 : 11;
56 ->trim(Facing::UP, $heightTrim / 16)
57 ->squash(Axis::X, $widthTrim / 16)
58 ->squash(Axis::Z, $widthTrim / 16)
59 ->extend(Facing::DOWN, 1 / 16)
63 private function grow(?
Player $player) : bool{
64 if($this->age > self::MAX_AGE){
68 if($this->age === self::MAX_AGE){
69 $up = $this->getSide(Facing::UP);
70 if($up->getTypeId() !== BlockTypeIds::AIR){
74 $tx =
new BlockTransaction($this->position->getWorld());
75 $tx->addBlock($this->position, VanillaBlocks::DOUBLE_PITCHER_CROP()->setTop(
false));
76 $tx->addBlock($this->position->up(), VanillaBlocks::DOUBLE_PITCHER_CROP()->setTop(
true));
78 $ev =
new StructureGrowEvent($this, $tx, $player);
81 return !$ev->isCancelled() && $tx->apply();
84 return BlockEventHelper::grow($this, (clone $this)->setAge($this->age + 1), $player);
88 if($item instanceof
Fertilizer && $this->grow($player)){