Gistrec

Async Enumeration Chunk

Aug 1st, 2017
260
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.88 KB | None | 0 0
  1. <?php
  2.  
  3. namespace test;
  4.  
  5.  
  6. use pocketmine\Server;
  7. use pocketmine\scheduler\AsyncTask;
  8.  
  9.  
  10. class TestAsyncTask extends AsyncTask {
  11.  
  12.     public $levelPath;
  13.  
  14.     public $pos1;
  15.     public $pos2;
  16.  
  17.     /**
  18.      * @param string  $levelPath  Путь к миру, пример /root/worlds/MyWorld
  19.      * @param Vector2 $pos1       позиция чанка
  20.      * @param Vector2 $pos2       позиция чанка
  21.      */
  22.     public function __construct($levelPath, $pos1, $pos2) {
  23.         $this->levelPath = $levelPath;
  24.         $this->pos1 = $pos1;
  25.         $this->pos2 = $pos2;
  26.     }
  27.  
  28.  
  29.     public function getChunk($chunkX, $chunkY) {
  30.         $region = new RegionLoader($this->levelPath, $chunkX >> 5, $chunkY >> 5);
  31.         return $region->readChunk($chunkX - ($chunkX >> 5) * 32, $chunkY - ($chunkY >> 5) * 32);
  32.     }
  33.  
  34.  
  35.     public function countBlock($chunk) {
  36.         for ($x = 0; $x < 16; $x++) {
  37.             for ($z = 0; $z < 16; $z++) {
  38.                 for ($y = 0; $y < 256; $y++) {
  39.                     # code...
  40.                }
  41.             }
  42.         }
  43.     }
  44.  
  45.  
  46.     public function onRun(){
  47.         $pos1 = $this->pos1;
  48.         $pos2 = $this->pos2;
  49.         if ($pos1->x < $pos2->x) {
  50.             $minX = $pos1->x;
  51.             $maxX = $pos2->x;
  52.         }else {
  53.             $minX = $pos2->x;
  54.             $maxX = $pos1->x;
  55.         }
  56.         if ($pos1->y < $pos2->y) {
  57.             $minY = $pos1->y;
  58.             $maxY = $pos2->y;
  59.         }else {
  60.             $minY = $pos2->y;
  61.             $maxY = $pos1->y;
  62.         }
  63.         for ($chunkX = $minX; $chunkX <= $maxX; $chunkX++) {
  64.             for ($chunkY = $minY; $chunkY <= $maxY; $chunkY ++) {
  65.                 $chunk = $this->getChunk($chunkX, $chunkY);
  66.                 $this->countBlock($chunk);
  67.             }
  68.         }
  69.     }
  70.  
  71.  
  72.     public function onCompletion(Server $server){
  73.         # code...
  74.    }
  75. }
Comments
  • User was banned
Add Comment
Please, Sign In to add comment