mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Tile: make createFromData() retrieve the ID by itself
This commit is contained in:
parent
d72e4cb9a1
commit
a9dc447f8f
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user