Do not always make the coral dead immediately after placement (#5149)

This commit is contained in:
Alexey 2022-09-17 19:48:23 +03:00 committed by GitHub
parent f80ffd8de0
commit 2a982d48ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 13 deletions

View File

@ -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();
$hasWater = false;
foreach($this->position->sides() as $vector3){
if($world->getBlock($vector3) instanceof Water){
$hasWater = true;
break;
$this->position->getWorld()->scheduleDelayedBlockUpdate($this->position, mt_rand(40, 200));
}
}
//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{

View File

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

View File

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