Tile: Fill defaults and move code to constructors where appropriate

this is leftovers from when NBT was required to construct a tile.
This commit is contained in:
Dylan K. Taylor
2018-12-10 18:35:26 +00:00
parent 7d594ac6d8
commit 6dbceda3e8
8 changed files with 67 additions and 31 deletions

View File

@ -32,6 +32,8 @@ use pocketmine\inventory\Inventory;
use pocketmine\inventory\InventoryHolder;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\level\Level;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\ContainerSetDataPacket;
@ -48,34 +50,37 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{
/** @var FurnaceInventory */
protected $inventory;
/** @var int */
private $burnTime;
private $burnTime = 0;
/** @var int */
private $cookTime;
private $cookTime = 0;
/** @var int */
private $maxTime;
private $maxTime = 0;
public function __construct(Level $level, Vector3 $pos){
$this->inventory = new FurnaceInventory($this);
$this->inventory->setSlotChangeListener(function(Inventory $inventory, int $slot, Item $oldItem, Item $newItem) : ?Item{
$this->scheduleUpdate();
return $newItem;
});
parent::__construct($level, $pos);
}
protected function readSaveData(CompoundTag $nbt) : void{
$this->burnTime = max(0, $nbt->getShort(self::TAG_BURN_TIME, 0, true));
$this->burnTime = max(0, $nbt->getShort(self::TAG_BURN_TIME, $this->burnTime, true));
$this->cookTime = $nbt->getShort(self::TAG_COOK_TIME, 0, true);
$this->cookTime = $nbt->getShort(self::TAG_COOK_TIME, $this->cookTime, true);
if($this->burnTime === 0){
$this->cookTime = 0;
}
$this->maxTime = $nbt->getShort(self::TAG_MAX_TIME, 0, true);
$this->maxTime = $nbt->getShort(self::TAG_MAX_TIME, $this->maxTime, true);
if($this->maxTime === 0){
$this->maxTime = $this->burnTime;
}
$this->loadName($nbt);
$this->inventory = new FurnaceInventory($this);
$this->loadItems($nbt);
$this->inventory->setSlotChangeListener(function(Inventory $inventory, int $slot, Item $oldItem, Item $newItem) : ?Item{
$this->scheduleUpdate();
return $newItem;
});
}
protected function writeSaveData(CompoundTag $nbt) : void{