From 8474eaf5f105ed93bae462cdcb370768098ee4bf Mon Sep 17 00:00:00 2001 From: bonbionseker <167460154+bonbionseker@users.noreply.github.com> Date: Fri, 15 Nov 2024 19:27:27 +0300 Subject: [PATCH] Adjust Sugar Cane to break when there is no water (#6486) --- src/block/Sugarcane.php | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/block/Sugarcane.php b/src/block/Sugarcane.php index 97b4aee9c..2da2dc9b9 100644 --- a/src/block/Sugarcane.php +++ b/src/block/Sugarcane.php @@ -36,7 +36,9 @@ use pocketmine\world\Position; class Sugarcane extends Flowable{ use AgeableTrait; - use StaticSupportTrait; + use StaticSupportTrait { + onNearbyBlockChange as onSupportBlockChange; + } public const MAX_AGE = 15; @@ -97,7 +99,13 @@ class Sugarcane extends Flowable{ } public function onRandomTick() : void{ - if(!$this->getSide(Facing::DOWN)->hasSameTypeId($this)){ + $down = $this->getSide(Facing::DOWN); + if(!$down->hasSameTypeId($this)){ + if(!$this->hasNearbyWater($down)){ + $this->position->getWorld()->useBreakOn($this->position, createParticles: true); + return; + } + if($this->age === self::MAX_AGE){ $this->grow($this->position); }else{ @@ -123,4 +131,23 @@ class Sugarcane extends Flowable{ return false; } + + private function hasNearbyWater(Block $down) : bool{ + foreach($down->getHorizontalSides() as $sideBlock){ + $blockId = $sideBlock->getTypeId(); + if($blockId === BlockTypeIds::WATER || $blockId === BlockTypeIds::FROSTED_ICE){ + return true; + } + } + return false; + } + + public function onNearbyBlockChange() : void{ + $down = $this->getSide(Facing::DOWN); + if(!$down->hasSameTypeId($this) && !$this->hasNearbyWater($down)){ + $this->position->getWorld()->useBreakOn($this->position, createParticles: true); + }else{ + $this->onSupportBlockChange(); + } + } }