22declare(strict_types=1);
26use pocketmine\block\utils\AgeableTrait;
29use pocketmine\block\utils\StaticSupportTrait;
44 use StaticSupportTrait;
46 public const STAGE_SAPLING = 0;
47 public const STAGE_BUSH_NO_BERRIES = 1;
48 public const STAGE_BUSH_SOME_BERRIES = 2;
49 public const STAGE_MATURE = 3;
50 public const MAX_AGE = self::STAGE_MATURE;
52 public function getBerryDropAmount() :
int{
53 if($this->age === self::STAGE_MATURE){
55 }elseif($this->age >= self::STAGE_BUSH_SOME_BERRIES){
69 private function canBeSupportedAt(
Block $block) : bool{
70 $supportBlock = $block->getSide(
Facing::DOWN);
71 return $this->canBeSupportedBy($supportBlock);
75 $world = $this->position->getWorld();
76 if($this->age < self::STAGE_MATURE && $item instanceof
Fertilizer){
79 if(BlockEventHelper::grow($this, $block, $player)){
82 }elseif(($dropAmount = $this->getBerryDropAmount()) > 0){
83 $world->setBlock($this->position, $this->setAge(self::STAGE_BUSH_NO_BERRIES));
84 $world->dropItem($this->position, $this->asItem()->setCount($dropAmount));
96 $count = match($this->age){
97 self::STAGE_MATURE => FortuneDropHelper::discrete($item, 2, 3),
98 self::STAGE_BUSH_SOME_BERRIES => FortuneDropHelper::discrete($item, 1, 2),
102 $this->asItem()->setCount($count)
107 return $this->age < self::STAGE_MATURE;
111 if($this->age < self::STAGE_MATURE && mt_rand(0, 2) === 1){
112 $block = clone $this;
114 BlockEventHelper::grow($this, $block,
null);
123 if($this->age >= self::STAGE_BUSH_NO_BERRIES && $entity instanceof
Living){
124 $entity->resetFallDistance();
onEntityInside(Entity $entity)
canBeSupportedBy(Block $block)
getDropsForCompatibleTool(Item $item)
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])