Tile: make createFromData() retrieve the ID by itself

This commit is contained in:
Dylan K. Taylor 2018-12-11 14:56:25 +00:00
parent d72e4cb9a1
commit a9dc447f8f
2 changed files with 6 additions and 9 deletions

View File

@ -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;

View File

@ -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);