39 use StaticSupportTrait;
41 public const MAX_AGE = 15;
43 private function seekToBottom() :
Position{
44 $world = $this->position->getWorld();
45 $bottom = $this->position;
46 while(($next = $world->getBlock($bottom->down()))->hasSameTypeId($this)){
47 $bottom = $next->position;
52 private function grow(
Position $pos, ?
Player $player =
null) :
bool{
55 for($y = 1; $y < 3; ++$y){
56 if(!$world->isInWorld($pos->x, $pos->y + $y, $pos->z)){
59 $b = $world->getBlockAt($pos->x, $pos->y + $y, $pos->z);
60 if($b->getTypeId() === BlockTypeIds::AIR){
61 if(BlockEventHelper::grow($b, VanillaBlocks::SUGARCANE(), $player)){
66 }elseif(!$b->hasSameTypeId($this)){
71 $world->setBlock($pos, $this);
77 if($this->grow($this->seekToBottom(), $player)){
87 private function canBeSupportedAt(Block $block) : bool{
88 $supportBlock = $block->getSide(Facing::DOWN);
89 return $supportBlock->hasSameTypeId($this) ||
90 $supportBlock->hasTypeTag(BlockTypeTags::MUD) ||
91 $supportBlock->hasTypeTag(BlockTypeTags::DIRT) ||
92 $supportBlock->hasTypeTag(BlockTypeTags::SAND);
100 if(!$this->getSide(
Facing::DOWN)->hasSameTypeId($this)){
101 if($this->age === self::MAX_AGE){
102 $this->grow($this->position);
105 $this->position->getWorld()->setBlock($this->position, $this);
111 $down = $blockReplace->getSide(
Facing::DOWN);
112 if($down->hasSameTypeId($this)){
113 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
117 foreach(Facing::HORIZONTAL as $side){
118 $sideBlock = $down->getSide($side);
119 if($sideBlock instanceof Water || $sideBlock instanceof FrostedIce){
120 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)