Eliminate usages of BaseNbtSerializer->readCompressed() and BaseNbtSerializer->writeCompressed()

This commit is contained in:
Dylan K. Taylor
2020-06-17 14:31:56 +01:00
parent 3cdf808da1
commit 506f98efc4
4 changed files with 48 additions and 9 deletions

View File

@@ -34,6 +34,7 @@ use pocketmine\world\format\Chunk;
use pocketmine\world\format\io\ChunkUtils;
use pocketmine\world\format\io\exception\CorruptedChunkException;
use pocketmine\world\format\SubChunk;
use function zlib_decode;
/**
* Trait containing I/O methods for handling legacy Anvil-style chunks.
@@ -54,9 +55,13 @@ trait LegacyAnvilChunkTrait{
* @throws CorruptedChunkException
*/
protected function deserializeChunk(string $data) : Chunk{
$decompressed = @zlib_decode($data);
if($decompressed === false){
throw new CorruptedChunkException("Failed to decompress chunk NBT");
}
$nbt = new BigEndianNbtSerializer();
try{
$chunk = $nbt->readCompressed($data)->mustGetCompoundTag();
$chunk = $nbt->read($decompressed)->mustGetCompoundTag();
}catch(NbtDataException $e){
throw new CorruptedChunkException($e->getMessage(), 0, $e);
}