Adjust Sugar Cane to break when there is no water (#6486)

This commit is contained in:
bonbionseker 2024-11-15 19:27:27 +03:00 committed by GitHub
parent a75d4687ce
commit 8474eaf5f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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();
}
}
}