Search in sources :

Example 1 with CraftingManager

use of net.glowstone.inventory.crafting.CraftingManager 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)) {
            CraftingManager cm = ((GlowServer) Bukkit.getServer()).getCraftingManager();
            if (cm.getFurnaceRecipe(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 (cm.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 : CraftingManager(net.glowstone.inventory.crafting.CraftingManager) GlowServer(net.glowstone.GlowServer)

Example 2 with CraftingManager

use of net.glowstone.inventory.crafting.CraftingManager in project Glowstone by GlowstoneMC.

the class GlowCraftingInventory method craft.

/**
     * Remove a layer of items from the inventory.
     */
public void craft() {
    ItemStack[] matrix = getMatrix();
    CraftingManager cm = ((GlowServer) Bukkit.getServer()).getCraftingManager();
    Recipe recipe = cm.getCraftingRecipe(matrix);
    if (recipe != null) {
        cm.removeItems(matrix, this);
    }
}
Also used : CraftingManager(net.glowstone.inventory.crafting.CraftingManager) GlowServer(net.glowstone.GlowServer)

Example 3 with CraftingManager

use of net.glowstone.inventory.crafting.CraftingManager in project Glowstone by GlowstoneMC.

the class FurnaceEntity method burn.

// TODO: Change block on burning
public void burn() {
    GlowFurnaceInventory inv = (GlowFurnaceInventory) getInventory();
    if (burnTime > 0)
        burnTime--;
    boolean isBurnable = isBurnable();
    if (cookTime > 0 && isBurnable) {
        cookTime++;
    } else if (burnTime != 0) {
        cookTime = 0;
    }
    if (cookTime == 0 && isBurnable) {
        cookTime = 1;
    }
    if (burnTime == 0) {
        if (isBurnable) {
            CraftingManager cm = ((GlowServer) Bukkit.getServer()).getCraftingManager();
            FurnaceBurnEvent burnEvent = new FurnaceBurnEvent(block, inv.getFuel(), cm.getFuelTime(inv.getFuel().getType()));
            EventFactory.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);
                }
            } else if (cookTime != 0) {
                if (cookTime % 2 == 0) {
                    cookTime = (short) (cookTime - 2);
                } else {
                    cookTime--;
                }
            }
        } else if (cookTime != 0) {
            if (cookTime % 2 == 0) {
                cookTime = (short) (cookTime - 2);
            } else {
                cookTime--;
            }
        }
    }
    if (cookTime == 200) {
        CraftingManager cm = ((GlowServer) Bukkit.getServer()).getCraftingManager();
        Recipe recipe = cm.getFurnaceRecipe(inv.getSmelting());
        if (recipe != null) {
            FurnaceSmeltEvent smeltEvent = new FurnaceSmeltEvent(block, inv.getSmelting(), recipe.getResult());
            EventFactory.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;
        }
    }
    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());
    }
}
Also used : FurnaceBurnEvent(org.bukkit.event.inventory.FurnaceBurnEvent) GlowFurnaceInventory(net.glowstone.inventory.GlowFurnaceInventory) Recipe(org.bukkit.inventory.Recipe) CraftingManager(net.glowstone.inventory.crafting.CraftingManager) GlowServer(net.glowstone.GlowServer) ItemStack(org.bukkit.inventory.ItemStack) FurnaceSmeltEvent(org.bukkit.event.inventory.FurnaceSmeltEvent)

Aggregations

GlowServer (net.glowstone.GlowServer)3 CraftingManager (net.glowstone.inventory.crafting.CraftingManager)3 GlowFurnaceInventory (net.glowstone.inventory.GlowFurnaceInventory)1 FurnaceBurnEvent (org.bukkit.event.inventory.FurnaceBurnEvent)1 FurnaceSmeltEvent (org.bukkit.event.inventory.FurnaceSmeltEvent)1 ItemStack (org.bukkit.inventory.ItemStack)1 Recipe (org.bukkit.inventory.Recipe)1