WorldProvider: allow loadChunk() to return additional information about the loaded chunk data

this will be needed for dealing with #5733. I don't plan to fix that before 5.0, but we need to make the appropriate BC breaks now, before release.
This commit is contained in:
Dylan K. Taylor
2023-05-29 17:03:39 +01:00
parent f5a1a0c9cb
commit c10be0f346
8 changed files with 91 additions and 30 deletions

View File

@@ -36,6 +36,7 @@ use pocketmine\world\format\Chunk;
use pocketmine\world\format\io\ChunkData;
use pocketmine\world\format\io\ChunkUtils;
use pocketmine\world\format\io\exception\CorruptedChunkException;
use pocketmine\world\format\io\LoadedChunkData;
use pocketmine\world\format\PalettedBlockArray;
use pocketmine\world\format\SubChunk;
use function strlen;
@@ -54,7 +55,7 @@ trait LegacyAnvilChunkTrait{
/**
* @throws CorruptedChunkException
*/
protected function deserializeChunk(string $data) : ?ChunkData{
protected function deserializeChunk(string $data) : ?LoadedChunkData{
$decompressed = @zlib_decode($data);
if($decompressed === false){
throw new CorruptedChunkException("Failed to decompress chunk NBT");
@@ -99,13 +100,17 @@ trait LegacyAnvilChunkTrait{
}
}
return new ChunkData(
new Chunk(
$subChunks,
$chunk->getByte("TerrainPopulated", 0) !== 0
return new LoadedChunkData(
data: new ChunkData(
new Chunk(
$subChunks,
$chunk->getByte("TerrainPopulated", 0) !== 0
),
($entitiesTag = $chunk->getTag("Entities")) instanceof ListTag ? self::getCompoundList("Entities", $entitiesTag) : [],
($tilesTag = $chunk->getTag("TileEntities")) instanceof ListTag ? self::getCompoundList("TileEntities", $tilesTag) : [],
),
($entitiesTag = $chunk->getTag("Entities")) instanceof ListTag ? self::getCompoundList("Entities", $entitiesTag) : [],
($tilesTag = $chunk->getTag("TileEntities")) instanceof ListTag ? self::getCompoundList("TileEntities", $tilesTag) : [],
upgraded: true,
fixerFlags: LoadedChunkData::FIXER_FLAG_ALL
);
}