Class ItemStackUtil

java.lang.Object
net.notcoded.codelib.util.item.ItemStackUtil

public class ItemStackUtil extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    enchant(net.minecraft.world.item.ItemStack itemStack, net.minecraft.world.item.enchantment.Enchantment enchantment, int level)
    Enchants an ItemStack with an enchantment and level.
    static net.minecraft.world.item.ItemStack
    getContainerClickItem(net.minecraft.server.level.ServerPlayer player, net.minecraft.network.protocol.game.ServerboundContainerClickPacket packet)
    Gets the ItemStack in the player's container click
    static ArrayList<net.minecraft.world.item.ItemStack>
    getInvItems(net.minecraft.server.level.ServerPlayer player)
    Gets all the ItemStacks in the player's inventory.
    static boolean
    hasItem(net.minecraft.world.entity.player.Inventory inventory, net.minecraft.world.item.Item item)
    Checks if the inventory has the item.
    static boolean
    hasRoomFor(net.minecraft.world.entity.player.Inventory inventory, net.minecraft.world.item.ItemStack itemStack)
    Checks if the inventory has enough room to store an item.
    static boolean
    isSameItem(net.minecraft.world.item.ItemStack itemStack1, net.minecraft.world.item.ItemStack itemStack2)
    Checks if the inventory has the same item.
    static net.minecraft.world.item.Item
    Gets the item name, e.g.
    static String
    itemStackToString(net.minecraft.world.item.ItemStack itemStack, boolean reversible)
    Gets the ItemStack name, e.g.
    static net.minecraft.world.item.ItemStack
    Turns a string into an ItemStack, e.g.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ItemStackUtil

      public ItemStackUtil()
  • Method Details

    • hasRoomFor

      public static boolean hasRoomFor(net.minecraft.world.entity.player.Inventory inventory, net.minecraft.world.item.ItemStack itemStack)
      Checks if the inventory has enough room to store an item.
      Returns:
      If the inventory has room for the item.
    • hasItem

      public static boolean hasItem(net.minecraft.world.entity.player.Inventory inventory, net.minecraft.world.item.Item item)
      Checks if the inventory has the item.
      Returns:
      If the inventory has the item.
    • isSameItem

      public static boolean isSameItem(net.minecraft.world.item.ItemStack itemStack1, net.minecraft.world.item.ItemStack itemStack2)
      Checks if the inventory has the same item.
      Parameters:
      itemStack2 - The original ItemStack.
      itemStack1 - The ItemStack that's going to get compared.
      Returns:
      If the inventory has the same item.
    • stringToItemStack

      public static net.minecraft.world.item.ItemStack stringToItemStack(String string)
      Turns a string into an ItemStack, e.g. diamond_sword.
      Parameters:
      string - Name, e.g. diamond_sword.
      Returns:
      ItemStack.
    • itemStackToString

      public static String itemStackToString(net.minecraft.world.item.ItemStack itemStack, boolean reversible)
      Gets the ItemStack name, e.g. iron_block.
      Parameters:
      itemStack - ItemStack.
      reversible - If the String can be turned back into an ItemStack with stringToItemStack.
      Returns:
      ItemStack name.
    • getInvItems

      public static ArrayList<net.minecraft.world.item.ItemStack> getInvItems(net.minecraft.server.level.ServerPlayer player)
      Gets all the ItemStacks in the player's inventory.
      Parameters:
      player - The player.
      Returns:
      ItemStacks in ArrayList.
    • itemFromString

      public static net.minecraft.world.item.Item itemFromString(String name)
      Gets the item name, e.g. diamond_sword.
      Parameters:
      name - The name.
      Returns:
      The Item (nullable).
    • enchant

      public static void enchant(net.minecraft.world.item.ItemStack itemStack, net.minecraft.world.item.enchantment.Enchantment enchantment, int level)
      Enchants an ItemStack with an enchantment and level.
    • getContainerClickItem

      public static net.minecraft.world.item.ItemStack getContainerClickItem(net.minecraft.server.level.ServerPlayer player, net.minecraft.network.protocol.game.ServerboundContainerClickPacket packet)
      Gets the ItemStack in the player's container click
      Returns:
      ItemStack.