setFuel() public méthode

public setFuel ( Item $item ) : boolean
$item pocketmine\item\Item
Résultat boolean
 protected function checkFuel(Item $fuel)
 {
     $this->server->getPluginManager()->callEvent($ev = new FurnaceBurnEvent($this, $fuel, $fuel->getFuelTime()));
     if ($ev->isCancelled()) {
         return;
     }
     $this->namedtag->MaxTime = new Short("MaxTime", $ev->getBurnTime());
     $this->namedtag->BurnTime = new Short("BurnTime", $ev->getBurnTime());
     $this->namedtag->BurnTicks = new Short("BurnTicks", 0);
     if ($this->getBlock()->getId() === Item::FURNACE) {
         $this->getLevel()->setBlock($this, Block::get(Item::BURNING_FURNACE, $this->getBlock()->getDamage()), true);
     }
     if ($this->namedtag["BurnTime"] > 0 and $ev->isBurning()) {
         $fuel->setCount($fuel->getCount() - 1);
         if ($fuel->getCount() === 0) {
             $fuel = Item::get(Item::AIR, 0, 0);
         }
         $this->inventory->setFuel($fuel);
     }
 }
Exemple #2
0
 public function onUpdate()
 {
     if ($this->closed === true) {
         return false;
     }
     $ret = false;
     $fuel = $this->inventory->getFuel();
     $raw = $this->inventory->getSmelting();
     $product = $this->inventory->getResult();
     $smelt = $this->server->getCraftingManager()->matchFurnaceRecipe($raw);
     $canSmelt = ($smelt instanceof FurnaceRecipe and $raw->getCount() > 0 and ($smelt->getResult()->equals($product, true) and $product->getCount() < $product->getMaxStackSize() or $product->getID() === Item::AIR));
     if ($this->namedtag["BurnTime"] <= 0 and $canSmelt and $fuel->getFuelTime() !== false and $fuel->getCount() > 0) {
         $this->lastUpdate = microtime(true);
         $time = floor($fuel->getFuelTime() * 20);
         $this->namedtag->MaxTime = new Short("MaxTime", $time);
         $this->namedtag->BurnTime = new Short("BurnTime", $time);
         $this->namedtag->BurnTicks = new Short("BurnTicks", 0);
         $fuel->setCount($fuel->getCount() - 1);
         if ($fuel->getCount() === 0) {
             $fuel = Item::get(Item::AIR, 0, 0);
         }
         $this->inventory->setFuel($fuel);
         $current = $this->getLevel()->getBlock($this);
         if ($current->getID() === Item::FURNACE) {
             $this->getLevel()->setBlock($this, Block::get(Item::BURNING_FURNACE, $current->getDamage()), true);
         }
     }
     if ($this->namedtag["BurnTime"] > 0) {
         $ticks = (microtime(true) - $this->lastUpdate) * 20;
         $this->namedtag->BurnTime = new Short("BurnTime", $this->namedtag["BurnTime"] - $ticks);
         $this->namedtag->BurnTicks = new Short("BurnTicks", ceil($this->namedtag["BurnTime"] / $this->namedtag["MaxTime"] * 200));
         if ($smelt instanceof FurnaceRecipe and $canSmelt) {
             $this->namedtag->CookTime = new Short("CookTime", $this->namedtag["CookTime"] + $ticks);
             if ($this->namedtag["CookTime"] >= 200) {
                 //10 seconds
                 $product = Item::get($smelt->getResult()->getID(), $smelt->getResult()->getDamage(), $product->getCount() + 1);
                 $this->inventory->setResult($product);
                 $raw->setCount($raw->getCount() - 1);
                 if ($raw->getCount() === 0) {
                     $raw = Item::get(Item::AIR, 0, 0);
                 }
                 $this->inventory->setSmelting($raw);
                 $this->namedtag->CookTime = new Short("CookTime", $this->namedtag["CookTime"] - 200);
             }
         } elseif ($this->namedtag["BurnTime"] <= 0) {
             $this->namedtag->BurnTime = new Short("BurnTime", 0);
             $this->namedtag->CookTime = new Short("CookTime", 0);
             $this->namedtag->BurnTicks = new Short("BurnTicks", 0);
         } else {
             $this->namedtag->CookTime = new Short("CookTime", 0);
         }
         $ret = true;
     } else {
         $current = $this->getLevel()->getBlock($this);
         if ($current->getID() === Item::BURNING_FURNACE) {
             $this->getLevel()->setBlock($this, Block::get(Item::FURNACE, $current->getDamage()), true);
         }
         $this->namedtag->BurnTime = new Short("BurnTime", 0);
         $this->namedtag->CookTime = new Short("CookTime", 0);
         $this->namedtag->BurnTicks = new Short("BurnTicks", 0);
     }
     foreach ($this->getInventory()->getViewers() as $player) {
         $windowId = $player->getWindowId($this->getInventory());
         if ($windowId > 0) {
             $pk = new ContainerSetDataPacket();
             $pk->windowid = $windowId;
             $pk->property = 0;
             //Smelting
             $pk->value = floor($this->namedtag["CookTime"]);
             $player->dataPacket($pk);
             $pk = new ContainerSetDataPacket();
             $pk->windowid = $windowId;
             $pk->property = 1;
             //Fire icon
             $pk->value = $this->namedtag["BurnTicks"];
             $player->dataPacket($pk);
         }
     }
     $this->lastUpdate = microtime(true);
     return $ret;
 }