Java Code Examples for org.bukkit.block.Dispenser#getInventory()

The following examples show how to use org.bukkit.block.Dispenser#getInventory() . 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: EnhancedCraftingTable.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onInteract(Player p, Block b) {
    Block dispenser = b.getRelative(BlockFace.DOWN);
    Dispenser disp = (Dispenser) dispenser.getState();
    Inventory inv = disp.getInventory();

    List<ItemStack[]> inputs = RecipeType.getRecipeInputList(this);

    for (int i = 0; i < inputs.size(); i++) {
        if (isCraftable(inv, inputs.get(i))) {
            ItemStack output = RecipeType.getRecipeOutputList(this, inputs.get(i)).clone();
            if (Slimefun.hasUnlocked(p, output, true)) {
                craft(inv, dispenser, p, b, output);
            }

            return;
        }
    }
    SlimefunPlugin.getLocalization().sendMessage(p, "machines.pattern-not-found", true);
}
 
Example 2
Source File: GrindStone.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onInteract(Player p, Block b) {
	Block dispBlock = b.getRelative(BlockFace.DOWN);
	Dispenser disp = (Dispenser) dispBlock.getState();
	Inventory inv = disp.getInventory();
	
	for (ItemStack current : inv.getContents()) {
		for (ItemStack convert : RecipeType.getRecipeInputs(this)) {
			if (convert != null && SlimefunUtils.isItemSimilar(current, convert, true)) {
				ItemStack output = RecipeType.getRecipeOutput(this, convert);
				Inventory outputInv = findOutputInventory(output, dispBlock, inv);
				
				if (outputInv != null) {
					ItemStack removing = current.clone();
					removing.setAmount(1);
					inv.removeItem(removing);
					outputInv.addItem(output);
					p.getWorld().playSound(p.getLocation(), Sound.BLOCK_WOODEN_BUTTON_CLICK_ON, 1, 1);
				}
				else {
					SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
				}
				
				return;
			}
		}
	}
	SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
}
 
Example 3
Source File: PressureChamber.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onInteract(Player p, Block b) {
    Block dispBlock = b.getRelative(BlockFace.UP).getRelative(BlockFace.UP);
    Dispenser disp = (Dispenser) dispBlock.getState();
    Inventory inv = disp.getInventory();

    for (ItemStack current : inv.getContents()) {
        for (ItemStack convert : RecipeType.getRecipeInputs(this)) {
            if (convert != null && SlimefunUtils.isItemSimilar(current, convert, true)) {
                ItemStack output = RecipeType.getRecipeOutput(this, convert);
                Inventory outputInv = findOutputInventory(output, dispBlock, inv);

                if (outputInv != null) {
                    ItemStack removing = current.clone();
                    removing.setAmount(convert.getAmount());
                    inv.removeItem(removing);

                    craft(p, b, output, outputInv);
                }
                else SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);

                return;
            }
        }
    }
    SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
}
 
Example 4
Source File: Juicer.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onInteract(Player p, Block b) {
	Block dispBlock = b.getRelative(BlockFace.DOWN);
	Dispenser disp = (Dispenser) dispBlock.getState();
	Inventory inv = disp.getInventory();
	
	for (ItemStack current : inv.getContents()) {
		for (ItemStack convert : RecipeType.getRecipeInputs(this)) {
			if (convert != null && SlimefunUtils.isItemSimilar(current, convert, true)) {
				ItemStack adding = RecipeType.getRecipeOutput(this, convert);
				Inventory outputInv = findOutputInventory(adding, dispBlock, inv);
				
				if (outputInv != null) {
					ItemStack removing = current.clone();
					removing.setAmount(1);
					inv.removeItem(removing);
					outputInv.addItem(adding);
					p.getWorld().playSound(b.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1F, 1F);
					p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.HAY_BLOCK);
				}
				else SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
				
				return;
			}
		}
	}
	
	SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
}
 
Example 5
Source File: OreCrusher.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onInteract(Player p, Block b) {
    Block dispBlock = b.getRelative(BlockFace.DOWN);
    Dispenser disp = (Dispenser) dispBlock.getState();
    Inventory inv = disp.getInventory();

    for (ItemStack current : inv.getContents()) {
        for (ItemStack convert : RecipeType.getRecipeInputs(this)) {
            if (convert != null && SlimefunUtils.isItemSimilar(current, convert, true)) {
                ItemStack adding = RecipeType.getRecipeOutput(this, convert);
                Inventory outputInv = findOutputInventory(adding, dispBlock, inv);
                if (outputInv != null) {
                    ItemStack removing = current.clone();
                    removing.setAmount(convert.getAmount());
                    inv.removeItem(removing);
                    outputInv.addItem(adding);
                    p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, 1);
                }
                else SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);

                return;
            }
        }
    }

    SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
}
 
Example 6
Source File: ArmorForge.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onInteract(Player p, Block b) {
    Block dispBlock = b.getRelative(BlockFace.DOWN);
    Dispenser disp = (Dispenser) dispBlock.getState();
    Inventory inv = disp.getInventory();
    List<ItemStack[]> inputs = RecipeType.getRecipeInputList(this);

    for (int i = 0; i < inputs.size(); i++) {
        if (isCraftable(inv, inputs.get(i))) {
            ItemStack output = RecipeType.getRecipeOutputList(this, inputs.get(i)).clone();

            if (Slimefun.hasUnlocked(p, output, true)) {
                Inventory outputInv = findOutputInventory(output, dispBlock, inv);

                if (outputInv != null) {
                    craft(p, output, inv, outputInv);
                }
                else {
                    SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
                }
            }
            
            return;
        }
    }

    SlimefunPlugin.getLocalization().sendMessage(p, "machines.pattern-not-found", true);
}
 
Example 7
Source File: Compressor.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onInteract(Player p, Block b) {
	Block dispBlock = b.getRelative(BlockFace.DOWN);
	Dispenser disp = (Dispenser) dispBlock.getState();
	Inventory inv = disp.getInventory();
	
	for (ItemStack item : inv.getContents()) {
		for (ItemStack recipeInput : RecipeType.getRecipeInputs(this)) {
			if (recipeInput != null && SlimefunUtils.isItemSimilar(item, recipeInput, true)) {
				ItemStack output = RecipeType.getRecipeOutput(this, recipeInput);
				Inventory outputInv = findOutputInventory(output, dispBlock, inv);
				
				if (outputInv != null) {
				    ItemStack removing = item.clone();
			        removing.setAmount(recipeInput.getAmount());
			        inv.removeItem(removing);

					craft(p, output, outputInv);
				}
				else {
				    SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
				}
				
				return;
			}
		}
	}
	
	SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
}
 
Example 8
Source File: AbstractSmeltery.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onInteract(Player p, Block b) {
    Block dispBlock = b.getRelative(BlockFace.DOWN);
    Dispenser disp = (Dispenser) dispBlock.getState();
    Inventory inv = disp.getInventory();
    List<ItemStack[]> inputs = RecipeType.getRecipeInputList(this);

    for (int i = 0; i < inputs.size(); i++) {
        if (canCraft(inv, inputs, i)) {
            ItemStack output = RecipeType.getRecipeOutputList(this, inputs.get(i)).clone();

            if (Slimefun.hasUnlocked(p, output, true)) {
                Inventory outputInv = findOutputInventory(output, dispBlock, inv);

                if (outputInv != null) {
                    craft(p, b, inv, inputs.get(i), output, outputInv);
                }
                else {
                    SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
                }
            }

            return;
        }
    }

    SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
}