Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace test;
- use pocketmine\Server;
- use pocketmine\scheduler\AsyncTask;
- /*
- * Пример перебора блоков в AsyncTask'е
- * Как использовать:
- * $task = new AsyncLoadChunk ("$dataPath/worlds/RPG");
- * $serverScheduler->scheduleAsyncTask($task);
- */
- class AsyncLoadChunk extends AsyncTask {
- public $levelPath;
- /**
- * @param string $levelPath Путь к миру, пример /root/worlds/MyWorld
- */
- public function __construct($levelPath) {
- $this->levelPath = $levelPath;
- print 'Перебираем все чанки в мире: ' + $levelPath;
- }
- public function countBlock($chunk) {
- for ($x = 0; $x < 16; $x++) {
- for ($z = 0; $z < 16; $z++) {
- for ($y = 0; $y < 256; $y++) {
- # code...
- }
- }
- }
- }
- public function onRun(){
- foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->levelPath)) as $file){
- if ($file->getFilename()[0] != 'r') continue;
- $data = explode(".", $file->getFilename());
- $regionX = $data[1];
- $regionY = $data[2];
- $region = new RegionLoader($this->levelPath, $regionX, $regionY);
- for ($x = 0; $x < 32; $x++) {
- for ($y = 0; $y < 32; $y++) {
- if ($region->chunkExists($x, $y)) {
- $chunk = $region->readChunk($x, $y);
- $this->countBlock($chunk);
- }
- }
- }
- }
- }
- public function onCompletion(Server $server){
- # code...
- }
- }
Advertisement