Class ItemUtils

java.lang.Object
io.github.bakedlibs.dough.items.ItemUtils

public final class ItemUtils extends Object
A utility class providing some methods to handle ItemStacks.
Author:
TheBusyBiscuit
  • Method Details

    • getItemName

      @Nonnull public static String getItemName(@Nullable ItemStack item)
      This method returns a human-readable version of this item's name. If the specified ItemStack has a Custom Display Name, it will return that. Otherwise it will return the english name of it's Material
      Parameters:
      item - The Item to format
      Returns:
      The formatted Item Name
    • canStack

      public static boolean canStack(@Nullable ItemStack a, @Nullable ItemStack b)
      This method compares two instances of ItemStack and checks whether their Material and ItemMeta match.
      Parameters:
      a - ItemStack One
      b - ItemStack Two
      Returns:
      Whether the two instances of ItemStack are similiar and can be stacked.
    • damageItem

      public static void damageItem(@Nonnull ItemStack item, boolean ignoreEnchantments)
      This method damages the specified Item by 1. If ignoredEnchantments is set to false, it will factor in the "Unbreaking" Enchantment.
      Parameters:
      item - The Item to damage
      ignoreEnchantments - Whether the Unbreaking Enchantment should be ignored
    • damageItem

      public static void damageItem(@Nonnull ItemStack item, int damage, boolean ignoreEnchantments)
      This method damages the specified Item by the given amount. If ignoredEnchantments is set to false, it will factor in the "Unbreaking" Enchantment.
      Parameters:
      item - The Item to damage
      damage - The amount of damage to apply
      ignoreEnchantments - Whether the Unbreaking Enchantment should be ignored
    • consumeItem

      public static void consumeItem(@Nonnull ItemStack item, boolean replaceConsumables)
      This Method will consume the Item in the specified slot. See consumeItem(ItemStack, int, boolean) for further details.
      Parameters:
      item - The Item to consume
      replaceConsumables - Whether Consumable Items should be replaced with their "empty" version, see consumeItem(ItemStack, int, boolean)
    • consumeItem

      public static void consumeItem(@Nonnull ItemStack item, int amount, boolean replaceConsumables)
      This Method consumes a specified amount of items from the specified slot. The items will be removed from the slot, if the slot does not hold enough items, it will be replaced with null. Note that this does not check whether there are enough Items present, if you specify a bigger amount than present, it will simply set the Item to null. If replaceConsumables is true, the following things will not be replaced with 'null': Buckets -> new ItemStack(Material.BUCKET) Potions -> new ItemStack(Material.GLASS_BOTTLE)
      Parameters:
      item - The Item to consume
      amount - How many Items should be removed
      replaceConsumables - Whether Items should be replaced with their "empty" version