mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-15 16:05:28 +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 */
|
/** @var FurnaceInventory */
|
||||||
protected $inventory;
|
protected $inventory;
|
||||||
/** @var int */
|
/** @var int */
|
||||||
private $burnTime = 0;
|
private $remainingFuelTime = 0;
|
||||||
/** @var int */
|
/** @var int */
|
||||||
private $cookTime = 0;
|
private $cookTime = 0;
|
||||||
/** @var int */
|
/** @var int */
|
||||||
private $maxTime = 0;
|
private $maxFuelTime = 0;
|
||||||
|
|
||||||
public function __construct(World $world, Vector3 $pos){
|
public function __construct(World $world, Vector3 $pos){
|
||||||
$this->inventory = new FurnaceInventory($this);
|
$this->inventory = new FurnaceInventory($this);
|
||||||
@ -67,16 +67,16 @@ class Furnace extends Spawnable implements Container, Nameable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function readSaveData(CompoundTag $nbt) : void{
|
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);
|
$this->cookTime = $nbt->getShort(self::TAG_COOK_TIME, $this->cookTime, true);
|
||||||
if($this->burnTime === 0){
|
if($this->remainingFuelTime === 0){
|
||||||
$this->cookTime = 0;
|
$this->cookTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->maxTime = $nbt->getShort(self::TAG_MAX_TIME, $this->maxTime, true);
|
$this->maxFuelTime = $nbt->getShort(self::TAG_MAX_TIME, $this->maxFuelTime, true);
|
||||||
if($this->maxTime === 0){
|
if($this->maxFuelTime === 0){
|
||||||
$this->maxTime = $this->burnTime;
|
$this->maxFuelTime = $this->remainingFuelTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->loadName($nbt);
|
$this->loadName($nbt);
|
||||||
@ -84,9 +84,9 @@ class Furnace extends Spawnable implements Container, Nameable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function writeSaveData(CompoundTag $nbt) : void{
|
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_COOK_TIME, $this->cookTime);
|
||||||
$nbt->setShort(self::TAG_MAX_TIME, $this->maxTime);
|
$nbt->setShort(self::TAG_MAX_TIME, $this->maxFuelTime);
|
||||||
$this->saveName($nbt);
|
$this->saveName($nbt);
|
||||||
$this->saveItems($nbt);
|
$this->saveItems($nbt);
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ class Furnace extends Spawnable implements Container, Nameable{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->maxTime = $this->burnTime = $ev->getBurnTime();
|
$this->maxFuelTime = $this->remainingFuelTime = $ev->getBurnTime();
|
||||||
|
|
||||||
$block = $this->getBlock();
|
$block = $this->getBlock();
|
||||||
if($block instanceof BlockFurnace and !$block->isLit()){
|
if($block instanceof BlockFurnace and !$block->isLit()){
|
||||||
@ -136,7 +136,7 @@ class Furnace extends Spawnable implements Container, Nameable{
|
|||||||
$this->getWorld()->setBlock($block, $block);
|
$this->getWorld()->setBlock($block, $block);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->burnTime > 0 and $ev->isBurning()){
|
if($this->remainingFuelTime > 0 and $ev->isBurning()){
|
||||||
$fuel->pop();
|
$fuel->pop();
|
||||||
$this->inventory->setFuel($fuel);
|
$this->inventory->setFuel($fuel);
|
||||||
}
|
}
|
||||||
@ -150,8 +150,8 @@ class Furnace extends Spawnable implements Container, Nameable{
|
|||||||
$this->timings->startTiming();
|
$this->timings->startTiming();
|
||||||
|
|
||||||
$prevCookTime = $this->cookTime;
|
$prevCookTime = $this->cookTime;
|
||||||
$prevBurnTime = $this->burnTime;
|
$prevRemainingFuelTime = $this->remainingFuelTime;
|
||||||
$prevMaxTime = $this->maxTime;
|
$prevMaxFuelTime = $this->maxFuelTime;
|
||||||
|
|
||||||
$ret = false;
|
$ret = false;
|
||||||
|
|
||||||
@ -161,12 +161,12 @@ class Furnace extends Spawnable implements Container, Nameable{
|
|||||||
$smelt = $this->world->getServer()->getCraftingManager()->matchFurnaceRecipe($raw);
|
$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()));
|
$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);
|
$this->checkFuel($fuel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->burnTime > 0){
|
if($this->remainingFuelTime > 0){
|
||||||
--$this->burnTime;
|
--$this->remainingFuelTime;
|
||||||
|
|
||||||
if($smelt instanceof FurnaceRecipe and $canSmelt){
|
if($smelt instanceof FurnaceRecipe and $canSmelt){
|
||||||
++$this->cookTime;
|
++$this->cookTime;
|
||||||
@ -185,8 +185,8 @@ class Furnace extends Spawnable implements Container, Nameable{
|
|||||||
|
|
||||||
$this->cookTime -= 200;
|
$this->cookTime -= 200;
|
||||||
}
|
}
|
||||||
}elseif($this->burnTime <= 0){
|
}elseif($this->remainingFuelTime <= 0){
|
||||||
$this->burnTime = $this->cookTime = $this->maxTime = 0;
|
$this->remainingFuelTime = $this->cookTime = $this->maxFuelTime = 0;
|
||||||
}else{
|
}else{
|
||||||
$this->cookTime = 0;
|
$this->cookTime = 0;
|
||||||
}
|
}
|
||||||
@ -197,22 +197,22 @@ class Furnace extends Spawnable implements Container, Nameable{
|
|||||||
$block->setLit(false);
|
$block->setLit(false);
|
||||||
$this->getWorld()->setBlock($block, $block);
|
$this->getWorld()->setBlock($block, $block);
|
||||||
}
|
}
|
||||||
$this->burnTime = $this->cookTime = $this->maxTime = 0;
|
$this->remainingFuelTime = $this->cookTime = $this->maxFuelTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($prevCookTime !== $this->cookTime){
|
if($prevCookTime !== $this->cookTime){
|
||||||
foreach($this->inventory->getViewers() as $v){
|
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){
|
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){
|
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{
|
class ContainerSetDataPacket extends DataPacket implements ClientboundPacket{
|
||||||
public const NETWORK_ID = ProtocolInfo::CONTAINER_SET_DATA_PACKET;
|
public const NETWORK_ID = ProtocolInfo::CONTAINER_SET_DATA_PACKET;
|
||||||
|
|
||||||
public const PROPERTY_FURNACE_TICK_COUNT = 0;
|
public const PROPERTY_FURNACE_SMELT_PROGRESS = 0;
|
||||||
public const PROPERTY_FURNACE_LIT_TIME = 1;
|
public const PROPERTY_FURNACE_REMAINING_FUEL_TIME = 1;
|
||||||
public const PROPERTY_FURNACE_LIT_DURATION = 2;
|
public const PROPERTY_FURNACE_MAX_FUEL_TIME = 2;
|
||||||
public const PROPERTY_FURNACE_STORED_XP = 3;
|
public const PROPERTY_FURNACE_STORED_XP = 3;
|
||||||
public const PROPERTY_FURNACE_FUEL_AUX = 4;
|
public const PROPERTY_FURNACE_FUEL_AUX = 4;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user