From 2a982d48ad2056ac5aef3b7b930e2b6d751987b7 Mon Sep 17 00:00:00 2001 From: Alexey <45711510+Gaprix@users.noreply.github.com> Date: Sat, 17 Sep 2022 19:48:23 +0300 Subject: [PATCH] Do not always make the coral dead immediately after placement (#5149) --- src/block/BaseCoral.php | 35 ++++++++++++++++++++++------------- src/block/FloorCoralFan.php | 3 +++ src/block/WallCoralFan.php | 3 +++ 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/block/BaseCoral.php b/src/block/BaseCoral.php index f1a5a9e79..37aab85f9 100644 --- a/src/block/BaseCoral.php +++ b/src/block/BaseCoral.php @@ -27,6 +27,7 @@ use pocketmine\block\utils\CoralType; use pocketmine\block\utils\CoralTypeTrait; use pocketmine\block\utils\SupportType; use pocketmine\item\Item; +use function mt_rand; abstract class BaseCoral extends Transparent{ use CoralTypeTrait; @@ -38,20 +39,13 @@ abstract class BaseCoral extends Transparent{ public function onNearbyBlockChange() : void{ if(!$this->dead){ - $world = $this->position->getWorld(); + $this->position->getWorld()->scheduleDelayedBlockUpdate($this->position, mt_rand(40, 200)); + } + } - $hasWater = false; - foreach($this->position->sides() as $vector3){ - if($world->getBlock($vector3) instanceof Water){ - $hasWater = true; - break; - } - } - - //TODO: check water inside the block itself (not supported on the API yet) - if(!$hasWater){ - $world->setBlock($this->position, $this->setDead(true)); - } + public function onScheduledUpdate() : void{ + if(!$this->dead && !$this->isCoveredWithWater()){ + $this->position->getWorld()->setBlock($this->position, $this->setDead(true)); } } @@ -65,6 +59,21 @@ abstract class BaseCoral extends Transparent{ public function isSolid() : bool{ return false; } + protected function isCoveredWithWater() : bool{ + $world = $this->position->getWorld(); + + $hasWater = false; + foreach($this->position->sides() as $vector3){ + if($world->getBlock($vector3) instanceof Water){ + $hasWater = true; + break; + } + } + + //TODO: check water inside the block itself (not supported on the API yet) + return $hasWater; + } + protected function recalculateCollisionBoxes() : array{ return []; } public function getSupportType(int $facing) : SupportType{ diff --git a/src/block/FloorCoralFan.php b/src/block/FloorCoralFan.php index 250fe0e4c..a9d53c119 100644 --- a/src/block/FloorCoralFan.php +++ b/src/block/FloorCoralFan.php @@ -70,6 +70,9 @@ final class FloorCoralFan extends BaseCoral{ $this->axis = Axis::Z; } } + + $this->dead = !$this->isCoveredWithWater(); + return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } diff --git a/src/block/WallCoralFan.php b/src/block/WallCoralFan.php index b678d80ed..5349f78f2 100644 --- a/src/block/WallCoralFan.php +++ b/src/block/WallCoralFan.php @@ -49,6 +49,9 @@ final class WallCoralFan extends BaseCoral{ return false; } $this->facing = $face; + + $this->dead = !$this->isCoveredWithWater(); + return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); }