diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index f0a340bc9a..a283373686 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -74,7 +74,7 @@ namespace pocketmine { use raklib\RakLib; const VERSION = "Alpha_1.4dev"; - const API_VERSION = "1.2.0"; + const API_VERSION = "1.2.1"; const CODENAME = "絶好(Zekkou)ケーキ(Cake)"; const MINECRAFT_VERSION = "v0.9.5 alpha"; const PHP_VERSION = "5.5"; diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index ba7f0620b0..dedc4a2bc6 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -63,6 +63,7 @@ use pocketmine\network\protocol\SetTimePacket; use pocketmine\network\protocol\UpdateBlockPacket; use pocketmine\Player; use pocketmine\plugin\Plugin; +use pocketmine\scheduler\AsyncTask; use pocketmine\Server; use pocketmine\tile\Sign; use pocketmine\tile\Spawnable; @@ -1411,9 +1412,11 @@ class Level implements ChunkManager, Metadatable{ } unset($this->chunkSendQueue[$index]); }else{ - $task = $this->provider->requestChunkTask($x, $z); - $this->server->getScheduler()->scheduleAsyncTask($task); $this->chunkSendTasks[$index] = true; + $task = $this->provider->requestChunkTask($x, $z); + if($task instanceof AsyncTask){ + $this->server->getScheduler()->scheduleAsyncTask($task); + } } } } diff --git a/src/pocketmine/level/format/mcregion/ChunkRequestTask.php b/src/pocketmine/level/format/mcregion/ChunkRequestTask.php deleted file mode 100644 index badd3c4192..0000000000 --- a/src/pocketmine/level/format/mcregion/ChunkRequestTask.php +++ /dev/null @@ -1,123 +0,0 @@ -levelId = $levelId; - $this->chunkX = $chunkX; - $this->chunkZ = $chunkZ; - $chunk = $level->getChunk($chunkX, $chunkZ, false); - if(!($chunk instanceof Chunk)){ - throw new \Exception("Invalid Chunk sent"); - } - $this->blocks = $chunk->getBlockIdArray(); - $this->data = $chunk->getBlockDataArray(); - $this->skyLight = $chunk->getBlockSkyLightArray(); - $this->blockLight = $chunk->getBlockLightArray(); - $this->biomeIds = $chunk->getBiomeIdArray(); - $this->biomeColors = $chunk->getBiomeColorArray(); - - $tiles = ""; - $nbt = new NBT(NBT::LITTLE_ENDIAN); - foreach($chunk->getTiles() as $tile){ - if($tile instanceof Spawnable){ - $nbt->setData($tile->getSpawnCompound()); - $tiles .= $nbt->write(); - } - } - - $this->tiles = $tiles; - - $this->compressionLevel = Level::$COMPRESSION_LEVEL; - - } - - public function onRun(){ - $biomeColors = ""; - - foreach($this->biomeColors as $color){ - $biomeColors .= Binary::writeInt($color); - } - - $ordered = zlib_encode(Binary::writeLInt($this->chunkX) . Binary::writeLInt($this->chunkZ) . $this->blocks . $this->data . $this->skyLight . $this->blockLight . $this->biomeIds . $biomeColors . $this->tiles, ZLIB_ENCODING_DEFLATE, $this->compressionLevel); - - $this->setResult($ordered); - } - - public function getColumn(&$data, $x, $z){ - $i = ($z << 4) + $x; - $column = ""; - for($y = 0; $y < 128; ++$y){ - $column .= $data{($y << 8) + $i}; - } - return $column; - } - - public function getHalfColumn(&$data, $x, $z){ - $i = ($z << 3) + ($x >> 1); - $column = ""; - if(($x & 1) === 0){ - for($y = 0; $y < 128; $y += 2){ - $column .= ($data{($y << 7) + $i} & "\x0f") | chr((ord($data{(($y + 1) << 7) + $i}) & 0x0f) << 4); - } - }else{ - for($y = 0; $y < 128; $y += 2){ - $column .= chr((ord($data{($y << 7) + $i}) & 0xf0) >> 4) | ($data{(($y + 1) << 7) + $i} & "\xf0"); - } - } - return $column; - } - - public function onCompletion(Server $server){ - $level = $server->getLevel($this->levelId); - if($level instanceof Level and $this->hasResult()){ - $level->chunkRequestCallback($this->chunkX, $this->chunkZ, $this->getResult()); - } - } - -} \ No newline at end of file diff --git a/src/pocketmine/level/format/mcregion/McRegion.php b/src/pocketmine/level/format/mcregion/McRegion.php index 472951352e..1be3e67274 100644 --- a/src/pocketmine/level/format/mcregion/McRegion.php +++ b/src/pocketmine/level/format/mcregion/McRegion.php @@ -32,6 +32,8 @@ use pocketmine\nbt\tag\Int; use pocketmine\nbt\tag\Long; use pocketmine\nbt\tag\String; use pocketmine\Player; +use pocketmine\tile\Spawnable; +use pocketmine\utils\Binary; class McRegion extends BaseLevelProvider{ @@ -105,7 +107,40 @@ class McRegion extends BaseLevelProvider{ } public function requestChunkTask($x, $z){ - return new ChunkRequestTask($this, $this->getLevel()->getID(), $x, $z); + $chunk = $this->getChunk($x, $z, false); + if(!($chunk instanceof Chunk)){ + throw new \Exception("Invalid Chunk sent"); + } + + $tiles = ""; + $nbt = new NBT(NBT::LITTLE_ENDIAN); + foreach($chunk->getTiles() as $tile){ + if($tile instanceof Spawnable){ + $nbt->setData($tile->getSpawnCompound()); + $tiles .= $nbt->write(); + } + } + + $biomeColors = ""; + + foreach($chunk->getBiomeColorArray() as $color){ + $biomeColors .= Binary::writeInt($color); + } + + $ordered = zlib_encode( + Binary::writeLInt($x) . Binary::writeLInt($z) . + $chunk->getBlockIdArray() . + $chunk->getBlockDataArray() . + $chunk->getBlockSkyLightArray() . + $chunk->getBlockLightArray() . + $chunk->getBiomeIdArray() . + $biomeColors . + $tiles + , ZLIB_ENCODING_DEFLATE, Level::$COMPRESSION_LEVEL); + + $this->getLevel()->chunkRequestCallback($x, $z, $ordered); + + return null; } public function unloadChunks(){