mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-11 04:17:48 +00:00
Liquid: Add events to allow controlling flow and fusion (#2547)
This commit is contained in:
parent
e4223bb7dc
commit
e3f46987f5
@ -24,6 +24,8 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\entity\Entity;
|
use pocketmine\entity\Entity;
|
||||||
|
use pocketmine\event\block\BlockFormEvent;
|
||||||
|
use pocketmine\event\block\BlockSpreadEvent;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\level\Level;
|
use pocketmine\level\Level;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
@ -294,14 +296,18 @@ abstract class Liquid extends Transparent{
|
|||||||
|
|
||||||
protected function flowIntoBlock(Block $block, int $newFlowDecay) : void{
|
protected function flowIntoBlock(Block $block, int $newFlowDecay) : void{
|
||||||
if($this->canFlowInto($block) and !($block instanceof Liquid)){
|
if($this->canFlowInto($block) and !($block instanceof Liquid)){
|
||||||
|
$ev = new BlockSpreadEvent($block, $this, BlockFactory::get($this->getId(), $newFlowDecay));
|
||||||
|
$ev->call();
|
||||||
|
if(!$ev->isCancelled()){
|
||||||
if($block->getId() > 0){
|
if($block->getId() > 0){
|
||||||
$this->level->useBreakOn($block);
|
$this->level->useBreakOn($block);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->level->setBlock($block, BlockFactory::get($this->getId(), $newFlowDecay), true, true);
|
$this->level->setBlock($block, $ev->getNewState(), true, true);
|
||||||
$this->level->scheduleDelayedBlockUpdate($block, $this->tickRate());
|
$this->level->scheduleDelayedBlockUpdate($block, $this->tickRate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function calculateFlowCost(int $blockX, int $blockY, int $blockZ, int $accumulatedCost, int $maxCost, int $originOpposite, int $lastOpposite) : int{
|
private function calculateFlowCost(int $blockX, int $blockY, int $blockZ, int $accumulatedCost, int $maxCost, int $originOpposite, int $lastOpposite) : int{
|
||||||
$cost = 1000;
|
$cost = 1000;
|
||||||
@ -425,10 +431,12 @@ abstract class Liquid extends Transparent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function liquidCollide(Block $cause, Block $result) : bool{
|
protected function liquidCollide(Block $cause, Block $result) : bool{
|
||||||
//TODO: add events
|
$ev = new BlockFormEvent($this, $result);
|
||||||
|
$ev->call();
|
||||||
$this->level->setBlock($this, $result, true, true);
|
if(!$ev->isCancelled()){
|
||||||
|
$this->level->setBlock($this, $ev->getNewState(), true, true);
|
||||||
$this->level->broadcastLevelSoundEvent($this->add(0.5, 0.5, 0.5), LevelSoundEventPacket::SOUND_FIZZ, (int) ((2.6 + (lcg_value() - lcg_value()) * 0.8) * 1000));
|
$this->level->broadcastLevelSoundEvent($this->add(0.5, 0.5, 0.5), LevelSoundEventPacket::SOUND_FIZZ, (int) ((2.6 + (lcg_value() - lcg_value()) * 0.8) * 1000));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user