diff --git a/src/block/ConcretePowder.php b/src/block/ConcretePowder.php index cfe2ccec6..8a39daa0d 100644 --- a/src/block/ConcretePowder.php +++ b/src/block/ConcretePowder.php @@ -42,8 +42,8 @@ class ConcretePowder extends Opaque implements Fallable{ } public function onNearbyBlockChange() : void{ - if(($block = $this->checkAdjacentWater()) !== null){ - $ev = new BlockFormEvent($this, $block); + if(($water = $this->getAdjacentWater()) !== null){ + $ev = new BlockFormEvent($this, VanillaBlocks::CONCRETE()->setColor($this->color), $water); $ev->call(); if(!$ev->isCancelled()){ $this->position->getWorld()->setBlock($this->position, $ev->getNewState()); @@ -54,16 +54,20 @@ class ConcretePowder extends Opaque implements Fallable{ } public function tickFalling() : ?Block{ - return $this->checkAdjacentWater(); + if ($this->getAdjacentWater() === null) { + return null; + } + return VanillaBlocks::CONCRETE()->setColor($this->color); } - private function checkAdjacentWater() : ?Block{ + private function getAdjacentWater() : ?Water{ foreach(Facing::ALL as $i){ if($i === Facing::DOWN){ continue; } - if($this->getSide($i) instanceof Water){ - return VanillaBlocks::CONCRETE()->setColor($this->color); + $block = $this->getSide($i); + if($block instanceof Water){ + return $block; } } diff --git a/src/block/Liquid.php b/src/block/Liquid.php index b14457f25..769fc039a 100644 --- a/src/block/Liquid.php +++ b/src/block/Liquid.php @@ -366,7 +366,7 @@ abstract class Liquid extends Transparent{ } protected function liquidCollide(Block $cause, Block $result) : bool{ - $ev = new BlockFormEvent($this, $result); + $ev = new BlockFormEvent($this, $result, $cause); $ev->call(); if(!$ev->isCancelled()){ $world = $this->position->getWorld(); diff --git a/src/event/block/BlockFormEvent.php b/src/event/block/BlockFormEvent.php index 5211e3a0f..95c484113 100644 --- a/src/event/block/BlockFormEvent.php +++ b/src/event/block/BlockFormEvent.php @@ -23,10 +23,26 @@ declare(strict_types=1); namespace pocketmine\event\block; +use pocketmine\block\Block; + /** * Called when a new block forms, usually as the result of some action. * This could be things like obsidian forming due to collision of lava and water. */ class BlockFormEvent extends BaseBlockChangeEvent{ + public function __construct( + Block $block, + Block $newState, + private Block $causingBlock + ){ + parent::__construct($block, $newState); + } + + /** + * Returns the block which caused the target block to form into a new state. + */ + public function getCausingBlock() : Block{ + return $this->causingBlock; + } }