updated pocketmine/nbt dependency

this is going to need work on exception handling, but right now it's so inconsistent that it doesn't matter anyway.
This commit is contained in:
Dylan K. Taylor 2020-03-04 17:53:37 +00:00
parent 6e39e34c1e
commit 995309424e
16 changed files with 45 additions and 32 deletions

8
composer.lock generated
View File

@ -443,12 +443,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/pmmp/NBT.git", "url": "https://github.com/pmmp/NBT.git",
"reference": "1cdf6aec3024e2061b8c3e5045c43250df94a740" "reference": "f205b5e6fe47ddf0ead4f1438b37f9cdee1fc407"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/pmmp/NBT/zipball/1cdf6aec3024e2061b8c3e5045c43250df94a740", "url": "https://api.github.com/repos/pmmp/NBT/zipball/f205b5e6fe47ddf0ead4f1438b37f9cdee1fc407",
"reference": "1cdf6aec3024e2061b8c3e5045c43250df94a740", "reference": "f205b5e6fe47ddf0ead4f1438b37f9cdee1fc407",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -472,7 +472,7 @@
"LGPL-3.0" "LGPL-3.0"
], ],
"description": "PHP library for working with Named Binary Tags", "description": "PHP library for working with Named Binary Tags",
"time": "2020-02-24T21:43:33+00:00" "time": "2020-03-04T16:39:25+00:00"
}, },
{ {
"name": "pocketmine/raklib", "name": "pocketmine/raklib",

View File

@ -45,7 +45,7 @@ class Comparator extends Tile{
} }
public function readSaveData(CompoundTag $nbt) : void{ public function readSaveData(CompoundTag $nbt) : void{
$this->signalStrength = $nbt->getInt(self::TAG_OUTPUT_SIGNAL, 0, true); $this->signalStrength = $nbt->getInt(self::TAG_OUTPUT_SIGNAL, 0);
} }
protected function writeSaveData(CompoundTag $nbt) : void{ protected function writeSaveData(CompoundTag $nbt) : void{

View File

@ -66,14 +66,14 @@ class Furnace extends Spawnable implements Container, Nameable{
} }
public function readSaveData(CompoundTag $nbt) : void{ public function readSaveData(CompoundTag $nbt) : void{
$this->remainingFuelTime = max(0, $nbt->getShort(self::TAG_BURN_TIME, $this->remainingFuelTime, true)); $this->remainingFuelTime = max(0, $nbt->getShort(self::TAG_BURN_TIME, $this->remainingFuelTime));
$this->cookTime = $nbt->getShort(self::TAG_COOK_TIME, $this->cookTime, true); $this->cookTime = $nbt->getShort(self::TAG_COOK_TIME, $this->cookTime);
if($this->remainingFuelTime === 0){ if($this->remainingFuelTime === 0){
$this->cookTime = 0; $this->cookTime = 0;
} }
$this->maxFuelTime = $nbt->getShort(self::TAG_MAX_TIME, $this->maxFuelTime, true); $this->maxFuelTime = $nbt->getShort(self::TAG_MAX_TIME, $this->maxFuelTime);
if($this->maxFuelTime === 0){ if($this->maxFuelTime === 0){
$this->maxFuelTime = $this->remainingFuelTime; $this->maxFuelTime = $this->remainingFuelTime;
} }

View File

@ -54,8 +54,8 @@ class ItemFrame extends Spawnable{
if(($itemTag = $nbt->getCompoundTag(self::TAG_ITEM)) !== null){ if(($itemTag = $nbt->getCompoundTag(self::TAG_ITEM)) !== null){
$this->item = Item::nbtDeserialize($itemTag); $this->item = Item::nbtDeserialize($itemTag);
} }
$this->itemRotation = $nbt->getByte(self::TAG_ITEM_ROTATION, $this->itemRotation, true); $this->itemRotation = $nbt->getByte(self::TAG_ITEM_ROTATION, $this->itemRotation);
$this->itemDropChance = $nbt->getFloat(self::TAG_ITEM_DROP_CHANCE, $this->itemDropChance, true); $this->itemDropChance = $nbt->getFloat(self::TAG_ITEM_DROP_CHANCE, $this->itemDropChance);
} }
protected function writeSaveData(CompoundTag $nbt) : void{ protected function writeSaveData(CompoundTag $nbt) : void{

View File

@ -58,7 +58,7 @@ class Skull extends Spawnable{
//bad data, drop it //bad data, drop it
} }
} }
$rotation = $nbt->getByte(self::TAG_ROT, 0, true); $rotation = $nbt->getByte(self::TAG_ROT, 0);
if($rotation >= 0 and $rotation <= 15){ if($rotation >= 0 and $rotation <= 15){
$this->skullRotation = $rotation; $this->skullRotation = $rotation;
} }

View File

@ -167,7 +167,7 @@ final class TileFactory{
* @internal * @internal
*/ */
public static function createFromData(World $world, CompoundTag $nbt) : ?Tile{ public static function createFromData(World $world, CompoundTag $nbt) : ?Tile{
$type = $nbt->getString(Tile::TAG_ID, "", true); $type = $nbt->getString(Tile::TAG_ID, "");
if(!isset(self::$knownTiles[$type])){ if(!isset(self::$knownTiles[$type])){
return null; return null;
} }

View File

@ -248,15 +248,15 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
$this->inventory->setHeldItemIndex($nbt->getInt("SelectedInventorySlot", 0), false); $this->inventory->setHeldItemIndex($nbt->getInt("SelectedInventorySlot", 0), false);
$this->hungerManager->setFood((float) $nbt->getInt("foodLevel", (int) $this->hungerManager->getFood(), true)); $this->hungerManager->setFood((float) $nbt->getInt("foodLevel", (int) $this->hungerManager->getFood()));
$this->hungerManager->setExhaustion($nbt->getFloat("foodExhaustionLevel", $this->hungerManager->getExhaustion(), true)); $this->hungerManager->setExhaustion($nbt->getFloat("foodExhaustionLevel", $this->hungerManager->getExhaustion()));
$this->hungerManager->setSaturation($nbt->getFloat("foodSaturationLevel", $this->hungerManager->getSaturation(), true)); $this->hungerManager->setSaturation($nbt->getFloat("foodSaturationLevel", $this->hungerManager->getSaturation()));
$this->hungerManager->setFoodTickTimer($nbt->getInt("foodTickTimer", $this->hungerManager->getFoodTickTimer(), true)); $this->hungerManager->setFoodTickTimer($nbt->getInt("foodTickTimer", $this->hungerManager->getFoodTickTimer()));
$this->xpManager->setXpAndProgressNoEvent( $this->xpManager->setXpAndProgressNoEvent(
$nbt->getInt("XpLevel", 0, true), $nbt->getInt("XpLevel", 0),
$nbt->getFloat("XpP", 0.0, true)); $nbt->getFloat("XpP", 0.0));
$this->xpManager->setLifetimeTotalXp($nbt->getInt("XpTotal", 0, true)); $this->xpManager->setLifetimeTotalXp($nbt->getInt("XpTotal", 0));
if($nbt->hasTag("XpSeed", IntTag::class)){ if($nbt->hasTag("XpSeed", IntTag::class)){
$this->xpSeed = $nbt->getInt("XpSeed"); $this->xpSeed = $nbt->getInt("XpSeed");

View File

@ -60,7 +60,7 @@ class PrimedTNT extends Entity implements Explosive{
protected function initEntity(CompoundTag $nbt) : void{ protected function initEntity(CompoundTag $nbt) : void{
parent::initEntity($nbt); parent::initEntity($nbt);
$this->fuse = $nbt->getShort("Fuse", 80, true); $this->fuse = $nbt->getShort("Fuse", 80);
$this->getWorld()->addSound($this->location, new IgniteSound()); $this->getWorld()->addSound($this->location, new IgniteSound());
} }

View File

@ -78,7 +78,7 @@ class Arrow extends Projectile{
protected function initEntity(CompoundTag $nbt) : void{ protected function initEntity(CompoundTag $nbt) : void{
parent::initEntity($nbt); parent::initEntity($nbt);
$this->pickupMode = $nbt->getByte(self::TAG_PICKUP, self::PICKUP_ANY, true); $this->pickupMode = $nbt->getByte(self::TAG_PICKUP, self::PICKUP_ANY);
$this->collideTicks = $nbt->getShort("life", $this->collideTicks); $this->collideTicks = $nbt->getShort("life", $this->collideTicks);
} }

View File

@ -273,7 +273,7 @@ class Item implements \JsonSerializable{
$display = $tag->getCompoundTag(self::TAG_DISPLAY); $display = $tag->getCompoundTag(self::TAG_DISPLAY);
if($display !== null){ if($display !== null){
$this->customName = $display->getString(self::TAG_DISPLAY_NAME, $this->customName, true); $this->customName = $display->getString(self::TAG_DISPLAY_NAME, $this->customName);
$lore = $display->getListTag(self::TAG_DISPLAY_LORE); $lore = $display->getListTag(self::TAG_DISPLAY_LORE);
if($lore !== null and $lore->getTagType() === NBT::TAG_String){ if($lore !== null and $lore->getTagType() === NBT::TAG_String){
/** @var StringTag $t */ /** @var StringTag $t */
@ -288,8 +288,8 @@ class Item implements \JsonSerializable{
if($enchantments !== null and $enchantments->getTagType() === NBT::TAG_Compound){ if($enchantments !== null and $enchantments->getTagType() === NBT::TAG_Compound){
/** @var CompoundTag $enchantment */ /** @var CompoundTag $enchantment */
foreach($enchantments as $enchantment){ foreach($enchantments as $enchantment){
$magicNumber = $enchantment->getShort("id", -1, true); $magicNumber = $enchantment->getShort("id", -1);
$level = $enchantment->getShort("lvl", 0, true); $level = $enchantment->getShort("lvl", 0);
if($level <= 0){ if($level <= 0){
continue; continue;
} }

View File

@ -267,7 +267,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
$spawnReset = false; $spawnReset = false;
if($namedtag !== null and ($world = $this->server->getWorldManager()->getWorldByName($namedtag->getString("Level", "", true))) !== null){ if($namedtag !== null and ($world = $this->server->getWorldManager()->getWorldByName($namedtag->getString("Level", ""))) !== null){
/** @var float[] $pos */ /** @var float[] $pos */
$pos = $namedtag->getListTag("Pos")->getAllValues(); $pos = $namedtag->getListTag("Pos")->getAllValues();
$spawn = new Vector3($pos[0], $pos[1], $pos[2]); $spawn = new Vector3($pos[0], $pos[1], $pos[2]);

View File

@ -33,6 +33,8 @@ use pocketmine\block\tile\TileFactory;
use pocketmine\entity\Entity; use pocketmine\entity\Entity;
use pocketmine\entity\EntityFactory; use pocketmine\entity\EntityFactory;
use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\player\Player; use pocketmine\player\Player;
use pocketmine\world\World; use pocketmine\world\World;
use function array_fill; use function array_fill;
@ -498,7 +500,14 @@ class Chunk{
try{ try{
$entity = EntityFactory::createFromData($world, $nbt); $entity = EntityFactory::createFromData($world, $nbt);
if(!($entity instanceof Entity)){ if(!($entity instanceof Entity)){
$world->getLogger()->warning("Chunk $this->x $this->z: Deleted unknown entity type " . $nbt->getString("id", $nbt->getString("identifier", "<unknown>", true), true)); $saveIdTag = $nbt->getTag("id") ?? $nbt->getTag("identifier");
$saveId = "<unknown>";
if($saveIdTag instanceof StringTag){
$saveId = $saveIdTag->getValue();
}elseif($saveIdTag instanceof IntTag){ //legacy MCPE format
$saveId = "legacy(" . $saveIdTag->getValue() . ")";
}
$world->getLogger()->warning("Chunk $this->x $this->z: Deleted unknown entity type $saveId");
continue; continue;
} }
}catch(\Exception $t){ //TODO: this shouldn't be here }catch(\Exception $t){ //TODO: this shouldn't be here
@ -517,7 +526,7 @@ class Chunk{
if(($tile = TileFactory::createFromData($world, $nbt)) !== null){ if(($tile = TileFactory::createFromData($world, $nbt)) !== null){
$world->addTile($tile); $world->addTile($tile);
}else{ }else{
$world->getLogger()->warning("Chunk $this->x $this->z: Deleted unknown tile entity type " . $nbt->getString("id", "<unknown>", true)); $world->getLogger()->warning("Chunk $this->x $this->z: Deleted unknown tile entity type " . $nbt->getString("id", "<unknown>"));
continue; continue;
} }
} }

View File

@ -25,6 +25,7 @@ namespace pocketmine\world\format\io\data;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\world\format\io\exception\CorruptedWorldException; use pocketmine\world\format\io\exception\CorruptedWorldException;
use pocketmine\world\format\io\exception\UnsupportedWorldFormatException; use pocketmine\world\format\io\exception\UnsupportedWorldFormatException;
use pocketmine\world\format\io\WorldData; use pocketmine\world\format\io\WorldData;
@ -124,11 +125,14 @@ abstract class BaseNbtWorldData implements WorldData{
} }
public function getTime() : int{ public function getTime() : int{
return $this->compoundTag->getLong("Time", 0, true); if($this->compoundTag->hasTag("Time", IntTag::class)){ //some older PM worlds had this in the wrong format
return $this->compoundTag->getInt("Time");
}
return $this->compoundTag->getLong("Time", 0);
} }
public function setTime(int $value) : void{ public function setTime(int $value) : void{
$this->compoundTag->setLong("Time", $value, true); //some older PM worlds had this in the wrong format $this->compoundTag->setLong("Time", $value);
} }
public function getSpawn() : Vector3{ public function getSpawn() : Vector3{

View File

@ -122,7 +122,7 @@ class BedrockWorldData extends BaseNbtWorldData{
throw new CorruptedWorldException($e->getMessage(), 0, $e); throw new CorruptedWorldException($e->getMessage(), 0, $e);
} }
$version = $worldData->getInt("StorageVersion", Limits::INT32_MAX, true); $version = $worldData->getInt("StorageVersion", Limits::INT32_MAX);
if($version > self::CURRENT_STORAGE_VERSION){ if($version > self::CURRENT_STORAGE_VERSION){
throw new UnsupportedWorldFormatException("LevelDB world format version $version is currently unsupported"); throw new UnsupportedWorldFormatException("LevelDB world format version $version is currently unsupported");
} }

View File

@ -90,7 +90,7 @@ class JavaWorldData extends BaseNbtWorldData{
protected function fix() : void{ protected function fix() : void{
if(!$this->compoundTag->hasTag("generatorName", StringTag::class)){ if(!$this->compoundTag->hasTag("generatorName", StringTag::class)){
$this->compoundTag->setString("generatorName", "default", true); $this->compoundTag->setString("generatorName", "default");
}elseif(($generatorName = self::hackyFixForGeneratorClasspathInLevelDat($this->compoundTag->getString("generatorName"))) !== null){ }elseif(($generatorName = self::hackyFixForGeneratorClasspathInLevelDat($this->compoundTag->getString("generatorName"))) !== null){
$this->compoundTag->setString("generatorName", $generatorName); $this->compoundTag->setString("generatorName", $generatorName);
} }

View File

@ -75,7 +75,7 @@ trait LegacyAnvilChunkTrait{
if($chunk->hasTag("BiomeColors", IntArrayTag::class)){ if($chunk->hasTag("BiomeColors", IntArrayTag::class)){
$biomeIds = ChunkUtils::convertBiomeColors($chunk->getIntArray("BiomeColors")); //Convert back to original format $biomeIds = ChunkUtils::convertBiomeColors($chunk->getIntArray("BiomeColors")); //Convert back to original format
}else{ }else{
$biomeIds = $chunk->getByteArray("Biomes", "", true); $biomeIds = $chunk->getByteArray("Biomes", "");
} }
$result = new Chunk( $result = new Chunk(