diff --git a/src/pocketmine/level/utils/SubChunkIteratorManager.php b/src/pocketmine/level/utils/SubChunkIteratorManager.php new file mode 100644 index 000000000..91300e5dd --- /dev/null +++ b/src/pocketmine/level/utils/SubChunkIteratorManager.php @@ -0,0 +1,78 @@ +level = $level; + $this->allocateEmptySubs = $allocateEmptySubs; + } + + public function moveTo(int $x, int $y, int $z) : bool{ + if($this->currentChunk === null or $this->currentX !== ($x >> 4) or $this->currentZ !== ($z >> 4)){ + $this->currentX = $x >> 4; + $this->currentZ = $z >> 4; + $this->currentSubChunk = null; + + $this->currentChunk = $this->level->getChunk($this->currentX, $this->currentZ); + if($this->currentChunk === null){ + return false; + } + } + + if($this->currentSubChunk === null or $this->currentY !== ($y >> 4)){ + $this->currentY = $y >> 4; + + $this->currentSubChunk = $this->currentChunk->getSubChunk($y >> 4, $this->allocateEmptySubs); + if($this->currentSubChunk instanceof EmptySubChunk){ + return false; + } + } + + return true; + } + +} \ No newline at end of file