22declare(strict_types=1);
24namespace pocketmine\world\format\io\region;
40use pocketmine\world\format\PalettedBlockArray;
43use
function zlib_decode;
50 $decompressed = @zlib_decode($data);
51 if($decompressed ===
false){
56 $chunk = $nbt->read($decompressed)->mustGetCompoundTag();
57 }
catch(NbtDataException $e){
60 $chunk = $chunk->getTag(
"Level");
65 $legacyGeneratedTag = $chunk->getTag(
"TerrainGenerated");
66 if($legacyGeneratedTag instanceof ByteTag && $legacyGeneratedTag->getValue() === 0){
74 $makeBiomeArray =
function(
string $biomeIds) : PalettedBlockArray{
75 if(strlen($biomeIds) !== 256){
76 throw new CorruptedChunkException(
"Expected biome array to be exactly 256 bytes, got " . strlen($biomeIds));
80 if(($biomeColorsTag = $chunk->getTag(
"BiomeColors")) instanceof IntArrayTag){
82 }elseif(($biomesTag = $chunk->getTag(
"Biomes")) instanceof ByteArrayTag){
83 $biomes3d = $makeBiomeArray($biomesTag->getValue());
85 $biomes3d =
new PalettedBlockArray(BiomeIds::OCEAN);
89 $fullIds = self::readFixedSizeByteArray($chunk,
"Blocks", 32768);
90 $fullData = self::readFixedSizeByteArray($chunk,
"Data", 16384);
92 for($y = 0; $y < 8; ++$y){
93 $subChunks[$y] =
new SubChunk(Block::EMPTY_STATE_ID, [$this->palettizeLegacySubChunkFromColumn(
100 for($y = Chunk::MIN_SUBCHUNK_INDEX; $y <= Chunk::MAX_SUBCHUNK_INDEX; ++$y){
101 if(!isset($subChunks[$y])){
102 $subChunks[$y] =
new SubChunk(Block::EMPTY_STATE_ID, [], clone $biomes3d);
106 return new LoadedChunkData(
109 $chunk->getByte(
"TerrainPopulated", 0) !== 0,
110 ($entitiesTag = $chunk->getTag(
"Entities")) instanceof ListTag ? self::getCompoundList(
"Entities", $entitiesTag) : [],
111 ($tilesTag = $chunk->getTag(
"TileEntities")) instanceof ListTag ? self::getCompoundList(
"TileEntities", $tilesTag) : [],
114 fixerFlags: LoadedChunkData::FIXER_FLAG_ALL