44 use StaticSupportTrait;
46 public const MAX_AGE = 2;
48 private function canBeSupportedAt(
Block $block) :
bool{
49 return $block->
getSide(Facing::DOWN)->getTypeId() === BlockTypeIds::FARMLAND;
53 $widthTrim = $this->age === 0 ? 5 : 3;
54 $heightTrim = $this->age === 0 ? 13 : 11;
57 ->trim(Facing::UP, $heightTrim / 16)
58 ->squash(Axis::X, $widthTrim / 16)
59 ->squash(Axis::Z, $widthTrim / 16)
60 ->extend(Facing::DOWN, 1 / 16)
64 private function grow(?
Player $player) : bool{
65 if($this->age > self::MAX_AGE){
69 if($this->age === self::MAX_AGE){
70 $up = $this->getSide(Facing::UP);
71 if($up->getTypeId() !== BlockTypeIds::AIR){
75 $tx =
new BlockTransaction($this->position->getWorld());
76 $tx->addBlock($this->position, VanillaBlocks::DOUBLE_PITCHER_CROP()->setTop(
false));
77 $tx->addBlock($this->position->up(), VanillaBlocks::DOUBLE_PITCHER_CROP()->setTop(
true));
79 $ev =
new StructureGrowEvent($this, $tx, $player);
82 return !$ev->isCancelled() && $tx->apply();
85 return BlockEventHelper::grow($this, (clone $this)->setAge($this->age + 1), $player);
89 if($item instanceof
Fertilizer && $this->grow($player)){