Class ContainerHelper

java.lang.Object
com.pixelmonmod.pixelmon.api.util.helpers.ContainerHelper

public class ContainerHelper extends Object
Methods for processing and dealing with containers and inventories.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    findSlotMatchingItem(net.minecraft.world.item.ItemStack toMatch, net.minecraft.world.Container inventory)
    Finds the first slot index of a matching ItemStack in a given inventory, only comparing item equality, ignoring all other properties such as quantity, damage, NBT, etc.
    static List<net.minecraft.world.item.ItemStack>
    getAllItems(net.minecraft.world.Container inventory)
    Collects all items in a given inventory into a list.
    static boolean
    hasItem(net.minecraft.world.item.Item item, net.minecraft.world.Container inventory)
    Checks if a given inventory contains a given item at all, anywhere.
    static boolean
    hasItem(net.minecraft.world.item.Item item, net.minecraft.world.entity.player.Player player)
    Checks if a given player has a given item in their inventory.

    Methods inherited from class java.lang.Object

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

    • ContainerHelper

      public ContainerHelper()
  • Method Details

    • findSlotMatchingItem

      public static int findSlotMatchingItem(net.minecraft.world.item.ItemStack toMatch, net.minecraft.world.Container inventory)
      Finds the first slot index of a matching ItemStack in a given inventory, only comparing item equality, ignoring all other properties such as quantity, damage, NBT, etc. If no such match is found, -1 is returned.
      Parameters:
      toMatch - the ItemStack to compare the rest of the inventory to.
      inventory - the inventory to search for a match in.
      Returns:
      the first index of a matching ItemStack, or otherwise -1.
    • hasItem

      public static boolean hasItem(net.minecraft.world.item.Item item, net.minecraft.world.Container inventory)
      Checks if a given inventory contains a given item at all, anywhere.
      Parameters:
      item - the Item to try and find.
      inventory - the inventory to search for a match in.
      Returns:
      if a matching item was found or not.
    • hasItem

      public static boolean hasItem(net.minecraft.world.item.Item item, net.minecraft.world.entity.player.Player player)
      Checks if a given player has a given item in their inventory.
      Parameters:
      item - the Item to try and find.
      player - the player to search for a match on.
      Returns:
      if a matching item was found or not.
    • getAllItems

      public static List<net.minecraft.world.item.ItemStack> getAllItems(net.minecraft.world.Container inventory)
      Collects all items in a given inventory into a list.
      Parameters:
      inventory - The Container to collect from.
      Returns:
      A list containing all the ItemStacks of the given inventory.