Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace test;
- use pocketmine\Server;
- use pocketmine\scheduler\AsyncTask;
- class TestAsyncTask extends AsyncTask {
- public $levelPath;
- public $pos1;
- public $pos2;
- /**
- * @param string $levelPath Путь к миру, пример /root/worlds/MyWorld
- * @param Vector2 $pos1 позиция чанка
- * @param Vector2 $pos2 позиция чанка
- */
- public function __construct($levelPath, $pos1, $pos2) {
- $this->levelPath = $levelPath;
- $this->pos1 = $pos1;
- $this->pos2 = $pos2;
- }
- public function getChunk($chunkX, $chunkY) {
- $region = new RegionLoader($this->levelPath, $chunkX >> 5, $chunkY >> 5);
- return $region->readChunk($chunkX - ($chunkX >> 5) * 32, $chunkY - ($chunkY >> 5) * 32);
- }
- 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(){
- $pos1 = $this->pos1;
- $pos2 = $this->pos2;
- if ($pos1->x < $pos2->x) {
- $minX = $pos1->x;
- $maxX = $pos2->x;
- }else {
- $minX = $pos2->x;
- $maxX = $pos1->x;
- }
- if ($pos1->y < $pos2->y) {
- $minY = $pos1->y;
- $maxY = $pos2->y;
- }else {
- $minY = $pos2->y;
- $maxY = $pos1->y;
- }
- for ($chunkX = $minX; $chunkX <= $maxX; $chunkX++) {
- for ($chunkY = $minY; $chunkY <= $maxY; $chunkY ++) {
- $chunk = $this->getChunk($chunkX, $chunkY);
- $this->countBlock($chunk);
- }
- }
- }
- public function onCompletion(Server $server){
- # code...
- }
- }