org.bukkit.inventory.FurnaceInventory Java Examples

The following examples show how to use org.bukkit.inventory.FurnaceInventory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CraftFurnace.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public FurnaceInventory getInventory() {
    if (!this.isPlaced()) {
        return this.getSnapshotInventory();
    }

    return new CraftInventoryFurnace(this.getTileEntity());
}
 
Example #2
Source File: CO2Listener.java    From GlobalWarming with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void onInventoryMoveItemEvent(InventoryMoveItemEvent event) {
    if (event.getItem().getType().isFuel()) {
        if (event.getDestination() instanceof FurnaceInventory) {
            FurnaceInventory furnaceInventory = (FurnaceInventory) event.getDestination();
        }
    }
}
 
Example #3
Source File: LifeskillingListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Fix a bukkit bug where shift click doesn't register.
 *
 * @param e
 * @return
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onSmelting2(InventoryClickEvent e) {
    Inventory clickedInventory = null;
    Player player = (Player) e.getWhoClicked();
    if (e.getSlot() < 0) {
        clickedInventory = null;
    } else if (e.getView().getTopInventory() != null && e.getSlot() < e
            .getView().getTopInventory().getSize()) {
        clickedInventory = e.getView().getTopInventory();
    } else {
        clickedInventory = e.getView().getBottomInventory();
    }
    if (clickedInventory == null) {
        return;
    }
    if (!clickedInventory.getType().equals(InventoryType.FURNACE)) {
        return;
    }
    if (e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR) {
        return;
    }
    FurnaceInventory fi = (FurnaceInventory) clickedInventory;
    boolean click = e.getClick().isShiftClick() || e.getClick()
            .isLeftClick() && e.getRawSlot() == 2;
    boolean item = fi.getResult() != null;

    if (click && item && !fi.getResult().getType().isFuel() && !fi.getResult().getType().isBurnable() && !Util.invFull(player)) {
        for (int i = 0; i < fi.getResult().getAmount(); i++) {
            if (DropManager.smeltingChance > random.nextDouble()) {
                DropManager.randomDrop(player, DropManager.smeltingLootTable);
            }
        }
    }
}
 
Example #4
Source File: EventListener.java    From ProRecipes with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void furnaceCraftEvent(FurnaceCraftEvent event){
	FurnaceInventory inv = (FurnaceInventory)event.getInventory();
	if(event.isCancelled()){
		inv.setResult(new ItemStack(Material.AIR));
		return;
	}else{
		int amount = 0;
		
		ItemStack b = new ItemStack(inv.getItem(0));
		
		amount = b.getAmount();
		
		int newAmount = amount - ProRecipes.getPlugin().getRecipes().fur.get(event.getRecipe().getId()).getSubtractAmount();
		ItemStack i = event.getSource().clone();
		i.setAmount(newAmount);
		inv.setSmelting(i);
		if(inv.getResult() != null && inv.getResult().isSimilar(event.getResult())){
			ItemStack re = event.getResult().clone();
			re.setAmount(re.getAmount() + inv.getResult().getAmount());
			inv.setResult(re);
		}else{
			inv.setResult(event.getResult());
		}
		
		ProRecipes.getPlugin().incrementRecipesCrafted(RecipeType.FURNACE);
		
	}
}
 
Example #5
Source File: CargoUtils.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
static ItemStack withdrawFromVanillaInventory(Block node, ItemStack template, Inventory inv) {
    ItemStack[] contents = inv.getContents();
    int minSlot = 0;
    int maxSlot = contents.length;

    if (inv instanceof FurnaceInventory) {
        minSlot = 2;
        maxSlot = 3;
    }
    else if (inv instanceof BrewerInventory) {
        maxSlot = 3;
    }

    ItemStackWrapper wrapper = new ItemStackWrapper(template);

    for (int slot = minSlot; slot < maxSlot; slot++) {
        // Changes to this ItemStack are synchronized with the Item in the Inventory
        ItemStack itemInSlot = contents[slot];

        if (SlimefunUtils.isItemSimilar(itemInSlot, wrapper, true) && matchesFilter(node, itemInSlot)) {
            if (itemInSlot.getAmount() > template.getAmount()) {
                itemInSlot.setAmount(itemInSlot.getAmount() - template.getAmount());
                return template;
            }
            else {
                ItemStack clone = itemInSlot.clone();
                itemInSlot.setAmount(0);
                return clone;
            }
        }
    }

    return null;
}
 
Example #6
Source File: Furnace.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public FurnaceInventory getInventory();
 
Example #7
Source File: Furnace.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public FurnaceInventory getSnapshotInventory();
 
Example #8
Source File: CraftFurnace.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public FurnaceInventory getSnapshotInventory() {
    return new CraftInventoryFurnace(this.getSnapshot());
}
 
Example #9
Source File: ExprFurnaceSlot.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
public FurnaceEventSlot(final Event e, final FurnaceInventory invi) {
	super(invi, slot);
	this.e = e;
}
 
