BlockFormEvent: Added getCausingBlock() method (#5226)

This commit is contained in:
Colin
2022-08-15 17:26:48 +02:00
committed by GitHub
parent cb020988d4
commit 304bb84af2
3 changed files with 27 additions and 7 deletions

View File

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