Inventories
Inventory interface usage examples
Adding Items
// Example: Adding items to the inventory
ItemStack item1 = new ItemStack(VanillaMaterial.DIAMOND.getMaterial(), 10);
ItemStack item2 = new ItemStack(VanillaMaterial.IRON_INGOT.getMaterial(), 20);
HashMap<Integer, ItemStack> failedItems = inventory.addItem(item1, item2);
if (!failedItems.isEmpty()) {
Cotton.getLogger().info("Some items couldn't be added to the inventory:");
failedItems.forEach((slot, item) -> {
Cotton.getLogger().info("Slot: " + slot + ", Item: " + item);
});
}Checking for Items
// Example: Checking if the inventory contains a material with a minimum amount
boolean containsMaterial = inventory.contains(VanillaMaterial.IRON_INGOT.getMaterial(), 10);
Cotton.getLogger().info("Inventory contains at least 10 iron ingots: " + containsMaterial);Retrieving Items
Removing Items
Clearing Inventory
Setting Contents
Querying Inventory Information
Last updated