Example #10
Source File: Kitchen.java    From ExoticGarden with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onInteract(Player p, Block b) {
    Block dispenser = b.getRelative(BlockFace.DOWN);

    Furnace furnace = locateFurnace(dispenser);
    FurnaceInventory furnaceInventory = furnace.getInventory();

    Inventory inv = ((Dispenser) dispenser.getState()).getInventory();
    List<ItemStack[]> inputs = RecipeType.getRecipeInputList(this);

    recipe:
    for (ItemStack[] input : inputs) {
        for (int i = 0; i < inv.getContents().length; i++) {
            if (!SlimefunUtils.isItemSimilar(inv.getContents()[i], input[i], true)) continue recipe;
        }

        ItemStack adding = RecipeType.getRecipeOutputList(this, input);

        if (Slimefun.hasUnlocked(p, adding, true)) {
            boolean canFit = furnaceInventory.getResult() == null || (furnaceInventory.getResult().getAmount() + adding.getAmount() <= 64 && SlimefunUtils.isItemSimilar(furnaceInventory.getResult(), adding, true));

            if (!canFit) {
                SlimefunPlugin.getLocal().sendMessage(p, "machines.full-inventory", true);
                return;
            }

            for (int i = 0; i < inv.getContents().length; i++) {
                ItemStack item = inv.getItem(i);

                if (item != null) {
                    ItemUtils.consumeItem(item, item.getType() == Material.MILK_BUCKET);
                }
            }

            Bukkit.getScheduler().runTaskLater(plugin, () -> p.getWorld().playSound(furnace.getLocation(), Sound.BLOCK_LAVA_EXTINGUISH, 1F, 1F), 55L);

            for (int i = 1; i < 7; i++) {
                Bukkit.getScheduler().runTaskLater(plugin, () -> p.getWorld().playSound(furnace.getLocation(), Sound.BLOCK_METAL_PLACE, 7F, 1F), i * 5L);
            }

            if (furnaceInventory.getResult() == null) {
                furnaceInventory.setResult(adding);
            }
            else {
                furnaceInventory.getResult().setAmount(furnaceInventory.getResult().getAmount() + adding.getAmount());
            }
        }

        return;
    }

    SlimefunPlugin.getLocal().sendMessage(p, "machines.pattern-not-found", true);
}
 
Example #11
Source File: CraftFurnace.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
public FurnaceInventory getInventory() {
    return new CraftInventoryFurnace(furnace);
}
 
Example #12
Source File: CargoUtils.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
static ItemStack insertIntoVanillaInventory(ItemStack stack, Inventory inv) {
    ItemStack[] contents = inv.getContents();
    int minSlot = 0;
    int maxSlot = contents.length;

    // Check if it is a normal furnace
    if (inv instanceof FurnaceInventory) {
        // Check if it is fuel or not
        if (stack.getType().isFuel()) {
            maxSlot = 2;

            // Any non-smeltable items should not land in the upper slot
            if (!isSmeltable(stack, true)) {
                minSlot = 1;
            }
        }
        else {
            maxSlot = 1;
        }
    }
    else if (inv instanceof BrewerInventory) {
        if (stack.getType() == Material.POTION || stack.getType() == Material.LINGERING_POTION || stack.getType() == Material.SPLASH_POTION) {
            // Potions slot
            maxSlot = 3;
        }
        else if (stack.getType() == Material.BLAZE_POWDER) {
            // Blaze Powder slot
            minSlot = 4;
            maxSlot = 5;
        }
        else {
            // Input slot
            minSlot = 3;
            maxSlot = 4;
        }
    }

    ItemStackWrapper wrapper = new ItemStackWrapper(stack);

    for (int slot = minSlot; slot < maxSlot; slot++) {
        // Changes to this ItemStack are synchronized with the Item in the Inventory
        ItemStack itemInSlot = contents[slot];

        if (itemInSlot == null) {
            inv.setItem(slot, stack);
            return null;
        }
        else {
            int maxStackSize = itemInSlot.getType().getMaxStackSize();

            if (SlimefunUtils.isItemSimilar(itemInSlot, wrapper, true, false) && itemInSlot.getAmount() < maxStackSize) {
                int amount = itemInSlot.getAmount() + stack.getAmount();

                if (amount > maxStackSize) {
                    stack.setAmount(amount - maxStackSize);
                }
                else {
                    stack = null;
                }

                itemInSlot.setAmount(Math.min(amount, maxStackSize));
                // Setting item in inventory will clone the ItemStack
                inv.setItem(slot, itemInSlot);

                return stack;
            }
        }
    }

    return stack;
}
 
Example #13
Source File: Recipes.java    From ProRecipes with GNU General Public License v2.0 3 votes vote down vote up
public void refreshCraft(final FurnaceInventory inv){
final ItemStack i = inv.getResult().clone();

inv.setResult(null);
		
	

ProRecipes.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(ProRecipes.getPlugin(), new Runnable(){

	@Override
	public void run() {
		if(inv.getResult() != null && inv.getResult().isSimilar(i)){
			ItemStack ne = i.clone();
			i.setAmount(i.getAmount() + inv.getResult().getAmount());
			inv.setResult(ne);
		}else{
			inv.getHolder().getLocation().getWorld().dropItem(inv.getHolder().getLocation(), i);
		}
		
	}
	
	
	}, 20*10 - 1);



}