diff --git a/src/pocketmine/level/Explosion.php b/src/pocketmine/level/Explosion.php index cead7fc53..aba744dba 100644 --- a/src/pocketmine/level/Explosion.php +++ b/src/pocketmine/level/Explosion.php @@ -35,6 +35,7 @@ use pocketmine\event\entity\EntityExplodeEvent; use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\level\particle\HugeExplodeSeedParticle; +use pocketmine\level\utils\SubChunkIteratorManager; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Math; use pocketmine\math\Vector3; @@ -58,11 +59,16 @@ class Explosion{ /** @var Entity|Block */ private $what; + /** @var SubChunkIteratorManager */ + private $subChunkHandler; + public function __construct(Position $center, $size, $what = null){ $this->level = $center->getLevel(); $this->source = $center; $this->size = max($size, 0); $this->what = $what; + + $this->subChunkHandler = new SubChunkIteratorManager($this->level, false); } /** @@ -76,11 +82,6 @@ class Explosion{ $vector = new Vector3(0, 0, 0); $vBlock = new Position(0, 0, 0, $this->level); - $currentX = ((int) $this->source->x) >> 4; - $currentZ = ((int) $this->source->z) >> 4; - - $currentSubY = ((int) $this->source->y) >> 4; - $currentChunk = null; $currentSubChunk = null; @@ -103,33 +104,17 @@ class Explosion{ $vBlock->y = $pointerY >= $y ? $y : $y - 1; $vBlock->z = $pointerZ >= $z ? $z : $z - 1; - - if($currentChunk === null or ($vBlock->x >> 4) !== $currentX or ($vBlock->z >> 4) !== $currentZ){ - $currentX = $vBlock->x >> 4; - $currentZ = $vBlock->z >> 4; - $currentSubChunk = null; - - $currentChunk = $this->level->getChunk($currentX, $currentZ); - if($currentChunk === null){ - continue; - } + if(!$this->subChunkHandler->moveTo($vBlock->x, $vBlock->y, $vBlock->z)){ + continue; } - if($currentSubChunk === null or ($vBlock->y >> 4) !== $currentSubY){ - $currentSubY = $vBlock->y >> 4; - $currentSubChunk = $currentChunk->getSubChunk($currentSubY); - if($currentSubChunk === null){ - continue; - } - } - - $blockId = $currentSubChunk->getBlockId($vBlock->x & 0x0f, $vBlock->y & 0x0f, $vBlock->z & 0x0f); + $blockId = $this->subChunkHandler->currentSubChunk->getBlockId($vBlock->x & 0x0f, $vBlock->y & 0x0f, $vBlock->z & 0x0f); if($blockId !== 0){ $blastForce -= (BlockFactory::$blastResistance[$blockId] / 5 + 0.3) * $this->stepLen; if($blastForce > 0){ if(!isset($this->affectedBlocks[$index = Level::blockHash($vBlock->x, $vBlock->y, $vBlock->z)])){ - $this->affectedBlocks[$index] = BlockFactory::get($blockId, $currentSubChunk->getBlockData($vBlock->x & 0x0f, $vBlock->y & 0x0f, $vBlock->z & 0x0f), $vBlock); + $this->affectedBlocks[$index] = BlockFactory::get($blockId, $this->subChunkHandler->currentSubChunk->getBlockData($vBlock->x & 0x0f, $vBlock->y & 0x0f, $vBlock->z & 0x0f), $vBlock); } } }