Class ContainerHelper
java.lang.Object
com.pixelmonmod.pixelmon.api.util.helpers.ContainerHelper
Methods for processing and dealing with containers and inventories.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
findSlotMatchingItem
(net.minecraft.world.item.ItemStack toMatch, net.minecraft.world.Container inventory) Finds the first slot index of a matchingItemStack
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.
-
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 matchingItemStack
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
- theItemStack
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
- theItem
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
- theItem
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
- TheContainer
to collect from.- Returns:
- A list containing all the
ItemStack
s of the given inventory.
-