mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
BlockFormEvent: Added getCausingBlock() method (#5226)
This commit is contained in:
parent
cb020988d4
commit
304bb84af2
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user