22declare(strict_types=1);
31use
function array_rand;
35 protected int $facing = Facing::UP;
39 $w->facingExcept($this->facing, Facing::DOWN);
42 public function getFacing() : int{ return $this->facing; }
46 if($facing ===
Facing::DOWN){
47 throw new \InvalidArgumentException(
"DOWN is not a valid facing for this block");
49 $this->facing = $facing;
53 abstract protected function getPlant() : Block;
56 if($this->facing !==
Facing::UP && !$this->getSide($this->facing)->hasSameTypeId($this->getPlant())){
57 $this->position->getWorld()->setBlock($this->position, $this->setFacing(Facing::UP));
59 parent::onNearbyBlockChange();
63 return $this->age < self::MAX_AGE || $this->facing ===
Facing::UP;
68 $world = $this->position->getWorld();
69 if($this->age < self::MAX_AGE){
72 BlockEventHelper::grow($this, $block,
null);
74 $grow = $this->getPlant();
75 foreach(Facing::HORIZONTAL as $side){
76 if($this->getSide($side)->hasSameTypeId($grow)){
81 $facing = Facing::HORIZONTAL[array_rand(Facing::HORIZONTAL)];
82 $side = $this->getSide($facing);
83 if($side->getTypeId() === BlockTypeIds::AIR && $side->getSide(Facing::DOWN)->hasTypeTag(BlockTypeTags::DIRT)){
84 if(BlockEventHelper::grow($side, $grow,
null)){
85 $this->position->getWorld()->setBlock($this->position, $this->setFacing($facing));
94 $this->asItem()->setCount(mt_rand(0, 2))
describeBlockOnlyState(RuntimeDataDescriber $w)
getDropsForCompatibleTool(Item $item)