From a9dc447f8f0acf5dd3bdd2a05384b3ceca9eaff6 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 11 Dec 2018 14:56:25 +0000 Subject: [PATCH] Tile: make createFromData() retrieve the ID by itself --- src/pocketmine/level/format/Chunk.php | 8 +------- src/pocketmine/tile/Tile.php | 7 +++++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/pocketmine/level/format/Chunk.php b/src/pocketmine/level/format/Chunk.php index 05ad16c4c..3fc1461a3 100644 --- a/src/pocketmine/level/format/Chunk.php +++ b/src/pocketmine/level/format/Chunk.php @@ -30,7 +30,6 @@ use pocketmine\block\BlockFactory; use pocketmine\entity\Entity; use pocketmine\level\Level; use pocketmine\nbt\tag\CompoundTag; -use pocketmine\nbt\tag\StringTag; use pocketmine\Player; use pocketmine\tile\Spawnable; use pocketmine\tile\Tile; @@ -613,12 +612,7 @@ class Chunk{ $level->timings->syncChunkLoadTileEntitiesTimer->startTiming(); foreach($this->NBTtiles as $nbt){ if($nbt instanceof CompoundTag){ - if(!$nbt->hasTag(Tile::TAG_ID, StringTag::class)){ - $changed = true; - continue; - } - - if(($tile = Tile::createFromData($nbt->getString(Tile::TAG_ID), $level, $nbt)) !== null){ + if(($tile = Tile::createFromData($level, $nbt)) !== null){ $level->addTile($tile); }else{ $changed = true; diff --git a/src/pocketmine/tile/Tile.php b/src/pocketmine/tile/Tile.php index f60f572a9..f6808cc1f 100644 --- a/src/pocketmine/tile/Tile.php +++ b/src/pocketmine/tile/Tile.php @@ -83,13 +83,16 @@ abstract class Tile extends Position{ } /** - * @param string $type * @param Level $level * @param CompoundTag $nbt * * @return Tile|null */ - public static function createFromData($type, Level $level, CompoundTag $nbt) : ?Tile{ + public static function createFromData(Level $level, CompoundTag $nbt) : ?Tile{ + $type = $nbt->getString(self::TAG_ID, "", true); + if($type === ""){ + return null; + } $tile = self::create($type, $level, new Vector3($nbt->getInt(self::TAG_X), $nbt->getInt(self::TAG_Y), $nbt->getInt(self::TAG_Z))); if($tile !== null){ $tile->readSaveData($nbt);