Search in sources :

Example 1 with GlowFurnaceInventory

use of net.glowstone.inventory.GlowFurnaceInventory in project Glowstone by GlowstoneMC.

the class FurnaceEntity method isBurnable.

private boolean isBurnable() {
    GlowFurnaceInventory inv = (GlowFurnaceInventory) getInventory();
    if ((burnTime != 0 || !InventoryUtil.isEmpty(inv.getFuel())) && !InventoryUtil.isEmpty(inv.getSmelting())) {
        if ((InventoryUtil.isEmpty(inv.getFuel()) || InventoryUtil.isEmpty(inv.getSmelting())) && burnTime == 0) {
            return false;
        }
        RecipeManager rm = ((GlowServer) ServerProvider.getServer()).getRecipeManager();
        FuelManager fm = ((GlowServer) ServerProvider.getServer()).getFuelManager();
        if (burnTime != 0 || fm.isFuel(inv.getFuel().getType())) {
            Recipe recipe = rm.getRecipe(inv);
            if (recipe != null && (InventoryUtil.isEmpty(inv.getResult()) || inv.getResult().getType().equals(recipe.getResult().getType()) && inv.getResult().getAmount() + recipe.getResult().getAmount() <= recipe.getResult().getMaxStackSize())) {
                return true;
            }
        }
    }
    return false;
}
Also used : GlowFurnaceInventory(net.glowstone.inventory.GlowFurnaceInventory) Recipe(org.bukkit.inventory.Recipe) RecipeManager(net.glowstone.datapack.RecipeManager) GlowServer(net.glowstone.GlowServer) FuelManager(net.glowstone.datapack.FuelManager)

Example 2 with GlowFurnaceInventory

use of net.glowstone.inventory.GlowFurnaceInventory in project Glowstone by GlowstoneMC.

the class FurnaceEntity method burn.

/**
 * Advances the cooking process for the tick.
 */
// TODO: Change block on burning
public void burn() {
    GlowFurnaceInventory inv = (GlowFurnaceInventory) getInventory();
    boolean sendChange = false;
    if (burnTime > 0) {
        burnTime--;
        sendChange = true;
    }
    boolean isBurnable = isBurnable();
    if (cookTime > 0 && isBurnable) {
        cookTime++;
        sendChange = true;
    } else if (burnTime != 0) {
        cookTime = 0;
        sendChange = true;
    }
    if (cookTime == 0 && isBurnable) {
        cookTime = 1;
        sendChange = true;
    }
    if (burnTime == 0) {
        if (isBurnable) {
            FuelManager fm = ((GlowServer) ServerProvider.getServer()).getFuelManager();
            FurnaceBurnEvent burnEvent = new FurnaceBurnEvent(block, inv.getFuel(), fm.getFuelTime(inv.getFuel().getType()));
            EventFactory.getInstance().callEvent(burnEvent);
            if (!burnEvent.isCancelled() && burnEvent.isBurning()) {
                burnTime = (short) burnEvent.getBurnTime();
                burnTimeFuel = burnTime;
                if (inv.getFuel().getAmount() == 1) {
                    if (inv.getFuel().getType().equals(Material.LAVA_BUCKET)) {
                        inv.setFuel(new ItemStack(Material.BUCKET));
                    } else {
                        inv.setFuel(null);
                    }
                } else {
                    inv.getFuel().setAmount(inv.getFuel().getAmount() - 1);
                }
                sendChange = true;
            } else if (cookTime != 0) {
                if (cookTime % 2 == 0) {
                    cookTime = (short) (cookTime - 2);
                } else {
                    cookTime--;
                }
                sendChange = true;
            }
        } else if (cookTime != 0) {
            if (cookTime % 2 == 0) {
                cookTime = (short) (cookTime - 2);
            } else {
                cookTime--;
            }
            sendChange = true;
        }
    }
    if (cookTime == 200) {
        RecipeManager rm = ((GlowServer) ServerProvider.getServer()).getRecipeManager();
        Recipe recipe = rm.getRecipe(inv);
        if (recipe != null) {
            FurnaceSmeltEvent smeltEvent = new FurnaceSmeltEvent(block, inv.getSmelting(), recipe.getResult());
            EventFactory.getInstance().callEvent(smeltEvent);
            if (!smeltEvent.isCancelled()) {
                if (inv.getSmelting().getType().equals(Material.SPONGE) && inv.getSmelting().getData().getData() == 1 && inv.getFuel() != null && inv.getFuel().getType().equals(Material.BUCKET) && inv.getFuel().getAmount() == 1) {
                    inv.setFuel(new ItemStack(Material.WATER_BUCKET));
                }
                if (inv.getResult() == null || inv.getResult().getType().equals(Material.AIR)) {
                    inv.setResult(smeltEvent.getResult());
                } else if (inv.getResult().getType().equals(smeltEvent.getResult().getType())) {
                    inv.getResult().setAmount(inv.getResult().getAmount() + smeltEvent.getResult().getAmount());
                }
                if (inv.getSmelting().getAmount() == 1) {
                    inv.setSmelting(null);
                } else {
                    inv.getSmelting().setAmount(inv.getSmelting().getAmount() - 1);
                }
            }
            cookTime = 0;
            sendChange = true;
        }
    }
    inv.getViewersSet().forEach(human -> {
        human.setWindowProperty(Property.BURN_TIME, burnTime);
        human.setWindowProperty(Property.TICKS_FOR_CURRENT_FUEL, burnTimeFuel);
        human.setWindowProperty(Property.COOK_TIME, cookTime);
        human.setWindowProperty(Property.TICKS_FOR_CURRENT_SMELTING, 200);
    });
    if (!isBurnable && burnTime == 0 && cookTime == 0) {
        getState().getBlock().getWorld().cancelPulse(getState().getBlock());
        sendChange = true;
    }
    if (sendChange) {
        updateInRange();
    }
}
Also used : FurnaceBurnEvent(org.bukkit.event.inventory.FurnaceBurnEvent) GlowFurnaceInventory(net.glowstone.inventory.GlowFurnaceInventory) Recipe(org.bukkit.inventory.Recipe) RecipeManager(net.glowstone.datapack.RecipeManager) GlowServer(net.glowstone.GlowServer) ItemStack(org.bukkit.inventory.ItemStack) FurnaceSmeltEvent(org.bukkit.event.inventory.FurnaceSmeltEvent) FuelManager(net.glowstone.datapack.FuelManager)

Aggregations

GlowServer (net.glowstone.GlowServer)2 FuelManager (net.glowstone.datapack.FuelManager)2 RecipeManager (net.glowstone.datapack.RecipeManager)2 GlowFurnaceInventory (net.glowstone.inventory.GlowFurnaceInventory)2 Recipe (org.bukkit.inventory.Recipe)2 FurnaceBurnEvent (org.bukkit.event.inventory.FurnaceBurnEvent)1 FurnaceSmeltEvent (org.bukkit.event.inventory.FurnaceSmeltEvent)1 ItemStack (org.bukkit.inventory.ItemStack)1