diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 67617f40c..b36d68233 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -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(); + } } /** diff --git a/src/pocketmine/tile/Furnace.php b/src/pocketmine/tile/Furnace.php index aef45ecb0..8e4846b14 100644 --- a/src/pocketmine/tile/Furnace.php +++ b/src/pocketmine/tile/Furnace.php @@ -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)); diff --git a/src/pocketmine/tile/Spawnable.php b/src/pocketmine/tile/Spawnable.php index 2d4710f5e..3b7f95e57 100644 --- a/src/pocketmine/tile/Spawnable.php +++ b/src/pocketmine/tile/Spawnable.php @@ -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; diff --git a/src/pocketmine/tile/Tile.php b/src/pocketmine/tile/Tile.php index fd48c30b2..5cfcc52dd 100644 --- a/src/pocketmine/tile/Tile.php +++ b/src/pocketmine/tile/Tile.php @@ -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); } /**