Advertisement
Gistrec

Async Enumeration All Chunks and Regions v2: SubChunk parse

Aug 2nd, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.11 KB | None | 0 0
  1. <?php
  2.  
  3. namespace test;
  4.  
  5. use pocketmine\Server;
  6. use pocketmine\scheduler\AsyncTask;
  7. use pocketmine\level\format\EmptySubChunk;
  8.  
  9. /*
  10.  * Пример перебора блоков в AsyncTask'е
  11.  * Как использовать:
  12.  * $task = new AsyncLoadChunk ("$dataPath/worlds/RPG");
  13.  * $serverScheduler->scheduleAsyncTask($task);
  14.  */
  15.  
  16. class Test3AsyncTask extends AsyncTask {
  17.  
  18.     public $levelPath;
  19.  
  20.     /**
  21.      * @param string  $levelPath  Путь к миру, пример /root/worlds/MyWorld
  22.      */
  23.     public function __construct($levelPath) {
  24.         $this->levelPath = $levelPath;
  25.         // print 'Перебираем все чанки в мире: ' . $levelPath . PHP_EOL;
  26.     }
  27.  
  28.  
  29.     public function parseSubChunk($subChunk) {
  30.         for ($x = 0; $x < 16; $x++) {
  31.             for ($z = 0; $z < 16; $z++) {
  32.                 for ($y = 0; $y < 16; $y++) {
  33.                     // var_dump($subChunk->getBlockId($x, $y, $z));
  34.                 }
  35.             }
  36.         }
  37.     }
  38.  
  39.  
  40.     public function onRun(){
  41.         foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->levelPath)) as $file){
  42.             if ($file->getFilename()[0] != 'r') continue;
  43.             $data = explode('.', $file->getFilename());
  44.             $regionX = $data[1];
  45.             $regionY = $data[2];
  46.             $region = new RegionLoader($this->levelPath, $regionX, $regionY);
  47.             for ($x = 0; $x < 32; $x++) {
  48.                 for ($y = 0; $y < 32; $y++) {
  49.                     if ($region->chunkExists($x, $y)) {
  50.                         $chunk = $region->readChunk($x, $y);
  51.                         if ($chunk != null) {
  52.                             foreach ($chunk->getSubChunks() as $subChunk) {
  53.                                 if (!$subChunk instanceof EmptySubChunk) {
  54.                                     $this->parseSubChunk($subChunk);
  55.                                 }
  56.                             }
  57.                         }
  58.                     }
  59.                 }
  60.             }
  61.         }
  62.     }
  63.  
  64.  
  65.     public function onCompletion(Server $server){
  66.         # code...
  67.    }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement