Update to latest NBT lib version

This commit is contained in:
Dylan K. Taylor
2018-10-23 16:47:00 +01:00
parent a49abff099
commit 011b9ae159
10 changed files with 23 additions and 43 deletions

View File

@ -100,15 +100,13 @@ class BedrockLevelData extends BaseNbtLevelData{
protected function load() : ?CompoundTag{
$nbt = new LittleEndianNBTStream();
$levelData = $nbt->read(substr(file_get_contents($this->dataPath), 8));
if($levelData instanceof CompoundTag){
$version = $levelData->getInt("StorageVersion", INT32_MAX, true);
if($version > self::CURRENT_STORAGE_VERSION){
throw new UnsupportedLevelFormatException("Specified LevelDB world format version ($version) is not supported by " . \pocketmine\NAME);
}
return $levelData;
$version = $levelData->getInt("StorageVersion", INT32_MAX, true);
if($version > self::CURRENT_STORAGE_VERSION){
throw new UnsupportedLevelFormatException("Specified LevelDB world format version ($version) is not supported by " . \pocketmine\NAME);
}
return null;
return $levelData;
}
protected function fix() : void{

View File

@ -67,7 +67,7 @@ class JavaLevelData extends BaseNbtLevelData{
protected function load() : ?CompoundTag{
$nbt = new BigEndianNBTStream();
$levelData = $nbt->readCompressed(file_get_contents($this->dataPath));
if($levelData instanceof CompoundTag and $levelData->hasTag("Data", CompoundTag::class)){
if($levelData->hasTag("Data", CompoundTag::class)){
return $levelData->getCompoundTag("Data");
}
return null;

View File

@ -225,10 +225,7 @@ class LevelDB extends BaseLevelProvider{
/** @var CompoundTag[] $entities */
$entities = [];
if(($entityData = $this->db->get($index . self::TAG_ENTITY)) !== false and $entityData !== ""){
$entities = $nbt->read($entityData, true);
if(!is_array($entities)){
$entities = [$entities];
}
$entities = $nbt->readMultiple($entityData);
}
/** @var CompoundTag $entityNBT */
@ -238,12 +235,10 @@ class LevelDB extends BaseLevelProvider{
}
}
/** @var CompoundTag[] $tiles */
$tiles = [];
if(($tileData = $this->db->get($index . self::TAG_BLOCK_ENTITY)) !== false and $tileData !== ""){
$tiles = $nbt->read($tileData, true);
if(!is_array($tiles)){
$tiles = [$tiles];
}
$tiles = $nbt->readMultiple($tileData);
}
//TODO: extra data should be converted into blockstorage layers (first they need to be implemented!)
@ -326,7 +321,7 @@ class LevelDB extends BaseLevelProvider{
private function writeTags(array $targets, string $index) : void{
if(!empty($targets)){
$nbt = new LittleEndianNBTStream();
$this->db->put($index, $nbt->write($targets));
$this->db->put($index, $nbt->writeMultiple($targets));
}else{
$this->db->delete($index);
}

View File

@ -98,7 +98,7 @@ trait LegacyAnvilChunkTrait{
protected function deserializeChunk(string $data) : Chunk{
$nbt = new BigEndianNBTStream();
$chunk = $nbt->readCompressed($data);
if(!($chunk instanceof CompoundTag) or !$chunk->hasTag("Level")){
if(!$chunk->hasTag("Level")){
throw new ChunkException("Invalid NBT format");
}

View File

@ -102,7 +102,7 @@ class McRegion extends RegionLevelProvider{
protected function deserializeChunk(string $data) : Chunk{
$nbt = new BigEndianNBTStream();
$chunk = $nbt->readCompressed($data);
if(!($chunk instanceof CompoundTag) or !$chunk->hasTag("Level")){
if(!$chunk->hasTag("Level")){
throw new ChunkException("Invalid NBT format");
}