Make Tile constructors non-dependent on NBT

This commit is contained in:
Dylan K. Taylor 2018-11-30 17:05:36 +00:00
parent a2253e9e7d
commit 16006f9175
4 changed files with 18 additions and 26 deletions

View File

@ -82,6 +82,7 @@ use pocketmine\plugin\Plugin;
use pocketmine\Server;
use pocketmine\tile\Chest;
use pocketmine\tile\Container;
use pocketmine\tile\Spawnable;
use pocketmine\tile\Tile;
use pocketmine\timings\Timings;
use pocketmine\utils\ReversePriorityQueue;
@ -2611,7 +2612,11 @@ class Level implements ChunkManager, Metadatable{
}
$this->tiles[Level::blockHash($tile->x, $tile->y, $tile->z)] = $tile;
$this->clearChunkCache($chunkX, $chunkZ);
$tile->scheduleUpdate();
if($tile instanceof Spawnable){
$this->clearChunkCache($chunkX, $chunkZ);
$tile->spawnToAll();
}
}
/**

View File

@ -33,7 +33,6 @@ use pocketmine\inventory\InventoryEventProcessor;
use pocketmine\inventory\InventoryHolder;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\level\Level;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\ContainerSetDataPacket;
@ -56,13 +55,6 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{
/** @var int */
private $maxTime;
public function __construct(Level $level, CompoundTag $nbt){
parent::__construct($level, $nbt);
if($this->burnTime > 0){
$this->scheduleUpdate();
}
}
protected function readSaveData(CompoundTag $nbt) : void{
$this->burnTime = max(0, $nbt->getShort(self::TAG_BURN_TIME, 0, true));

View File

@ -23,7 +23,6 @@ declare(strict_types=1);
namespace pocketmine\tile;
use pocketmine\level\Level;
use pocketmine\nbt\NetworkLittleEndianNBTStream;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
@ -57,11 +56,6 @@ abstract class Spawnable extends Tile{
return true;
}
public function __construct(Level $level, CompoundTag $nbt){
parent::__construct($level, $nbt);
$this->spawnToAll();
}
public function spawnToAll(){
if($this->closed){
return;

View File

@ -65,7 +65,7 @@ abstract class Tile extends Position{
private static $saveNames = [];
/** @var string */
public $name;
public $name = "";
/** @var bool */
public $closed = false;
/** @var TimingsHandler */
@ -94,9 +94,16 @@ abstract class Tile extends Position{
*/
public static function createTile($type, Level $level, CompoundTag $nbt, ...$args) : ?Tile{
if(isset(self::$knownTiles[$type])){
$pos = new Vector3($nbt->getInt(self::TAG_X), $nbt->getInt(self::TAG_Y), $nbt->getInt(self::TAG_Z));
$class = self::$knownTiles[$type];
/** @see Tile::__construct() */
return new $class($level, $nbt, ...$args);
/**
* @var Tile $tile
* @see Tile::__construct()
*/
$tile = new $class($level, $pos);
$tile->readSaveData($nbt);
$level->addTile($tile);
return $tile;
}
return null;
@ -134,15 +141,9 @@ abstract class Tile extends Position{
return current(self::$saveNames[static::class]);
}
public function __construct(Level $level, CompoundTag $nbt){
public function __construct(Level $level, Vector3 $pos){
$this->timings = Timings::getTileEntityTimings($this);
$this->name = "";
parent::__construct($nbt->getInt(self::TAG_X), $nbt->getInt(self::TAG_Y), $nbt->getInt(self::TAG_Z), $level);
$this->readSaveData($nbt);
$this->getLevel()->addTile($this);
parent::__construct($pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ(), $level);
}
/**