Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace test;
- use pocketmine\Server;
- use pocketmine\scheduler\AsyncTask;
- use pocketmine\level\format\EmptySubChunk;
- /*
- * Пример перебора блоков в AsyncTask'е
- * Как использовать:
- * $task = new AsyncLoadChunk ("$dataPath/worlds/RPG");
- * $serverScheduler->scheduleAsyncTask($task);
- */
- class Test3AsyncTask extends AsyncTask {
- public $levelPath;
- /**
- * @param string $levelPath Путь к миру, пример /root/worlds/MyWorld
- */
- public function __construct($levelPath) {
- $this->levelPath = $levelPath;
- // print 'Перебираем все чанки в мире: ' . $levelPath . PHP_EOL;
- }
- public function parseSubChunk($subChunk) {
- for ($x = 0; $x < 16; $x++) {
- for ($z = 0; $z < 16; $z++) {
- for ($y = 0; $y < 16; $y++) {
- // var_dump($subChunk->getBlockId($x, $y, $z));
- }
- }
- }
- }
- 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);
- if ($chunk != null) {
- foreach ($chunk->getSubChunks() as $subChunk) {
- if (!$subChunk instanceof EmptySubChunk) {
- $this->parseSubChunk($subChunk);
- }
- }
- }
- }
- }
- }
- }
- }
- public function onCompletion(Server $server){
- # code...
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement