Added LevelProvider->getAllChunks() method

this returns a generator which yields known chunks. This will be used in the future for world format conversions.
This commit is contained in:
Dylan K. Taylor
2018-10-03 19:43:16 +01:00
parent 8a062f440d
commit 23132b899c
3 changed files with 44 additions and 0 deletions

View File

@ -535,4 +535,16 @@ class LevelDB extends BaseLevelProvider{
public function close(){
$this->db->close();
}
public function getAllChunks() : \Generator{
foreach($this->db->getIterator() as $key => $_){
if(strlen($key) === 9 and substr($key, -1) === self::TAG_VERSION){
$chunkX = Binary::readLInt(substr($key, 0, 4));
$chunkZ = Binary::readLInt(substr($key, 4, 4));
if(($chunk = $this->loadChunk($chunkX, $chunkZ)) !== null){
yield $chunk;
}
}
}
}
}