mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-06 20:07:09 +00:00
Do not always make the coral dead immediately after placement (#5149)
This commit is contained in:
parent
f80ffd8de0
commit
2a982d48ad
@ -27,6 +27,7 @@ use pocketmine\block\utils\CoralType;
|
|||||||
use pocketmine\block\utils\CoralTypeTrait;
|
use pocketmine\block\utils\CoralTypeTrait;
|
||||||
use pocketmine\block\utils\SupportType;
|
use pocketmine\block\utils\SupportType;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
|
use function mt_rand;
|
||||||
|
|
||||||
abstract class BaseCoral extends Transparent{
|
abstract class BaseCoral extends Transparent{
|
||||||
use CoralTypeTrait;
|
use CoralTypeTrait;
|
||||||
@ -38,20 +39,13 @@ abstract class BaseCoral extends Transparent{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!$this->dead){
|
if(!$this->dead){
|
||||||
$world = $this->position->getWorld();
|
$this->position->getWorld()->scheduleDelayedBlockUpdate($this->position, mt_rand(40, 200));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$hasWater = false;
|
public function onScheduledUpdate() : void{
|
||||||
foreach($this->position->sides() as $vector3){
|
if(!$this->dead && !$this->isCoveredWithWater()){
|
||||||
if($world->getBlock($vector3) instanceof Water){
|
$this->position->getWorld()->setBlock($this->position, $this->setDead(true));
|
||||||
$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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,6 +59,21 @@ abstract class BaseCoral extends Transparent{
|
|||||||
|
|
||||||
public function isSolid() : bool{ return false; }
|
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 []; }
|
protected function recalculateCollisionBoxes() : array{ return []; }
|
||||||
|
|
||||||
public function getSupportType(int $facing) : SupportType{
|
public function getSupportType(int $facing) : SupportType{
|
||||||
|
@ -70,6 +70,9 @@ final class FloorCoralFan extends BaseCoral{
|
|||||||
$this->axis = Axis::Z;
|
$this->axis = Axis::Z;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->dead = !$this->isCoveredWithWater();
|
||||||
|
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +49,9 @@ final class WallCoralFan extends BaseCoral{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->facing = $face;
|
$this->facing = $face;
|
||||||
|
|
||||||
|
$this->dead = !$this->isCoveredWithWater();
|
||||||
|
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user