Explosion: allow the normal blockupdate mechanism to deal with explosions

in PM4, all blockupdates are buffered, so the old 7x performance penalty that used to be incurred by doing this is no longer a problem.
Also, this actually reduces the overhead of explosions themselves by moving the onNearbyBlockChange() burden off explodeB() and into the main world ticking function.
This commit is contained in:
Dylan K. Taylor 2021-09-12 15:45:02 +01:00
parent 5ddd94b7e8
commit ace8841d5d
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -28,14 +28,12 @@ use pocketmine\block\BlockFactory;
use pocketmine\block\TNT;
use pocketmine\block\VanillaBlocks;
use pocketmine\entity\Entity;
use pocketmine\event\block\BlockUpdateEvent;
use pocketmine\event\entity\EntityDamageByBlockEvent;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityExplodeEvent;
use pocketmine\item\ItemFactory;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\world\format\SubChunk;
use pocketmine\world\particle\HugeExplodeSeedParticle;
@ -227,29 +225,7 @@ class Explosion{
if(($t = $this->world->getTileAt($pos->x, $pos->y, $pos->z)) !== null){
$t->onBlockDestroyed(); //needed to create drops for inventories
}
$this->world->setBlockAt($pos->x, $pos->y, $pos->z, $airBlock, false); //TODO: should updating really be disabled here?
$this->world->updateAllLight($pos->x, $pos->y, $pos->z);
}
}
foreach($this->affectedBlocks as $block){
$pos = $block->getPosition();
foreach(Facing::ALL as $side){
$sideBlock = $pos->getSide($side);
if(!$this->world->isInWorld($sideBlock->x, $sideBlock->y, $sideBlock->z)){
continue;
}
if(!isset($this->affectedBlocks[$index = World::blockHash($sideBlock->x, $sideBlock->y, $sideBlock->z)]) and !isset($updateBlocks[$index])){
$ev = new BlockUpdateEvent($this->world->getBlockAt($sideBlock->x, $sideBlock->y, $sideBlock->z));
$ev->call();
if(!$ev->isCancelled()){
foreach($this->world->getNearbyEntities(AxisAlignedBB::one()->offset($sideBlock->x, $sideBlock->y, $sideBlock->z)->expand(1, 1, 1)) as $entity){
$entity->onNearbyBlockChange();
}
$ev->getBlock()->onNearbyBlockChange();
}
$updateBlocks[$index] = true;
}
$this->world->setBlockAt($pos->x, $pos->y, $pos->z, $airBlock);
}
}