getIngredient() public method

public getIngredient ( ) : Item
return pocketmine\item\Item
コード例 #1
0
 public function onUpdate()
 {
     if ($this->closed === true) {
         return false;
     }
     $this->timings->startTiming();
     $ret = false;
     $ingredient = $this->inventory->getIngredient();
     $potions = $this->inventory->getPotions();
     $canBrew = false;
     foreach ($potions as $pot) {
         if ($pot->getId() === Item::POTION) {
             $canBrew = true;
         }
     }
     if ($this->namedtag["BrewTime"] <= self::MAX_BREW_TIME and $canBrew and $ingredient->getCount() > 0) {
         if (!$this->checkIngredient($ingredient)) {
             $canBrew = false;
         }
     } else {
         $canBrew = false;
     }
     if ($canBrew) {
         $this->namedtag->BrewTime = new ShortTag("BrewTime", $this->namedtag["BrewTime"] - 1);
         if ($this->namedtag["BrewTime"] <= 0) {
             //20 seconds
             foreach ($this->inventory->getPotions() as $slot => $potion) {
                 $recipe = Server::getInstance()->getCraftingManager()->matchBrewingRecipe($ingredient, $potion);
                 if ($recipe instanceof BrewingRecipe) {
                     $this->inventory->setPotion($slot, $recipe->getResult());
                 } elseif ($ingredient->getId() === Item::GUNPOWDER && $potion->getId() === Item::POTION) {
                     $this->inventory->setPotion($slot, new SplashPotion($potion->getDamage()));
                 }
             }
             $ingredient->count--;
             $this->inventory->setIngredient($ingredient);
             $this->namedtag->BrewTime = new ShortTag("BrewTime", $this->namedtag["BrewTime"] + 400);
         }
         foreach ($this->getInventory()->getViewers() as $player) {
             $windowId = $player->getWindowId($this->getInventory());
             if ($windowId > 0) {
                 $pk = new ContainerSetDataPacket();
                 $pk->windowid = $windowId;
                 $pk->property = 0;
                 //Brewing
                 $pk->value = floor($this->namedtag["BrewTime"]);
                 $player->dataPacket($pk);
             }
         }
         $ret = true;
     } else {
         $this->namedtag->BrewTime = new ShortTag("BrewTime", self::MAX_BREW_TIME);
         $ret = false;
     }
     $this->lastUpdate = microtime(true);
     $this->timings->stopTiming();
     return $ret;
 }
コード例 #2
0
ファイル: BrewingStand.php プロジェクト: PepbookPvP/Genisys
 public function onUpdate()
 {
     if ($this->closed === true) {
         return false;
     }
     $this->timings->startTiming();
     $ret = false;
     $ingredient = $this->inventory->getIngredient();
     $canBrew = false;
     for ($i = 1; $i <= 3; $i++) {
         if ($this->inventory->getItem($i)->getId() == Item::POTION) {
             $canBrew = true;
             break;
         }
     }
     if ($this->namedtag["CookTime"] <= self::MAX_BREW_TIME and $canBrew and $ingredient->getCount() > 0) {
         //if(!$this->checkIngredient($ingredient)) $canBrew = false;
         //TODO: check ingredients
     } else {
         $canBrew = false;
     }
     if ($canBrew) {
         $this->namedtag->CookTime = new ShortTag("CookTime", $this->namedtag["CookTime"] - 1);
         if ($this->namedtag["CookTime"] <= 0) {
             for ($i = 1; $i <= 3; $i++) {
                 $potion = $this->inventory->getItem($i);
                 $recipe = Server::getInstance()->getCraftingManager()->matchBrewingRecipe($ingredient, $potion);
                 if ($recipe != null) {
                     $this->inventory->setItem($i, $recipe->getResult());
                 }
             }
             $ingredient->count--;
             if ($ingredient->getCount() <= 0) {
                 $ingredient = Item::get(Item::AIR);
             }
             $this->inventory->setIngredient($ingredient);
         }
         foreach ($this->getInventory()->getViewers() as $player) {
             $windowId = $player->getWindowId($this->getInventory());
             if ($windowId > 0) {
                 $pk = new ContainerSetDataPacket();
                 $pk->windowid = $windowId;
                 $pk->property = 0;
                 //Brew
                 $pk->value = $this->namedtag["CookTime"];
                 $player->dataPacket($pk);
             }
         }
         $ret = true;
     } else {
         $this->namedtag->CookTime = new ShortTag("CookTime", self::MAX_BREW_TIME);
     }
     $this->lastUpdate = microtime(true);
     $this->timings->stopTiming();
     return $ret;
 }
コード例 #3
0
 public function onUpdate()
 {
     if ($this->closed === true) {
         return false;
     }
     $this->timings->startTiming();
     $ret = false;
     $ingredient = $this->inventory->getIngredient();
     $product = $this->inventory->getResult();
     $brew = $this->server->getCraftingManager()->matchBrewingRecipe($ingredient);
     $canbrew = ($brew instanceof BrewingRecipe and $ingredient->getCount() > 0 and ($brew->getResult()->equals($product) and $product->getCount() < $product->getMaxStackSize() or $product->getId() === Item::AIR));
     $this->namedtag->BrewTime = new Short("BrewTime", $this->namedtag["BrewTime"] - 1);
     $this->namedtag->BrewTicks = new Short("BrewTicks", ceil($this->namedtag["BrewTime"] / $this->namedtag["MaxTime"] * 200));
     if ($brew instanceof BrewingRecipe and $canbrew) {
         $product = Item::get($brew->getResult()->getId(), $brew->getResult()->getDamage(), $product->getCount() + 1);
         $this->server->getPluginManager()->callEvent($ev = new BrewingStandBrewEvent($this, $ingredient, $product));
         if (!$ev->isCancelled()) {
             $this->inventory->setResult($ev->getResult());
             $ingredient->setCount($ingredient->getCount() - 1);
             if ($ingredient->getCount() === 0) {
                 $ingredient = Item::get(Item::AIR, 0, 0);
             }
             $this->inventory->setbrewing($ingredient);
         }
     }
     $ret = true;
     foreach ($this->getInventory()->getViewers() as $player) {
         $windowId = $player->getWindowId($this->getInventory());
         if ($windowId > 0) {
             $pk = new ContainerSetDataPacket();
             $pk->windowid = $windowId;
             $pk->property = 0;
             //Brew
             $player->dataPacket($pk);
             $pk = new ContainerSetDataPacket();
             $pk->windowid = $windowId;
             $pk->property = 1;
             //Bubble Icon
             $player->dataPacket($pk);
         }
     }
     $this->lastUpdate = microtime(true);
     $this->timings->stopTiming();
     return $ret;
 }