Search in sources :

Example 1 with RecipeManager

use of net.glowstone.datapack.RecipeManager 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 RecipeManager

use of net.glowstone.datapack.RecipeManager in project Glowstone by GlowstoneMC.

the class GlowCraftingInventory method craft.

/**
 * Remove a layer of items from the inventory.
 */
public void craft() {
    RecipeManager cm = ((GlowServer) ServerProvider.getServer()).getRecipeManager();
    Recipe recipe = cm.getRecipe(this);
    if (recipe != null) {
        removeItems(getMatrix(), this);
    }
}
Also used : Recipe(org.bukkit.inventory.Recipe) RecipeManager(net.glowstone.datapack.RecipeManager) GlowServer(net.glowstone.GlowServer)

Example 3 with RecipeManager

use of net.glowstone.datapack.RecipeManager in project Glowstone by GlowstoneMC.

the class GlowPlayerInventory method handleShiftClick.

@Override
public void handleShiftClick(GlowPlayer player, InventoryView view, int clickedSlot, ItemStack clickedItem) {
    GlowInventory top = (GlowInventory) view.getTopInventory();
    // If this is the default inventory try to equip the item as armor first
    if (GlowInventoryView.isDefault(view)) {
        clickedItem = tryToFillSlots(clickedItem, 36, 40);
    }
    // Check whether the top inventory allows shift clicking in any of it's slots
    boolean topAllowsShiftClick = false;
    for (int i = 0; i < top.getSize(); i++) {
        if (top.itemShiftClickAllowed(i, clickedItem)) {
            topAllowsShiftClick = true;
            break;
        }
    }
    if (topAllowsShiftClick) {
        if (top.getType().equals(InventoryType.FURNACE)) {
            RecipeManager rm = ((GlowServer) ServerProvider.getServer()).getRecipeManager();
            FuelManager fm = ((GlowServer) ServerProvider.getServer()).getFuelManager();
            if (rm.getRecipe(top.getType(), new ItemStack[] { clickedItem }) != null) {
                // move items are be burnable to the input slot
                // TODO: Use of variable (INPUT_SLOT) instead of hard coded value ?
                clickedItem = top.tryToFillSlots(clickedItem, 0, -1);
            } else if (fm.isFuel(clickedItem.getType())) {
                // move fuel items direct to fuel slot
                // TODO: Use of variable (FUEL_SLOT) instead of hard coded value ?
                clickedItem = top.tryToFillSlots(clickedItem, 1, -1);
            } else {
                // switch them between hotbar and main inventory depending on where they are now
                if (view.convertSlot(clickedSlot) < 9 || view.convertSlot(clickedSlot) >= 36) {
                    // move from hotbar and armor to main inventory
                    clickedItem = tryToFillSlots(clickedItem, 9, 36);
                } else {
                    // move from main inventory to hotbar
                    clickedItem = tryToFillSlots(clickedItem, 0, 9);
                }
            }
        } else {
            // move items to the top inventory
            clickedItem = top.tryToFillSlots(clickedItem, 0, top.getSize());
        }
    } else {
        // switch them between hotbar and main inventory depending on where they are now
        if (view.convertSlot(clickedSlot) < 9 || view.convertSlot(clickedSlot) >= 36) {
            // move from hotbar and armor to main inventory
            clickedItem = tryToFillSlots(clickedItem, 9, 36);
        } else {
            // move from main inventory to hotbar
            clickedItem = tryToFillSlots(clickedItem, 0, 9);
        }
    }
    view.setItem(clickedSlot, clickedItem);
}
Also used : RecipeManager(net.glowstone.datapack.RecipeManager) GlowServer(net.glowstone.GlowServer) ItemStack(org.bukkit.inventory.ItemStack) FuelManager(net.glowstone.datapack.FuelManager)

Example 4 with RecipeManager

use of net.glowstone.datapack.RecipeManager 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)4 RecipeManager (net.glowstone.datapack.RecipeManager)4 FuelManager (net.glowstone.datapack.FuelManager)3 Recipe (org.bukkit.inventory.Recipe)3 GlowFurnaceInventory (net.glowstone.inventory.GlowFurnaceInventory)2 ItemStack (org.bukkit.inventory.ItemStack)2 FurnaceBurnEvent (org.bukkit.event.inventory.FurnaceBurnEvent)1 FurnaceSmeltEvent (org.bukkit.event.inventory.FurnaceSmeltEvent)1