228 if($this->closed ===
true){
232 $this->timings->startTiming();
236 $fuel = $this->inventory->getFuel();
237 $raw = $this->inventory->getSmelting();
238 $product = $this->inventory->getResult();
239 $smelt = $this->server->getCraftingManager()->matchFurnaceRecipe($raw);
240 $canSmelt = ($smelt instanceof FurnaceRecipe and $raw->getCount() > 0 and (($smelt->getResult()->equals($product) and $product->getCount() < $product->getMaxStackSize()) or $product->getId() ===
Item::AIR));
242 if($this->namedtag[
"BurnTime"] <= 0 and $canSmelt and $fuel->getFuelTime() !== null and $fuel->getCount() > 0){
246 if($this->namedtag[
"BurnTime"] > 0){
247 $this->namedtag->BurnTime =
new ShortTag(
"BurnTime", $this->namedtag[
"BurnTime"] - 1);
248 $this->namedtag->BurnTicks =
new ShortTag(
"BurnTicks",
ceil(($this->namedtag[
"BurnTime"] / $this->namedtag[
"MaxTime"] * 200)));
250 if($smelt instanceof FurnaceRecipe and $canSmelt){
251 $this->namedtag->CookTime =
new ShortTag(
"CookTime", $this->namedtag[
"CookTime"] + 1);
252 if($this->namedtag[
"CookTime"] >= 200){
253 $product =
Item::get($smelt->getResult()->getId(), $smelt->getResult()->getDamage(), $product->getCount() + 1);
255 $this->server->getPluginManager()->callEvent($ev =
new FurnaceSmeltEvent($this, $raw, $product));
257 if(!$ev->isCancelled()){
258 $this->inventory->setResult($ev->getResult());
259 $raw->setCount($raw->getCount() - 1);
260 if($raw->getCount() === 0){
263 $this->inventory->setSmelting($raw);
266 $this->namedtag->CookTime =
new ShortTag(
"CookTime", $this->namedtag[
"CookTime"] - 200);
268 }elseif($this->namedtag[
"BurnTime"] <= 0){
269 $this->namedtag->BurnTime =
new ShortTag(
"BurnTime", 0);
270 $this->namedtag->CookTime =
new ShortTag(
"CookTime", 0);
271 $this->namedtag->BurnTicks =
new ShortTag(
"BurnTicks", 0);
273 $this->namedtag->CookTime =
new ShortTag(
"CookTime", 0);
280 $this->namedtag->BurnTime =
new ShortTag(
"BurnTime", 0);
281 $this->namedtag->CookTime =
new ShortTag(
"CookTime", 0);
282 $this->namedtag->BurnTicks =
new ShortTag(
"BurnTicks", 0);
285 foreach($this->
getInventory()->getViewers() as $player){
286 $windowId = $player->getWindowId($this->
getInventory());
288 $pk =
new ContainerSetDataPacket();
289 $pk->windowid = $windowId;
291 $pk->value =
floor($this->namedtag[
"CookTime"]);
292 $player->dataPacket($pk);
294 $pk =
new ContainerSetDataPacket();
295 $pk->windowid = $windowId;
297 $pk->value = $this->namedtag[
"BurnTicks"];
298 $player->dataPacket($pk);
303 $this->lastUpdate = microtime(
true);
305 $this->timings->stopTiming();