diff --git a/src/block/BaseCoral.php b/src/block/BaseCoral.php index 73b2c48d6..3a6acd5d1 100644 --- a/src/block/BaseCoral.php +++ b/src/block/BaseCoral.php @@ -23,10 +23,10 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\BlockEventHelper; use pocketmine\block\utils\CoralType; use pocketmine\block\utils\CoralTypeTrait; use pocketmine\block\utils\SupportType; -use pocketmine\event\block\BlockDeathEvent; use pocketmine\item\Item; use function mt_rand; @@ -46,11 +46,7 @@ abstract class BaseCoral extends Transparent{ public function onScheduledUpdate() : void{ if(!$this->dead && !$this->isCoveredWithWater()){ - $ev = new BlockDeathEvent($this, $this->setDead(true)); - $ev->call(); - if(!$ev->isCancelled()){ - $this->position->getWorld()->setBlock($this->position, $ev->getNewState()); - } + BlockEventHelper::die($this, (clone $this)->setDead(true)); } } diff --git a/src/block/Cactus.php b/src/block/Cactus.php index 8fff294f6..0176d17bd 100644 --- a/src/block/Cactus.php +++ b/src/block/Cactus.php @@ -23,10 +23,10 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\BlockEventHelper; use pocketmine\block\utils\SupportType; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\entity\Entity; -use pocketmine\event\block\BlockGrowEvent; use pocketmine\event\entity\EntityDamageByBlockEvent; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\item\Item; @@ -111,12 +111,7 @@ class Cactus extends Transparent{ } $b = $world->getBlockAt($this->position->x, $this->position->y + $y, $this->position->z); if($b->getTypeId() === BlockTypeIds::AIR){ - $ev = new BlockGrowEvent($b, VanillaBlocks::CACTUS()); - $ev->call(); - if($ev->isCancelled()){ - break; - } - $world->setBlock($b->position, $ev->getNewState()); + BlockEventHelper::grow($b, VanillaBlocks::CACTUS(), null); }else{ break; } diff --git a/src/block/CaveVines.php b/src/block/CaveVines.php index e56b8b720..6ff934881 100644 --- a/src/block/CaveVines.php +++ b/src/block/CaveVines.php @@ -23,10 +23,10 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\BlockEventHelper; use pocketmine\block\utils\SupportType; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\entity\Entity; -use pocketmine\event\block\BlockGrowEvent; use pocketmine\item\Fertilizer; use pocketmine\item\Item; use pocketmine\item\VanillaItems; @@ -114,16 +114,12 @@ class CaveVines extends Flowable{ return true; } if($item instanceof Fertilizer){ - $ev = new BlockGrowEvent($this, (clone $this) + $newState = (clone $this) ->setBerries(true) - ->setHead(!$this->getSide(Facing::DOWN)->hasSameTypeId($this)) - ); - $ev->call(); - if($ev->isCancelled()){ - return false; + ->setHead(!$this->getSide(Facing::DOWN)->hasSameTypeId($this)); + if(BlockEventHelper::grow($this, $newState, $player)){ + $item->pop(); } - $item->pop(); - $this->position->getWorld()->setBlock($this->position, $ev->getNewState()); return true; } return false; @@ -141,16 +137,10 @@ class CaveVines extends Flowable{ if($world->isInWorld($growthPos->getFloorX(), $growthPos->getFloorY(), $growthPos->getFloorZ())){ $block = $world->getBlock($growthPos); if($block->getTypeId() === BlockTypeIds::AIR){ - $ev = new BlockGrowEvent($block, VanillaBlocks::CAVE_VINES() + $newState = VanillaBlocks::CAVE_VINES() ->setAge($this->age + 1) - ->setBerries(mt_rand(1, 9) === 1) - ); - - $ev->call(); - - if(!$ev->isCancelled()){ - $world->setBlock($growthPos, $ev->getNewState()); - } + ->setBerries(mt_rand(1, 9) === 1); + BlockEventHelper::grow($block, $newState, null); } } } diff --git a/src/block/CocoaBlock.php b/src/block/CocoaBlock.php index aafce3169..69f94eaf6 100644 --- a/src/block/CocoaBlock.php +++ b/src/block/CocoaBlock.php @@ -23,11 +23,11 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\BlockEventHelper; use pocketmine\block\utils\HorizontalFacingTrait; use pocketmine\block\utils\SupportType; use pocketmine\block\utils\WoodType; use pocketmine\data\runtime\RuntimeDataDescriber; -use pocketmine\event\block\BlockGrowEvent; use pocketmine\item\Fertilizer; use pocketmine\item\Item; use pocketmine\item\VanillaItems; @@ -123,12 +123,7 @@ class CocoaBlock extends Transparent{ if($this->age < self::MAX_AGE){ $block = clone $this; $block->age++; - $ev = new BlockGrowEvent($this, $block, $player); - $ev->call(); - if(!$ev->isCancelled()){ - $this->position->getWorld()->setBlock($this->position, $ev->getNewState()); - return true; - } + return BlockEventHelper::grow($this, $block, $player); } return false; } diff --git a/src/block/ConcretePowder.php b/src/block/ConcretePowder.php index 02fa31adb..635d3ff2c 100644 --- a/src/block/ConcretePowder.php +++ b/src/block/ConcretePowder.php @@ -23,11 +23,11 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\BlockEventHelper; use pocketmine\block\utils\ColoredTrait; use pocketmine\block\utils\DyeColor; use pocketmine\block\utils\Fallable; use pocketmine\block\utils\FallableTrait; -use pocketmine\event\block\BlockFormEvent; use pocketmine\math\Facing; class ConcretePowder extends Opaque implements Fallable{ @@ -43,11 +43,7 @@ class ConcretePowder extends Opaque implements Fallable{ public function onNearbyBlockChange() : void{ 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()); - } + BlockEventHelper::form($this, VanillaBlocks::CONCRETE()->setColor($this->color), $water); }else{ $this->startFalling(); } diff --git a/src/block/CoralBlock.php b/src/block/CoralBlock.php index b90246561..3aaf5b752 100644 --- a/src/block/CoralBlock.php +++ b/src/block/CoralBlock.php @@ -23,9 +23,9 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\BlockEventHelper; use pocketmine\block\utils\CoralType; use pocketmine\block\utils\CoralTypeTrait; -use pocketmine\event\block\BlockDeathEvent; use pocketmine\item\Item; use function mt_rand; @@ -55,11 +55,7 @@ final class CoralBlock extends Opaque{ } } if(!$hasWater){ - $ev = new BlockDeathEvent($this, $this->setDead(true)); - $ev->call(); - if(!$ev->isCancelled()){ - $world->setBlock($this->position, $ev->getNewState()); - } + BlockEventHelper::die($this, (clone $this)->setDead(true)); } } } diff --git a/src/block/Crops.php b/src/block/Crops.php index 8949e663b..d6e84c424 100644 --- a/src/block/Crops.php +++ b/src/block/Crops.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\BlockEventHelper; use pocketmine\data\runtime\RuntimeDataDescriber; -use pocketmine\event\block\BlockGrowEvent; use pocketmine\item\Fertilizer; use pocketmine\item\Item; use pocketmine\math\Facing; @@ -68,11 +68,7 @@ abstract class Crops extends Flowable{ if($block->age > self::MAX_AGE){ $block->age = self::MAX_AGE; } - - $ev = new BlockGrowEvent($this, $block, $player); - $ev->call(); - if(!$ev->isCancelled()){ - $this->position->getWorld()->setBlock($this->position, $ev->getNewState()); + if(BlockEventHelper::grow($this, $block, $player)){ $item->pop(); } @@ -96,11 +92,7 @@ abstract class Crops extends Flowable{ if($this->age < self::MAX_AGE && mt_rand(0, 2) === 1){ $block = clone $this; ++$block->age; - $ev = new BlockGrowEvent($this, $block); - $ev->call(); - if(!$ev->isCancelled()){ - $this->position->getWorld()->setBlock($this->position, $ev->getNewState()); - } + BlockEventHelper::grow($this, $block, null); } } } diff --git a/src/block/Fire.php b/src/block/Fire.php index 0a3b2e3e3..a39ef6b9c 100644 --- a/src/block/Fire.php +++ b/src/block/Fire.php @@ -23,10 +23,10 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\BlockEventHelper; use pocketmine\block\utils\SupportType; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\event\block\BlockBurnEvent; -use pocketmine\event\block\BlockSpreadEvent; use pocketmine\math\Facing; use pocketmine\world\format\Chunk; use pocketmine\world\World; @@ -225,13 +225,6 @@ class Fire extends BaseFire{ } private function spreadBlock(Block $block, Block $newState) : bool{ - $ev = new BlockSpreadEvent($block, $this, $newState); - $ev->call(); - if(!$ev->isCancelled()){ - $block->position->getWorld()->setBlock($block->position, $ev->getNewState()); - return true; - } - - return false; + return BlockEventHelper::spread($block, $newState, $this); } } diff --git a/src/block/FrostedIce.php b/src/block/FrostedIce.php index 38c552a95..039fe49f3 100644 --- a/src/block/FrostedIce.php +++ b/src/block/FrostedIce.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\BlockEventHelper; use pocketmine\data\runtime\RuntimeDataDescriber; -use pocketmine\event\block\BlockMeltEvent; use function mt_rand; class FrostedIce extends Ice{ @@ -97,11 +97,7 @@ class FrostedIce extends Ice{ private function tryMelt() : bool{ $world = $this->position->getWorld(); if($this->age >= self::MAX_AGE){ - $ev = new BlockMeltEvent($this, VanillaBlocks::WATER()); - $ev->call(); - if(!$ev->isCancelled()){ - $world->setBlock($this->position, $ev->getNewState()); - } + BlockEventHelper::melt($this, VanillaBlocks::WATER()); return true; } diff --git a/src/block/GlowLichen.php b/src/block/GlowLichen.php index 39ce512a6..84dec29ce 100644 --- a/src/block/GlowLichen.php +++ b/src/block/GlowLichen.php @@ -23,9 +23,9 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\BlockEventHelper; use pocketmine\block\utils\SupportType; use pocketmine\data\runtime\RuntimeDataDescriber; -use pocketmine\event\block\BlockSpreadEvent; use pocketmine\item\Fertilizer; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; @@ -166,14 +166,7 @@ class GlowLichen extends Transparent{ return false; } - $ev = new BlockSpreadEvent($replacedBlock, $this, $replacementBlock); - $ev->call(); - if(!$ev->isCancelled()){ - $world->setBlock($replacedBlock->getPosition(), $ev->getNewState()); - return true; - } - - return false; + return BlockEventHelper::spread($replacedBlock, $replacementBlock, $this); } /** diff --git a/src/block/Grass.php b/src/block/Grass.php index 54975d046..709dc6a9d 100644 --- a/src/block/Grass.php +++ b/src/block/Grass.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\BlockEventHelper; use pocketmine\block\utils\DirtType; -use pocketmine\event\block\BlockSpreadEvent; use pocketmine\item\Fertilizer; use pocketmine\item\Hoe; use pocketmine\item\Item; @@ -58,11 +58,7 @@ class Grass extends Opaque{ $lightAbove = $world->getFullLightAt($this->position->x, $this->position->y + 1, $this->position->z); if($lightAbove < 4 && $world->getBlockAt($this->position->x, $this->position->y + 1, $this->position->z)->getLightFilter() >= 2){ //grass dies - $ev = new BlockSpreadEvent($this, $this, VanillaBlocks::DIRT()); - $ev->call(); - if(!$ev->isCancelled()){ - $world->setBlock($this->position, $ev->getNewState(), false); - } + BlockEventHelper::spread($this, VanillaBlocks::DIRT(), $this); }elseif($lightAbove >= 9){ //try grass spread for($i = 0; $i < 4; ++$i){ @@ -80,11 +76,7 @@ class Grass extends Opaque{ continue; } - $ev = new BlockSpreadEvent($b, $this, VanillaBlocks::GRASS()); - $ev->call(); - if(!$ev->isCancelled()){ - $world->setBlock($b->position, $ev->getNewState(), false); - } + BlockEventHelper::spread($b, VanillaBlocks::GRASS(), $this); } } } diff --git a/src/block/Ice.php b/src/block/Ice.php index 41f60e3f9..ca0302f90 100644 --- a/src/block/Ice.php +++ b/src/block/Ice.php @@ -23,7 +23,7 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\event\block\BlockMeltEvent; +use pocketmine\block\utils\BlockEventHelper; use pocketmine\item\enchantment\VanillaEnchantments; use pocketmine\item\Item; use pocketmine\player\Player; @@ -53,11 +53,7 @@ class Ice extends Transparent{ public function onRandomTick() : void{ $world = $this->position->getWorld(); if($world->getHighestAdjacentBlockLight($this->position->x, $this->position->y, $this->position->z) >= 12){ - $ev = new BlockMeltEvent($this, VanillaBlocks::WATER()); - $ev->call(); - if(!$ev->isCancelled()){ - $world->setBlock($this->position, $ev->getNewState()); - } + BlockEventHelper::melt($this, VanillaBlocks::WATER()); } } diff --git a/src/block/Liquid.php b/src/block/Liquid.php index a56f666a2..e102540ec 100644 --- a/src/block/Liquid.php +++ b/src/block/Liquid.php @@ -23,11 +23,11 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\BlockEventHelper; use pocketmine\block\utils\MinimumCostFlowCalculator; use pocketmine\block\utils\SupportType; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\entity\Entity; -use pocketmine\event\block\BlockFormEvent; use pocketmine\event\block\BlockSpreadEvent; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; @@ -363,12 +363,8 @@ abstract class Liquid extends Transparent{ } protected function liquidCollide(Block $cause, Block $result) : bool{ - $ev = new BlockFormEvent($this, $result, $cause); - $ev->call(); - if(!$ev->isCancelled()){ - $world = $this->position->getWorld(); - $world->setBlock($this->position, $ev->getNewState()); - $world->addSound($this->position->add(0.5, 0.5, 0.5), new FizzSound(2.6 + (lcg_value() - lcg_value()) * 0.8)); + if(BlockEventHelper::form($this, $result, $cause)){ + $this->position->getWorld()->addSound($this->position->add(0.5, 0.5, 0.5), new FizzSound(2.6 + (lcg_value() - lcg_value()) * 0.8)); } return true; } diff --git a/src/block/Mycelium.php b/src/block/Mycelium.php index c87f89367..08b0b3e75 100644 --- a/src/block/Mycelium.php +++ b/src/block/Mycelium.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\BlockEventHelper; use pocketmine\block\utils\DirtType; -use pocketmine\event\block\BlockSpreadEvent; use pocketmine\item\Item; use pocketmine\math\Facing; use function mt_rand; @@ -54,11 +54,7 @@ class Mycelium extends Opaque{ $block = $world->getBlockAt($x, $y, $z); if($block instanceof Dirt && $block->getDirtType()->equals(DirtType::NORMAL())){ if($block->getSide(Facing::UP) instanceof Transparent){ - $ev = new BlockSpreadEvent($block, $this, VanillaBlocks::MYCELIUM()); - $ev->call(); - if(!$ev->isCancelled()){ - $world->setBlock($block->position, $ev->getNewState()); - } + BlockEventHelper::spread($block, VanillaBlocks::MYCELIUM(), $this); } } } diff --git a/src/block/NetherWartPlant.php b/src/block/NetherWartPlant.php index 6a8fe1f7a..d7e587441 100644 --- a/src/block/NetherWartPlant.php +++ b/src/block/NetherWartPlant.php @@ -23,9 +23,9 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\BlockEventHelper; use pocketmine\block\utils\FortuneDropHelper; use pocketmine\data\runtime\RuntimeDataDescriber; -use pocketmine\event\block\BlockGrowEvent; use pocketmine\item\Item; use pocketmine\math\Facing; use pocketmine\math\Vector3; @@ -76,11 +76,7 @@ class NetherWartPlant extends Flowable{ if($this->age < self::MAX_AGE && mt_rand(0, 10) === 0){ //Still growing $block = clone $this; $block->age++; - $ev = new BlockGrowEvent($this, $block); - $ev->call(); - if(!$ev->isCancelled()){ - $this->position->getWorld()->setBlock($this->position, $ev->getNewState()); - } + BlockEventHelper::grow($this, $block, null); } } diff --git a/src/block/SnowLayer.php b/src/block/SnowLayer.php index f561c8ff5..05fc88421 100644 --- a/src/block/SnowLayer.php +++ b/src/block/SnowLayer.php @@ -23,11 +23,11 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\BlockEventHelper; use pocketmine\block\utils\Fallable; use pocketmine\block\utils\FallableTrait; use pocketmine\block\utils\SupportType; use pocketmine\data\runtime\RuntimeDataDescriber; -use pocketmine\event\block\BlockMeltEvent; use pocketmine\item\Item; use pocketmine\item\VanillaItems; use pocketmine\math\AxisAlignedBB; @@ -105,11 +105,7 @@ class SnowLayer extends Flowable implements Fallable{ public function onRandomTick() : void{ $world = $this->position->getWorld(); if($world->getBlockLightAt($this->position->x, $this->position->y, $this->position->z) >= 12){ - $ev = new BlockMeltEvent($this, VanillaBlocks::AIR()); - $ev->call(); - if(!$ev->isCancelled()){ - $world->setBlock($this->position, $ev->getNewState()); - } + BlockEventHelper::melt($this, VanillaBlocks::AIR()); } } diff --git a/src/block/Stem.php b/src/block/Stem.php index 252b28aeb..7223572dd 100644 --- a/src/block/Stem.php +++ b/src/block/Stem.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\BlockEventHelper; use pocketmine\data\runtime\RuntimeDataDescriber; -use pocketmine\event\block\BlockGrowEvent; use pocketmine\item\Item; use pocketmine\math\Facing; use function array_rand; @@ -64,11 +64,7 @@ abstract class Stem extends Crops{ if($this->age < self::MAX_AGE){ $block = clone $this; ++$block->age; - $ev = new BlockGrowEvent($this, $block); - $ev->call(); - if(!$ev->isCancelled()){ - $world->setBlock($this->position, $ev->getNewState()); - } + BlockEventHelper::grow($this, $block, null); }else{ $grow = $this->getPlant(); foreach(Facing::HORIZONTAL as $side){ @@ -80,12 +76,7 @@ abstract class Stem extends Crops{ $facing = Facing::HORIZONTAL[array_rand(Facing::HORIZONTAL)]; $side = $this->getSide($facing); if($side->getTypeId() === BlockTypeIds::AIR && $side->getSide(Facing::DOWN)->hasTypeTag(BlockTypeTags::DIRT)){ - $ev = new BlockGrowEvent($side, $grow); - $ev->call(); - if(!$ev->isCancelled()){ - $world->setBlock($this->position, $this->setFacing($facing)); - $world->setBlock($side->position, $ev->getNewState()); - } + BlockEventHelper::grow($side, $grow, null); } } } diff --git a/src/block/Sugarcane.php b/src/block/Sugarcane.php index 4cc5989a7..3757e4577 100644 --- a/src/block/Sugarcane.php +++ b/src/block/Sugarcane.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\BlockEventHelper; use pocketmine\data\runtime\RuntimeDataDescriber; -use pocketmine\event\block\BlockGrowEvent; use pocketmine\item\Fertilizer; use pocketmine\item\Item; use pocketmine\math\Facing; @@ -60,13 +60,11 @@ class Sugarcane extends Flowable{ } $b = $world->getBlockAt($pos->x, $pos->y + $y, $pos->z); if($b->getTypeId() === BlockTypeIds::AIR){ - $ev = new BlockGrowEvent($b, VanillaBlocks::SUGARCANE(), $player); - $ev->call(); - if($ev->isCancelled()){ + if(BlockEventHelper::grow($b, VanillaBlocks::SUGARCANE(), $player)){ + $grew = true; + }else{ break; } - $world->setBlock($b->position, $ev->getNewState()); - $grew = true; }elseif(!$b->hasSameTypeId($this)){ break; } diff --git a/src/block/SweetBerryBush.php b/src/block/SweetBerryBush.php index 5ead39390..ef1169df5 100644 --- a/src/block/SweetBerryBush.php +++ b/src/block/SweetBerryBush.php @@ -23,11 +23,11 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\BlockEventHelper; use pocketmine\block\utils\FortuneDropHelper; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\entity\Entity; use pocketmine\entity\Living; -use pocketmine\event\block\BlockGrowEvent; use pocketmine\event\entity\EntityDamageByBlockEvent; use pocketmine\item\Fertilizer; use pocketmine\item\Item; @@ -87,15 +87,9 @@ class SweetBerryBush extends Flowable{ if($this->age < self::STAGE_MATURE && $item instanceof Fertilizer){ $block = clone $this; $block->age++; - - $ev = new BlockGrowEvent($this, $block, $player); - $ev->call(); - - if(!$ev->isCancelled()){ - $world->setBlock($this->position, $ev->getNewState()); + if(BlockEventHelper::grow($this, $block, $player)){ $item->pop(); } - }elseif(($dropAmount = $this->getBerryDropAmount()) > 0){ $world->setBlock($this->position, $this->setAge(self::STAGE_BUSH_NO_BERRIES)); $world->dropItem($this->position, $this->asItem()->setCount($dropAmount)); @@ -133,11 +127,7 @@ class SweetBerryBush extends Flowable{ if($this->age < self::STAGE_MATURE && mt_rand(0, 2) === 1){ $block = clone $this; ++$block->age; - $ev = new BlockGrowEvent($this, $block); - $ev->call(); - if(!$ev->isCancelled()){ - $this->position->getWorld()->setBlock($this->position, $ev->getNewState()); - } + BlockEventHelper::grow($this, $block, null); } } diff --git a/src/block/utils/BlockEventHelper.php b/src/block/utils/BlockEventHelper.php new file mode 100644 index 000000000..fc9b06d13 --- /dev/null +++ b/src/block/utils/BlockEventHelper.php @@ -0,0 +1,115 @@ +call(); + if($ev->isCancelled()){ + return false; + } + $newState = $ev->getNewState(); + } + + $position = $oldState->getPosition(); + $position->getWorld()->setBlock($position, $newState); + return true; + } + + public static function spread(Block $oldState, Block $newState, Block $source) : bool{ + if(BlockSpreadEvent::hasHandlers()){ + $ev = new BlockSpreadEvent($oldState, $source, $newState); + $ev->call(); + if($ev->isCancelled()){ + return false; + } + $newState = $ev->getNewState(); + } + + $position = $oldState->getPosition(); + $position->getWorld()->setBlock($position, $newState); + return true; + } + + public static function form(Block $oldState, Block $newState, Block $cause) : bool{ + if(BlockFormEvent::hasHandlers()){ + $ev = new BlockFormEvent($oldState, $newState, $cause); + $ev->call(); + if($ev->isCancelled()){ + return false; + } + $newState = $ev->getNewState(); + } + + $position = $oldState->getPosition(); + $position->getWorld()->setBlock($position, $newState); + return true; + } + + public static function melt(Block $oldState, Block $newState) : bool{ + if(BlockMeltEvent::hasHandlers()){ + $ev = new BlockMeltEvent($oldState, $newState); + $ev->call(); + if($ev->isCancelled()){ + return false; + } + $newState = $ev->getNewState(); + } + + $position = $oldState->getPosition(); + $position->getWorld()->setBlock($position, $newState); + return true; + } + + public static function die(Block $oldState, Block $newState) : bool{ + if(BlockDeathEvent::hasHandlers()){ + $ev = new BlockDeathEvent($oldState, $newState); + $ev->call(); + if($ev->isCancelled()){ + return false; + } + $newState = $ev->getNewState(); + } + + $position = $oldState->getPosition(); + $position->getWorld()->setBlock($position, $newState); + return true; + } +}