39 use StaticSupportTrait {
43 public const MAX_AGE = 15;
45 private function seekToBottom() :
Position{
46 $world = $this->position->getWorld();
47 $bottom = $this->position;
48 while(($next = $world->getBlock($bottom->down()))->hasSameTypeId($this)){
49 $bottom = $next->position;
54 private function grow(
Position $pos, ?
Player $player =
null) :
bool{
57 for($y = 1; $y < 3; ++$y){
58 if(!$world->isInWorld($pos->x, $pos->y + $y, $pos->z)){
61 $b = $world->getBlockAt($pos->x, $pos->y + $y, $pos->z);
62 if($b->getTypeId() === BlockTypeIds::AIR){
63 if(BlockEventHelper::grow($b, VanillaBlocks::SUGARCANE(), $player)){
68 }elseif(!$b->hasSameTypeId($this)){
73 $world->setBlock($pos, $this);
79 if($this->grow($this->seekToBottom(), $player)){
89 private function canBeSupportedAt(Block $block) : bool{
90 $supportBlock = $block->getSide(Facing::DOWN);
91 return $supportBlock->hasSameTypeId($this) ||
92 $supportBlock->hasTypeTag(BlockTypeTags::MUD) ||
93 $supportBlock->hasTypeTag(BlockTypeTags::DIRT) ||
94 $supportBlock->hasTypeTag(BlockTypeTags::SAND);
102 $down = $this->getSide(
Facing::DOWN);
103 if(!$down->hasSameTypeId($this)){
104 if(!$this->hasNearbyWater($down)){
105 $this->position->getWorld()->useBreakOn($this->position, createParticles: true);
109 if($this->age === self::MAX_AGE){
110 $this->grow($this->position);
113 $this->position->getWorld()->setBlock($this->position, $this);
119 $down = $blockReplace->getSide(
Facing::DOWN);
120 if($down->hasSameTypeId($this)){
121 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
125 foreach(Facing::HORIZONTAL as $side){
126 $sideBlock = $down->getSide($side);
127 if($sideBlock instanceof Water || $sideBlock instanceof FrostedIce){
128 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
135 private function hasNearbyWater(Block $down) : bool{
136 foreach($down->getHorizontalSides() as $sideBlock){
137 $blockId = $sideBlock->getTypeId();
138 if($blockId === BlockTypeIds::WATER || $blockId === BlockTypeIds::FROSTED_ICE){
146 $down = $this->getSide(
Facing::DOWN);
147 if(!$down->hasSameTypeId($this) && !$this->hasNearbyWater($down)){
148 $this->position->getWorld()->useBreakOn($this->position, createParticles: true);
150 $this->onSupportBlockChange();
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)