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;
}