diff --git a/src/pocketmine/level/format/Chunk.php b/src/pocketmine/level/format/Chunk.php index 0a6471d5c..e265ebc23 100644 --- a/src/pocketmine/level/format/Chunk.php +++ b/src/pocketmine/level/format/Chunk.php @@ -328,7 +328,7 @@ interface Chunk{ * @return SubChunk */ public function getSubChunk(int $fY, bool $generateNew = false) : SubChunk; - + /** * @param int $fY 0-15 * @param SubChunk $subChunk @@ -348,19 +348,19 @@ interface Chunk{ * @return bool */ public function getHighestSubChunkIndex() : int; - + /** * Returns the number of subchunks that need sending * * @return int */ public function getSubChunkSendCount() : int; - + /** * Disposes of empty subchunks */ public function pruneEmptySubChunks(); - + /** * Serializes the chunk to network data * diff --git a/src/pocketmine/level/format/generic/EmptySubChunk.php b/src/pocketmine/level/format/generic/EmptySubChunk.php index 423a65197..acdbccce7 100644 --- a/src/pocketmine/level/format/generic/EmptySubChunk.php +++ b/src/pocketmine/level/format/generic/EmptySubChunk.php @@ -25,7 +25,7 @@ use pocketmine\utils\ChunkException; class EmptySubChunk extends SubChunk{ protected $y; - + public function __construct(int $y){ $this->y = $y; } @@ -73,19 +73,19 @@ class EmptySubChunk extends SubChunk{ public function setBlockLight(int $x, int $y, int $z, int $level) : bool{ return false; } - + public function getBlockIdColumn(int $x, int $z) : string{ return "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; } - + public function getBlockDataColumn(int $x, int $z) : string{ return "\x00\x00\x00\x00\x00\x00\x00\x00"; } - + public function getBlockLightColumn(int $x, int $z) : string{ return "\x00\x00\x00\x00\x00\x00\x00\x00"; } - + public function getSkyLightColumn(int $x, int $z) : string{ return "\xff\xff\xff\xff\xff\xff\xff\xff"; } diff --git a/src/pocketmine/level/format/generic/GenericChunk.php b/src/pocketmine/level/format/generic/GenericChunk.php index bd903533b..8e3ed9a2d 100644 --- a/src/pocketmine/level/format/generic/GenericChunk.php +++ b/src/pocketmine/level/format/generic/GenericChunk.php @@ -620,7 +620,8 @@ class GenericChunk implements Chunk{ } $result .= pack("v*", ...$this->heightMap) . $this->biomeIds - . chr(0); //border block array count (TODO) + . chr(0); //border block array count + //Border block entry format: 1 byte (4 bits X, 4 bits Z). These are however useless since they crash the regular client. $extraData = new BinaryStream(); $extraData->putVarInt(count($this->extraData)); //WHY, Mojang, WHY @@ -695,6 +696,7 @@ class GenericChunk implements Chunk{ return $chunk; } + //TODO: get rid of this public static function getEmptyChunk(int $x, int $z, LevelProvider $provider = null) : Chunk{ return new GenericChunk($provider, $x, $z); } @@ -750,6 +752,13 @@ class GenericChunk implements Chunk{ return $result; } + /** + * Converts pre-MCPE-1.0 biome colour array to biome ID array. RIP BiomeColors :( + * + * @param int[256] $array of biome colour values + * + * @return string + */ public static function convertBiomeColours(array $array) : string{ $result = str_repeat("\x00", 256); foreach($array as $i => $colour){ diff --git a/src/pocketmine/level/format/generic/SubChunk.php b/src/pocketmine/level/format/generic/SubChunk.php index 62e4af0e7..630bfaae3 100644 --- a/src/pocketmine/level/format/generic/SubChunk.php +++ b/src/pocketmine/level/format/generic/SubChunk.php @@ -45,7 +45,7 @@ class SubChunk{ self::assignData($this->blockLight, $blockLight, 2048); self::assignData($this->skyLight, $skyLight, 2048); } - + public function getY() : int{ return $this->y; } @@ -168,19 +168,19 @@ class SubChunk{ return -1; //highest block not in this subchunk } - + public function getBlockIdColumn(int $x, int $z) : string{ return substr($this->ids, (($x << 8) | ($z << 4)), 16); } - + public function getBlockDataColumn(int $x, int $z) : string{ return substr($this->data, (($x << 7) | ($z << 3)), 8); } - + public function getBlockLightColumn(int $x, int $z) : string{ return substr($this->blockLight, (($x << 7) | ($z << 3)), 8); } - + public function getSkyLightColumn(int $x, int $z) : string{ return substr($this->skyLight, (($x << 7) | ($z << 3)), 8); } diff --git a/src/pocketmine/level/format/mcregion/McRegion.php b/src/pocketmine/level/format/mcregion/McRegion.php index e4c422222..bb9edce03 100644 --- a/src/pocketmine/level/format/mcregion/McRegion.php +++ b/src/pocketmine/level/format/mcregion/McRegion.php @@ -35,7 +35,7 @@ use pocketmine\utils\ChunkException; use pocketmine\utils\MainLogger; class McRegion extends BaseLevelProvider{ - + public static function nbtSerialize(GenericChunk $chunk) : string{ $nbt = new CompoundTag("Level", []); $nbt->xPos = new IntTag("xPos", $chunk->getX()); @@ -62,7 +62,7 @@ class McRegion extends BaseLevelProvider{ } } } - + $nbt->Blocks = new ByteArrayTag("Blocks", $ids); $nbt->Data = new ByteArrayTag("Data", $data); $nbt->SkyLight = new ByteArrayTag("SkyLight", $skyLight); @@ -100,7 +100,7 @@ class McRegion extends BaseLevelProvider{ return $writer->writeCompressed(ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL); } - + public static function nbtDeserialize(string $data, LevelProvider $provider = null){ $nbt = new NBT(NBT::BIG_ENDIAN); try{ @@ -111,9 +111,9 @@ class McRegion extends BaseLevelProvider{ if(!isset($chunk->Level) or !($chunk->Level instanceof CompoundTag)){ return null; } - + $chunk = $chunk->Level; - + $subChunks = []; $fullIds = $chunk->Blocks instanceof ByteArrayTag ? $chunk->Blocks->getValue() : str_repeat("\x00", 32768); $fullData = $chunk->Data instanceof ByteArrayTag ? $chunk->Data->getValue() : ($half = str_repeat("\x00", 16384)); @@ -155,7 +155,7 @@ class McRegion extends BaseLevelProvider{ }else{ $biomeIds = ""; } - + $result = new GenericChunk( $provider, $chunk["xPos"],