diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index b38c4e023..7d0dd275d 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -45,6 +45,7 @@ use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\FloatTag; use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\ListTag; +use pocketmine\nbt\tag\ShortTag; use pocketmine\network\mcpe\protocol\ActorEventPacket; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use pocketmine\network\mcpe\protocol\MobEffectPacket; @@ -97,17 +98,15 @@ abstract class Living extends Entity implements Damageable{ //TODO: load/save armor inventory contents $this->armorInventory->setEventProcessor(new ArmorInventoryEventProcessor($this)); - $health = $this->getMaxHealth(); - if($this->namedtag->hasTag("HealF", FloatTag::class)){ $health = $this->namedtag->getFloat("HealF"); $this->namedtag->removeTag("HealF"); - }elseif($this->namedtag->hasTag("Health")){ - $healthTag = $this->namedtag->getTag("Health"); - $health = (float) $healthTag->getValue(); //Older versions of PocketMine-MP incorrectly saved this as a short instead of a float - if(!($healthTag instanceof FloatTag)){ - $this->namedtag->removeTag("Health"); - } + }elseif($this->namedtag->hasTag("Health", ShortTag::class)){ + //Older versions of PocketMine-MP incorrectly saved this as a short instead of a float + $health = $this->namedtag->getShort("Health"); + $this->namedtag->removeTag("Health"); + }else{ + $health = $this->namedtag->getFloat("Health"); } $this->setHealth($health); diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 83be88cf9..5d49dd848 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -42,6 +42,7 @@ use pocketmine\nbt\tag\NamedTag; use pocketmine\nbt\tag\ShortTag; use pocketmine\nbt\tag\StringTag; use pocketmine\Player; +use pocketmine\utils\AssumptionFailedError; use pocketmine\utils\Binary; use function array_map; use function base64_decode; @@ -475,7 +476,12 @@ class Item implements ItemIds, \JsonSerializable{ public function getLore() : array{ $display = $this->getNamedTagEntry(self::TAG_DISPLAY); if($display instanceof CompoundTag and ($lore = $display->getListTag(self::TAG_DISPLAY_LORE)) !== null){ - return $lore->getAllValues(); + return array_map(function(NamedTag $line) : string{ + if(!($line instanceof StringTag)){ + throw new AssumptionFailedError("Nobody bothered to handle this error case and we can't fix it until PM4, oops ... #blameshoghi"); + } + return $line->getValue(); + }, $lore->getValue()); } return []; diff --git a/src/pocketmine/level/format/Chunk.php b/src/pocketmine/level/format/Chunk.php index 8134af9d0..c199a7409 100644 --- a/src/pocketmine/level/format/Chunk.php +++ b/src/pocketmine/level/format/Chunk.php @@ -30,6 +30,7 @@ use pocketmine\block\BlockFactory; use pocketmine\entity\Entity; use pocketmine\level\Level; use pocketmine\nbt\tag\CompoundTag; +use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\StringTag; use pocketmine\Player; use pocketmine\tile\Spawnable; @@ -691,13 +692,14 @@ class Chunk{ $level->timings->syncChunkLoadEntitiesTimer->startTiming(); foreach($this->NBTentities as $nbt){ - if(!$nbt->hasTag("id")){ //allow mixed types (because of leveldb) + $idTag = $nbt->getTag("id"); + if(!($idTag instanceof IntTag) && !($idTag instanceof StringTag)){ //allow mixed types (because of leveldb) $changed = true; continue; } try{ - $entity = Entity::createEntity($nbt->getTag("id")->getValue(), $level, $nbt); + $entity = Entity::createEntity($idTag->getValue(), $level, $nbt); if(!($entity instanceof Entity)){ $changed = true; continue;