mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 16:51:42 +00:00
Furnace: give some properties clearer names
This commit is contained in:
parent
7eb9b33fd6
commit
cc6296b019
@ -49,11 +49,11 @@ class Furnace extends Spawnable implements Container, Nameable{
|
||||
/** @var FurnaceInventory */
|
||||
protected $inventory;
|
||||
/** @var int */
|
||||
private $burnTime = 0;
|
||||
private $remainingFuelTime = 0;
|
||||
/** @var int */
|
||||
private $cookTime = 0;
|
||||
/** @var int */
|
||||
private $maxTime = 0;
|
||||
private $maxFuelTime = 0;
|
||||
|
||||
public function __construct(World $world, Vector3 $pos){
|
||||
$this->inventory = new FurnaceInventory($this);
|
||||
@ -67,16 +67,16 @@ class Furnace extends Spawnable implements Container, Nameable{
|
||||
}
|
||||
|
||||
public function readSaveData(CompoundTag $nbt) : void{
|
||||
$this->burnTime = max(0, $nbt->getShort(self::TAG_BURN_TIME, $this->burnTime, true));
|
||||
$this->remainingFuelTime = max(0, $nbt->getShort(self::TAG_BURN_TIME, $this->remainingFuelTime, true));
|
||||
|
||||
$this->cookTime = $nbt->getShort(self::TAG_COOK_TIME, $this->cookTime, true);
|
||||
if($this->burnTime === 0){
|
||||
if($this->remainingFuelTime === 0){
|
||||
$this->cookTime = 0;
|
||||
}
|
||||
|
||||
$this->maxTime = $nbt->getShort(self::TAG_MAX_TIME, $this->maxTime, true);
|
||||
if($this->maxTime === 0){
|
||||
$this->maxTime = $this->burnTime;
|
||||
$this->maxFuelTime = $nbt->getShort(self::TAG_MAX_TIME, $this->maxFuelTime, true);
|
||||
if($this->maxFuelTime === 0){
|
||||
$this->maxFuelTime = $this->remainingFuelTime;
|
||||
}
|
||||
|
||||
$this->loadName($nbt);
|
||||
@ -84,9 +84,9 @@ class Furnace extends Spawnable implements Container, Nameable{
|
||||
}
|
||||
|
||||
protected function writeSaveData(CompoundTag $nbt) : void{
|
||||
$nbt->setShort(self::TAG_BURN_TIME, $this->burnTime);
|
||||
$nbt->setShort(self::TAG_BURN_TIME, $this->remainingFuelTime);
|
||||
$nbt->setShort(self::TAG_COOK_TIME, $this->cookTime);
|
||||
$nbt->setShort(self::TAG_MAX_TIME, $this->maxTime);
|
||||
$nbt->setShort(self::TAG_MAX_TIME, $this->maxFuelTime);
|
||||
$this->saveName($nbt);
|
||||
$this->saveItems($nbt);
|
||||
}
|
||||
@ -128,7 +128,7 @@ class Furnace extends Spawnable implements Container, Nameable{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->maxTime = $this->burnTime = $ev->getBurnTime();
|
||||
$this->maxFuelTime = $this->remainingFuelTime = $ev->getBurnTime();
|
||||
|
||||
$block = $this->getBlock();
|
||||
if($block instanceof BlockFurnace and !$block->isLit()){
|
||||
@ -136,7 +136,7 @@ class Furnace extends Spawnable implements Container, Nameable{
|
||||
$this->getWorld()->setBlock($block, $block);
|
||||
}
|
||||
|
||||
if($this->burnTime > 0 and $ev->isBurning()){
|
||||
if($this->remainingFuelTime > 0 and $ev->isBurning()){
|
||||
$fuel->pop();
|
||||
$this->inventory->setFuel($fuel);
|
||||
}
|
||||
@ -150,8 +150,8 @@ class Furnace extends Spawnable implements Container, Nameable{
|
||||
$this->timings->startTiming();
|
||||
|
||||
$prevCookTime = $this->cookTime;
|
||||
$prevBurnTime = $this->burnTime;
|
||||
$prevMaxTime = $this->maxTime;
|
||||
$prevRemainingFuelTime = $this->remainingFuelTime;
|
||||
$prevMaxFuelTime = $this->maxFuelTime;
|
||||
|
||||
$ret = false;
|
||||
|
||||
@ -161,12 +161,12 @@ class Furnace extends Spawnable implements Container, Nameable{
|
||||
$smelt = $this->world->getServer()->getCraftingManager()->matchFurnaceRecipe($raw);
|
||||
$canSmelt = ($smelt instanceof FurnaceRecipe and $raw->getCount() > 0 and (($smelt->getResult()->equals($product) and $product->getCount() < $product->getMaxStackSize()) or $product->isNull()));
|
||||
|
||||
if($this->burnTime <= 0 and $canSmelt and $fuel->getFuelTime() > 0 and $fuel->getCount() > 0){
|
||||
if($this->remainingFuelTime <= 0 and $canSmelt and $fuel->getFuelTime() > 0 and $fuel->getCount() > 0){
|
||||
$this->checkFuel($fuel);
|
||||
}
|
||||
|
||||
if($this->burnTime > 0){
|
||||
--$this->burnTime;
|
||||
if($this->remainingFuelTime > 0){
|
||||
--$this->remainingFuelTime;
|
||||
|
||||
if($smelt instanceof FurnaceRecipe and $canSmelt){
|
||||
++$this->cookTime;
|
||||
@ -185,8 +185,8 @@ class Furnace extends Spawnable implements Container, Nameable{
|
||||
|
||||
$this->cookTime -= 200;
|
||||
}
|
||||
}elseif($this->burnTime <= 0){
|
||||
$this->burnTime = $this->cookTime = $this->maxTime = 0;
|
||||
}elseif($this->remainingFuelTime <= 0){
|
||||
$this->remainingFuelTime = $this->cookTime = $this->maxFuelTime = 0;
|
||||
}else{
|
||||
$this->cookTime = 0;
|
||||
}
|
||||
@ -197,22 +197,22 @@ class Furnace extends Spawnable implements Container, Nameable{
|
||||
$block->setLit(false);
|
||||
$this->getWorld()->setBlock($block, $block);
|
||||
}
|
||||
$this->burnTime = $this->cookTime = $this->maxTime = 0;
|
||||
$this->remainingFuelTime = $this->cookTime = $this->maxFuelTime = 0;
|
||||
}
|
||||
|
||||
if($prevCookTime !== $this->cookTime){
|
||||
foreach($this->inventory->getViewers() as $v){
|
||||
$v->getNetworkSession()->syncInventoryData($this->inventory, ContainerSetDataPacket::PROPERTY_FURNACE_TICK_COUNT, $this->cookTime);
|
||||
$v->getNetworkSession()->syncInventoryData($this->inventory, ContainerSetDataPacket::PROPERTY_FURNACE_SMELT_PROGRESS, $this->cookTime);
|
||||
}
|
||||
}
|
||||
if($prevBurnTime !== $this->burnTime){
|
||||
if($prevRemainingFuelTime !== $this->remainingFuelTime){
|
||||
foreach($this->inventory->getViewers() as $v){
|
||||
$v->getNetworkSession()->syncInventoryData($this->inventory, ContainerSetDataPacket::PROPERTY_FURNACE_LIT_TIME, $this->burnTime);
|
||||
$v->getNetworkSession()->syncInventoryData($this->inventory, ContainerSetDataPacket::PROPERTY_FURNACE_REMAINING_FUEL_TIME, $this->remainingFuelTime);
|
||||
}
|
||||
}
|
||||
if($prevMaxTime !== $this->maxTime){
|
||||
if($prevMaxFuelTime !== $this->maxFuelTime){
|
||||
foreach($this->inventory->getViewers() as $v){
|
||||
$v->getNetworkSession()->syncInventoryData($this->inventory, ContainerSetDataPacket::PROPERTY_FURNACE_LIT_DURATION, $this->maxTime);
|
||||
$v->getNetworkSession()->syncInventoryData($this->inventory, ContainerSetDataPacket::PROPERTY_FURNACE_MAX_FUEL_TIME, $this->maxFuelTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,9 +31,9 @@ use pocketmine\network\mcpe\handler\SessionHandler;
|
||||
class ContainerSetDataPacket extends DataPacket implements ClientboundPacket{
|
||||
public const NETWORK_ID = ProtocolInfo::CONTAINER_SET_DATA_PACKET;
|
||||
|
||||
public const PROPERTY_FURNACE_TICK_COUNT = 0;
|
||||
public const PROPERTY_FURNACE_LIT_TIME = 1;
|
||||
public const PROPERTY_FURNACE_LIT_DURATION = 2;
|
||||
public const PROPERTY_FURNACE_SMELT_PROGRESS = 0;
|
||||
public const PROPERTY_FURNACE_REMAINING_FUEL_TIME = 1;
|
||||
public const PROPERTY_FURNACE_MAX_FUEL_TIME = 2;
|
||||
public const PROPERTY_FURNACE_STORED_XP = 3;
|
||||
public const PROPERTY_FURNACE_FUEL_AUX = 4;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user