if (getBrewTime() <= 0) {
// Try to start brewing
if (inventory.hasInput() && inventory.hasOutput()) {
// Ensure the input is able to brew the three output items
for (int i = 0; i < 3; i++) {
ItemStack output = inventory.getOutput(i);
if (output == null) {
continue;
}
if (((PotionReagent) inventory.getInput().getMaterial()).getResult((PotionItem) output.getMaterial()) == null) {
return;
}
}
input = inventory.getInput(); // Store input just in case it is later removed during the brewing process
setBrewTime(1);
inventory.addAmount(BrewingStandInventory.INPUT_SLOT, -1);
}
} else {
// Continue brewing
float newBrewTime = getBrewTime() + dt;
if (newBrewTime > BREW_TIME_INCREMENT) {
// Brewing has finished
newBrewTime = -1;
// Set output
if (inventory.hasOutput()) {
for (int i = 0; i < 3; i++) {
ItemStack output = inventory.getOutput(i);
if (output == null) {
continue;
}
ItemStack result = new ItemStack(((PotionReagent) input.getMaterial()).getResult((PotionItem) output.getMaterial()), 1);
PotionBrewEvent event = new PotionBrewEvent(this, new MaterialCause(output.getMaterial(), this.getBlock()), input, output, result);
VanillaPlugin.getInstance().getEngine().getEventManager().callEvent(event);