From 995309424e652b81beb2b39ffdbb1d89820541fd Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 4 Mar 2020 17:53:37 +0000 Subject: [PATCH] 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. --- composer.lock | 8 ++++---- src/block/tile/Comparator.php | 2 +- src/block/tile/Furnace.php | 6 +++--- src/block/tile/ItemFrame.php | 4 ++-- src/block/tile/Skull.php | 2 +- src/block/tile/TileFactory.php | 2 +- src/entity/Human.php | 14 +++++++------- src/entity/object/PrimedTNT.php | 2 +- src/entity/projectile/Arrow.php | 2 +- src/item/Item.php | 6 +++--- src/player/Player.php | 2 +- src/world/format/Chunk.php | 13 +++++++++++-- src/world/format/io/data/BaseNbtWorldData.php | 8 ++++++-- src/world/format/io/data/BedrockWorldData.php | 2 +- src/world/format/io/data/JavaWorldData.php | 2 +- .../format/io/region/LegacyAnvilChunkTrait.php | 2 +- 16 files changed, 45 insertions(+), 32 deletions(-) diff --git a/composer.lock b/composer.lock index 3e98a2d59..6bfe05bd3 100644 --- a/composer.lock +++ b/composer.lock @@ -443,12 +443,12 @@ "source": { "type": "git", "url": "https://github.com/pmmp/NBT.git", - "reference": "1cdf6aec3024e2061b8c3e5045c43250df94a740" + "reference": "f205b5e6fe47ddf0ead4f1438b37f9cdee1fc407" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pmmp/NBT/zipball/1cdf6aec3024e2061b8c3e5045c43250df94a740", - "reference": "1cdf6aec3024e2061b8c3e5045c43250df94a740", + "url": "https://api.github.com/repos/pmmp/NBT/zipball/f205b5e6fe47ddf0ead4f1438b37f9cdee1fc407", + "reference": "f205b5e6fe47ddf0ead4f1438b37f9cdee1fc407", "shasum": "" }, "require": { @@ -472,7 +472,7 @@ "LGPL-3.0" ], "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", diff --git a/src/block/tile/Comparator.php b/src/block/tile/Comparator.php index 24e63a79d..317a682f4 100644 --- a/src/block/tile/Comparator.php +++ b/src/block/tile/Comparator.php @@ -45,7 +45,7 @@ class Comparator extends Tile{ } 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{ diff --git a/src/block/tile/Furnace.php b/src/block/tile/Furnace.php index 0428cfb0b..a94491afd 100644 --- a/src/block/tile/Furnace.php +++ b/src/block/tile/Furnace.php @@ -66,14 +66,14 @@ class Furnace extends Spawnable implements Container, Nameable{ } 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){ $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){ $this->maxFuelTime = $this->remainingFuelTime; } diff --git a/src/block/tile/ItemFrame.php b/src/block/tile/ItemFrame.php index a3910046f..32d55f201 100644 --- a/src/block/tile/ItemFrame.php +++ b/src/block/tile/ItemFrame.php @@ -54,8 +54,8 @@ class ItemFrame extends Spawnable{ if(($itemTag = $nbt->getCompoundTag(self::TAG_ITEM)) !== null){ $this->item = Item::nbtDeserialize($itemTag); } - $this->itemRotation = $nbt->getByte(self::TAG_ITEM_ROTATION, $this->itemRotation, true); - $this->itemDropChance = $nbt->getFloat(self::TAG_ITEM_DROP_CHANCE, $this->itemDropChance, true); + $this->itemRotation = $nbt->getByte(self::TAG_ITEM_ROTATION, $this->itemRotation); + $this->itemDropChance = $nbt->getFloat(self::TAG_ITEM_DROP_CHANCE, $this->itemDropChance); } protected function writeSaveData(CompoundTag $nbt) : void{ diff --git a/src/block/tile/Skull.php b/src/block/tile/Skull.php index fe0fe062c..13de524cf 100644 --- a/src/block/tile/Skull.php +++ b/src/block/tile/Skull.php @@ -58,7 +58,7 @@ class Skull extends Spawnable{ //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){ $this->skullRotation = $rotation; } diff --git a/src/block/tile/TileFactory.php b/src/block/tile/TileFactory.php index 130d99e56..186b28068 100644 --- a/src/block/tile/TileFactory.php +++ b/src/block/tile/TileFactory.php @@ -167,7 +167,7 @@ final class TileFactory{ * @internal */ 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])){ return null; } diff --git a/src/entity/Human.php b/src/entity/Human.php index 72c5f10e7..a3e1db0da 100644 --- a/src/entity/Human.php +++ b/src/entity/Human.php @@ -248,15 +248,15 @@ class Human extends Living implements ProjectileSource, InventoryHolder{ $this->inventory->setHeldItemIndex($nbt->getInt("SelectedInventorySlot", 0), false); - $this->hungerManager->setFood((float) $nbt->getInt("foodLevel", (int) $this->hungerManager->getFood(), true)); - $this->hungerManager->setExhaustion($nbt->getFloat("foodExhaustionLevel", $this->hungerManager->getExhaustion(), true)); - $this->hungerManager->setSaturation($nbt->getFloat("foodSaturationLevel", $this->hungerManager->getSaturation(), true)); - $this->hungerManager->setFoodTickTimer($nbt->getInt("foodTickTimer", $this->hungerManager->getFoodTickTimer(), true)); + $this->hungerManager->setFood((float) $nbt->getInt("foodLevel", (int) $this->hungerManager->getFood())); + $this->hungerManager->setExhaustion($nbt->getFloat("foodExhaustionLevel", $this->hungerManager->getExhaustion())); + $this->hungerManager->setSaturation($nbt->getFloat("foodSaturationLevel", $this->hungerManager->getSaturation())); + $this->hungerManager->setFoodTickTimer($nbt->getInt("foodTickTimer", $this->hungerManager->getFoodTickTimer())); $this->xpManager->setXpAndProgressNoEvent( - $nbt->getInt("XpLevel", 0, true), - $nbt->getFloat("XpP", 0.0, true)); - $this->xpManager->setLifetimeTotalXp($nbt->getInt("XpTotal", 0, true)); + $nbt->getInt("XpLevel", 0), + $nbt->getFloat("XpP", 0.0)); + $this->xpManager->setLifetimeTotalXp($nbt->getInt("XpTotal", 0)); if($nbt->hasTag("XpSeed", IntTag::class)){ $this->xpSeed = $nbt->getInt("XpSeed"); diff --git a/src/entity/object/PrimedTNT.php b/src/entity/object/PrimedTNT.php index 505b22f55..e6d72c039 100644 --- a/src/entity/object/PrimedTNT.php +++ b/src/entity/object/PrimedTNT.php @@ -60,7 +60,7 @@ class PrimedTNT extends Entity implements Explosive{ protected function initEntity(CompoundTag $nbt) : void{ parent::initEntity($nbt); - $this->fuse = $nbt->getShort("Fuse", 80, true); + $this->fuse = $nbt->getShort("Fuse", 80); $this->getWorld()->addSound($this->location, new IgniteSound()); } diff --git a/src/entity/projectile/Arrow.php b/src/entity/projectile/Arrow.php index 9a2bae08c..b0ba0fa7e 100644 --- a/src/entity/projectile/Arrow.php +++ b/src/entity/projectile/Arrow.php @@ -78,7 +78,7 @@ class Arrow extends Projectile{ protected function initEntity(CompoundTag $nbt) : void{ 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); } diff --git a/src/item/Item.php b/src/item/Item.php index bc4364ca3..fef054c6c 100644 --- a/src/item/Item.php +++ b/src/item/Item.php @@ -273,7 +273,7 @@ class Item implements \JsonSerializable{ $display = $tag->getCompoundTag(self::TAG_DISPLAY); 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); if($lore !== null and $lore->getTagType() === NBT::TAG_String){ /** @var StringTag $t */ @@ -288,8 +288,8 @@ class Item implements \JsonSerializable{ if($enchantments !== null and $enchantments->getTagType() === NBT::TAG_Compound){ /** @var CompoundTag $enchantment */ foreach($enchantments as $enchantment){ - $magicNumber = $enchantment->getShort("id", -1, true); - $level = $enchantment->getShort("lvl", 0, true); + $magicNumber = $enchantment->getShort("id", -1); + $level = $enchantment->getShort("lvl", 0); if($level <= 0){ continue; } diff --git a/src/player/Player.php b/src/player/Player.php index d476925ba..3a2e8fce1 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -267,7 +267,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $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 */ $pos = $namedtag->getListTag("Pos")->getAllValues(); $spawn = new Vector3($pos[0], $pos[1], $pos[2]); diff --git a/src/world/format/Chunk.php b/src/world/format/Chunk.php index e6ada96ac..82aa8bde2 100644 --- a/src/world/format/Chunk.php +++ b/src/world/format/Chunk.php @@ -33,6 +33,8 @@ use pocketmine\block\tile\TileFactory; use pocketmine\entity\Entity; use pocketmine\entity\EntityFactory; use pocketmine\nbt\tag\CompoundTag; +use pocketmine\nbt\tag\IntTag; +use pocketmine\nbt\tag\StringTag; use pocketmine\player\Player; use pocketmine\world\World; use function array_fill; @@ -498,7 +500,14 @@ class Chunk{ try{ $entity = EntityFactory::createFromData($world, $nbt); if(!($entity instanceof Entity)){ - $world->getLogger()->warning("Chunk $this->x $this->z: Deleted unknown entity type " . $nbt->getString("id", $nbt->getString("identifier", "", true), true)); + $saveIdTag = $nbt->getTag("id") ?? $nbt->getTag("identifier"); + $saveId = ""; + 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; } }catch(\Exception $t){ //TODO: this shouldn't be here @@ -517,7 +526,7 @@ class Chunk{ if(($tile = TileFactory::createFromData($world, $nbt)) !== null){ $world->addTile($tile); }else{ - $world->getLogger()->warning("Chunk $this->x $this->z: Deleted unknown tile entity type " . $nbt->getString("id", "", true)); + $world->getLogger()->warning("Chunk $this->x $this->z: Deleted unknown tile entity type " . $nbt->getString("id", "")); continue; } } diff --git a/src/world/format/io/data/BaseNbtWorldData.php b/src/world/format/io/data/BaseNbtWorldData.php index 20074dc5e..b1092130f 100644 --- a/src/world/format/io/data/BaseNbtWorldData.php +++ b/src/world/format/io/data/BaseNbtWorldData.php @@ -25,6 +25,7 @@ namespace pocketmine\world\format\io\data; use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; +use pocketmine\nbt\tag\IntTag; use pocketmine\world\format\io\exception\CorruptedWorldException; use pocketmine\world\format\io\exception\UnsupportedWorldFormatException; use pocketmine\world\format\io\WorldData; @@ -124,11 +125,14 @@ abstract class BaseNbtWorldData implements WorldData{ } 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{ - $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{ diff --git a/src/world/format/io/data/BedrockWorldData.php b/src/world/format/io/data/BedrockWorldData.php index 252513f76..5be66be8b 100644 --- a/src/world/format/io/data/BedrockWorldData.php +++ b/src/world/format/io/data/BedrockWorldData.php @@ -122,7 +122,7 @@ class BedrockWorldData extends BaseNbtWorldData{ 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){ throw new UnsupportedWorldFormatException("LevelDB world format version $version is currently unsupported"); } diff --git a/src/world/format/io/data/JavaWorldData.php b/src/world/format/io/data/JavaWorldData.php index a51c5ce06..2b7f45598 100644 --- a/src/world/format/io/data/JavaWorldData.php +++ b/src/world/format/io/data/JavaWorldData.php @@ -90,7 +90,7 @@ class JavaWorldData extends BaseNbtWorldData{ protected function fix() : void{ 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){ $this->compoundTag->setString("generatorName", $generatorName); } diff --git a/src/world/format/io/region/LegacyAnvilChunkTrait.php b/src/world/format/io/region/LegacyAnvilChunkTrait.php index aacad403e..204edff3b 100644 --- a/src/world/format/io/region/LegacyAnvilChunkTrait.php +++ b/src/world/format/io/region/LegacyAnvilChunkTrait.php @@ -75,7 +75,7 @@ trait LegacyAnvilChunkTrait{ if($chunk->hasTag("BiomeColors", IntArrayTag::class)){ $biomeIds = ChunkUtils::convertBiomeColors($chunk->getIntArray("BiomeColors")); //Convert back to original format }else{ - $biomeIds = $chunk->getByteArray("Biomes", "", true); + $biomeIds = $chunk->getByteArray("Biomes", ""); } $result = new Chunk(