return getData().get(VanillaData.BREWING_STAND_INVENTORY);
}
@Override
public void onTick(float dt) {
BrewingStandInventory inventory = getInventory();
// Update brewing stand display with number of output slots filled
int filledSlots = 0;
if (inventory.hasOutput()) {
for (int i = 0; i < 3; i++) {
if (inventory.getOutput(i) != null) {
filledSlots++;
}
}
}
VanillaMaterials.BREWING_STAND_BLOCK.setFilledPotionSlots(getBlock(), filledSlots);
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);
if (!event.isCancelled()) {
inventory.set(i, event.getResult());
}
}
}
}
setBrewTime(newBrewTime);