}
@Override
public void onTick(float dt) {
final float fuel = getFuel();
final FurnaceInventory inventory = getInventory();
// Not burning
if (fuel <= 0) {
// Reset any progress
if (getSmeltTime() > 0) {
setSmeltTime(-1);
setMaxSmeltTime(-1);
}
// Try to light the furnace
if (inventory.hasFuel() && inventory.hasIngredient()) {
float newFuel = ((Fuel) inventory.getFuel().getMaterial()).getFuelTime();
FurnaceBurnEvent event = VanillaPlugin.getInstance().getEngine().getEventManager().callEvent(new FurnaceBurnEvent(this, inventory.getFuel(), newFuel));
if (event.isCancelled()) {
return;
}
newFuel = event.getBurnTime();
setMaxFuel(newFuel);
setFuel(newFuel);
inventory.addAmount(FurnaceInventory.FUEL_SLOT, -1);
setBurning(true);
return;
}
setBurning(false);
}
// Burning
else if (fuel > 0) {
setBurning(true);
pulseFuel(dt);
final float smeltTime = getSmeltTime();
if (smeltTime == -1) {
// Try to start smelting
if (inventory.hasIngredient()) {
if (!canSmelt()) {
return;
}
float newSmeltTime = ((TimedCraftable) inventory.getIngredient().getMaterial()).getCraftTime();
setMaxSmeltTime(newSmeltTime);
setSmeltTime(newSmeltTime);
return;
}
}
if (smeltTime <= 0) {
// Try to smelt the current ingredient
if (inventory.hasIngredient()) {
smelt();
return;
}
}
if (smeltTime > 0) {
// Reset progress if ingredient is gone
if (!inventory.hasIngredient()) {
setSmeltTime(-1);
return;
}
pulseSmeltTime(dt);