Inheritance: extends pocketmine\event\block\BlockEvent, implements pocketmine\event\Cancellable
Exemple #1
0
 public function onFuranceSmelt(FurnaceSmeltEvent $event)
 {
     $event->getFurnace()->namedtag["BurnTime"] = 0;
     $event->getFurnace()->namedtag["CookTime"] = 200;
 }
 public function onUpdate()
 {
     if ($this->closed === true) {
         return false;
     }
     $this->timings->startTiming();
     $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) and $product->getCount() < $product->getMaxStackSize() or $product->getId() === Item::AIR));
     if ($this->namedtag["BurnTime"] <= 0 and $canSmelt and $fuel->getFuelTime() !== null and $fuel->getCount() > 0) {
         $this->checkFuel($fuel);
     }
     if ($this->namedtag["BurnTime"] > 0) {
         $this->namedtag->BurnTime = new Short("BurnTime", $this->namedtag["BurnTime"] - 1);
         $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"] + 1);
             if ($this->namedtag["CookTime"] >= 200) {
                 //10 seconds
                 $product = Item::get($smelt->getResult()->getId(), $smelt->getResult()->getDamage(), $product->getCount() + 1);
                 $this->server->getPluginManager()->callEvent($ev = new FurnaceSmeltEvent($this, $raw, $product));
                 if (!$ev->isCancelled()) {
                     $this->inventory->setResult($ev->getResult());
                     $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 {
         if ($this->getBlock()->getId() === Item::BURNING_FURNACE) {
             $this->getLevel()->setBlock($this, Block::get(Item::FURNACE, $this->getBlock()->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);
     $this->timings->stopTiming();
     return $ret;
 }
Exemple #3
0
 public function onFurnaceSmelt(FurnaceSmeltEvent $event)
 {
     $itemSkill = SkillManager::getSkillByItem($event->getSource());
     if (count($itemSkill) > 0) {
         $event->setCancelled();
     }
 }