Class InventoryUtils

java.lang.Object
com.minecolonies.api.util.InventoryUtils

public class InventoryUtils extends Object
Utility methods for the inventories.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    addItemStackToItemHandler(@NotNull net.minecraftforge.items.IItemHandler itemHandler, @Nullable net.minecraft.world.item.ItemStack itemStack)
    Add stack to item handler.
    static net.minecraft.world.item.ItemStack
    addItemStackToItemHandlerWithResult(@NotNull net.minecraftforge.items.IItemHandler itemHandler, @Nullable net.minecraft.world.item.ItemStack itemStack)
    Add stack to handler with result.
    static boolean
    addItemStackToProvider(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable net.minecraft.world.item.ItemStack itemStack)
    Add stack to provider.
    static net.minecraft.world.item.ItemStack
    addItemStackToProviderWithResult(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable net.minecraft.world.item.ItemStack itemStack)
    Add stack to provider with result.
    static boolean
    areAllItemsInItemHandler(@NotNull List<net.minecraft.world.item.ItemStack> stacks, @NotNull net.minecraftforge.items.IItemHandler handler)
    Checks if all stacks given in the list are in the itemhandler given
    static boolean
    areAllItemsInItemHandlerList(@NotNull List<net.minecraft.world.item.ItemStack> stacks, @NotNull Collection<net.minecraftforge.items.IItemHandler> handlers)
    Checks if all stacks given in the list are in at least one of the given the itemhandlers
    static boolean
    areAllItemsInProvider(@NotNull List<net.minecraft.world.item.ItemStack> stacks, @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider)
    Checks if all stacks given in the list are in the capability provider given
    static boolean
    attemptReduceStackInItemHandler(net.minecraftforge.items.IItemHandler invWrapper, net.minecraft.world.item.ItemStack itemStack, int quantity)
    Search for a certain itemStack in the inventory and decrease it by a certain quantity.
    static boolean
    attemptReduceStackInItemHandler(net.minecraftforge.items.IItemHandler invWrapper, net.minecraft.world.item.ItemStack itemStack, int quantity, boolean ignoreDamage, boolean ignoreNBT)
    Search for a certain itemStack in the inventory and decrease it by a certain quantity.
    static void
    clearItemHandler(@NotNull net.minecraftforge.items.IItemHandler itemHandler)
    Clears an entire IItemHandler.
    static int
    Calculate the number of empty slots in a given building.
    static boolean
    Returns whether two sets of itemstorage has the same content
    static void
    dropItemHandler(net.minecraftforge.items.IItemHandler handler, net.minecraft.world.level.Level world, int x, int y, int z)
    Drop an actual itemHandler in the world.
    static @NotNull List<net.minecraft.world.item.ItemStack>
    filterItemHandler(@NotNull net.minecraftforge.items.IItemHandler itemHandler, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
    Filters a list of items, that match the given predicate, in an IItemHandler.
    static @NotNull List<net.minecraft.world.item.ItemStack>
    filterItemHandler(@NotNull net.minecraftforge.items.IItemHandler itemHandler, @NotNull net.minecraft.world.item.Item targetItem)
    Filters a list of items, matches the stack using compareItems(ItemStack, Item), with targetItem and itemDamage as parameters, in an IItemHandler.
    static @NotNull List<net.minecraft.world.item.ItemStack>
    filterItemHandler(@NotNull net.minecraftforge.items.IItemHandler itemHandler, @NotNull net.minecraft.world.level.block.Block block)
    Filters a list of items, matches the stack using compareItems(ItemStack, Item), in an IItemHandler.
    static @NotNull List<net.minecraft.world.item.ItemStack>
    filterItemHandlerFromProviderForSide(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable net.minecraft.core.Direction facing, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
    Filters a list of items, that match the given predicate, in an IItemHandler.
    static @NotNull List<net.minecraft.world.item.ItemStack>
    filterItemHandlerFromProviderForSide(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable net.minecraft.core.Direction facing, @NotNull net.minecraft.world.item.Item targetItem, int itemDamage)
    Filters a list of items, matches the stack using compareItems(ItemStack, Item), with targetItem and itemDamage as parameters, in an IItemHandler.
    static @NotNull List<net.minecraft.world.item.ItemStack>
    filterItemHandlerFromProviderForSide(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable net.minecraft.core.Direction facing, @NotNull net.minecraft.world.level.block.Block block)
    Filters a list of items, matches the stack using compareItems(ItemStack, Item), in an IItemHandler.
    static @NotNull List<net.minecraft.world.item.ItemStack>
    filterProvider(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
    Filters a list of items, that match the given predicate, in an ICapabilityProvider.
    static @NotNull List<net.minecraft.world.item.ItemStack>
    filterProvider(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable net.minecraft.world.item.Item targetItem)
    Filters a list of items, matches the stack using compareItems(ItemStack, Item), with targetItem and itemDamage as parameters, in an ICapabilityProvider.
    static @NotNull List<net.minecraft.world.item.ItemStack>
    filterProvider(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, net.minecraft.world.level.block.Block block)
    Filters a list of items, matches the stack using compareItems(ItemStack, Item), in an ICapabilityProvider.
    static List<Integer>
    findAllSlotsInItemHandlerWith(@NotNull net.minecraftforge.items.IItemHandler itemHandler, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
    Returns the indexes of all occurrences of an ItemStack that matches the given predicate in the IItemHandler.
    static Map<net.minecraftforge.items.IItemHandler,List<Integer>>
    findAllSlotsInProviderWith(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
    Returns a map with all itemhandlers and slots matching the predicate in the provider.
    static int
    findFirstSlotInItemHandlerNotEmptyWith(@NotNull net.minecraftforge.items.IItemHandler itemHandler, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
    Returns the index of the first occurrence of an ItemStack that matches the given predicate in the IItemHandler.
    static int
    findFirstSlotInItemHandlerWith(@NotNull net.minecraftforge.items.IItemHandler itemHandler, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
    Returns the index of the first occurrence of an ItemStack that matches the given predicate in the IItemHandler.
    static int
    findFirstSlotInItemHandlerWith(@NotNull net.minecraftforge.items.IItemHandler itemHandler, @NotNull net.minecraft.world.item.Item targetItem)
    Returns the index of the first occurrence of the Item with the given ItemDamage in the IItemHandler.
    static int
    findFirstSlotInItemHandlerWith(@NotNull net.minecraftforge.items.IItemHandler itemHandler, @NotNull net.minecraft.world.level.block.Block block)
    Returns the index of the first occurrence of the block in the IItemHandler.
    static int
    findFirstSlotInProviderForSideWith(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable net.minecraft.core.Direction facing, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
    Returns the index of the first occurrence of an ItemStack that matches the given predicate in the ICapabilityProvider for a given Direction.
    static int
    findFirstSlotInProviderForSideWith(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable net.minecraft.core.Direction facing, @NotNull net.minecraft.world.item.Item targetItem)
    Returns the index of the first occurrence of the Item with the given ItemDamage in the ICapabilityProvider for a given Direction.
    static int
    findFirstSlotInProviderForSideWith(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable net.minecraft.core.Direction facing, @NotNull net.minecraft.world.level.block.Block block, int itemDamage)
    Returns the index of the first occurrence of the block in the ICapabilityProvider for a given Direction.
    static int
    findFirstSlotInProviderNotEmptyWith(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
    Returns the index of the first occurrence of an ItemStack that matches the given predicate in the ICapabilityProvider.
    static int
    findFirstSlotInProviderNotEmptyWith(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, List<Predicate<net.minecraft.world.item.ItemStack>> itemStackSelectionPredicate)
    Returns the index of the first occurrence of an ItemStack that matches the given predicate in the ICapabilityProvider.
    static int
    findFirstSlotInProviderWith(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, net.minecraft.world.item.Item targetItem)
    Returns the index of the first occurrence of the Item with the given ItemDamage in the ICapabilityProvider.
    static int
    findFirstSlotInProviderWith(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, net.minecraft.world.level.block.Block block)
    Returns the index of the first occurrence of the block in the ICapabilityProvider.
    static int
    findSlotInItemHandlerNotFullWithItem(net.minecraftforge.items.IItemHandler handler, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount)
    Check if a certain item is in the handler but without the provider being full.
    static boolean
    findSlotInItemHandlerNotFullWithItem(net.minecraftforge.items.IItemHandler handler, net.minecraft.world.item.ItemStack inStack)
    Check if a similar item is in the handler but without the provider being full.
    static int
    findSlotInProviderNotFullWithItem(net.minecraftforge.common.capabilities.ICapabilityProvider provider, net.minecraft.world.item.Item item, int amount)
    Check if a certain item is in the provider but without the provider being full.
    static @Nullable net.minecraft.world.item.ItemStack
    forceItemStackToItemHandler(@NotNull net.minecraftforge.items.IItemHandler itemHandler, @NotNull net.minecraft.world.item.ItemStack itemStack, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackToKeepPredicate)
    Force stack to handler.
    static @Nullable net.minecraft.world.item.ItemStack
    forceItemStackToProvider(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @NotNull net.minecraft.world.item.ItemStack itemStack, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackToKeepPredicate)
    Force stack to provider.
    getAllItemsForProviders(Set<net.minecraftforge.items.IItemHandler> handlerList)
    Sums up all items in the given handlers
    getAllItemsForProviders(net.minecraftforge.common.capabilities.ICapabilityProvider provider, net.minecraftforge.items.IItemHandler... handlers)
    Sums up all items in the given provider/handlers
    getAllItemsForProviders(net.minecraftforge.items.IItemHandler... handlers)
    Sums up all items in the given handlers
    static int
    getAmountOfStacksInItemHandler(@NotNull net.minecraftforge.items.IItemHandler itemHandler)
    Returns the amount of item stacks in an inventory.
    static int
    getAmountOfStacksInProvider(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider)
    Returns the amount of item stacks in an inventory.
    static List<net.minecraft.world.item.ItemStack>
     
    static List<net.minecraft.world.item.ItemStack>
    getContainedFromItemHandler(@NotNull List<net.minecraft.world.item.ItemStack> stacks, @NotNull net.minecraftforge.items.IItemHandler handler)
    Searches a given itemhandler for the stacks given and returns the list that is contained in the itemhandler
    static int
    getCountFromBuilding(@NotNull IBuilding provider, @NotNull ItemStorage stack)
    Count the number of items a building has.
    static int
    getCountFromBuilding(@NotNull IBuilding provider, @NotNull Predicate<net.minecraft.world.item.ItemStack> predicate)
    Count the number of items a building has.
    static int
    getCountFromBuilding(@NotNull IBuilding provider, @NotNull List<ItemStorage> stacks)
    Count the number of items of different types a building has.
    static int
    getCountFromBuildingWithLimit(@NotNull IBuilding provider, @NotNull Predicate<net.minecraft.world.item.ItemStack> predicate, Function<net.minecraft.world.item.ItemStack,Integer> limit)
    Count the number of items a building has.
    static int
    getDurabilityInProvider(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
    Returns the sum of the durability of occurrences in the ICapabilityProvider.
    static net.minecraft.world.item.ItemStack
    getFirstMatch(List<net.minecraft.world.item.ItemStack> stacks, Predicate<net.minecraft.world.item.ItemStack> stackPredicate)
    Gets the first matching itemstack from a list
    static int
    getFirstOpenSlotFromItemHandler(@Nullable net.minecraftforge.items.IItemHandler itemHandler)
    Returns the first open slot in the IItemHandler.
    static int
    getFirstOpenSlotFromProvider(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider)
    Returns the first open slot in the ICapabilityProvider.
    static int
    getFirstOpenSlotFromProviderForSide(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable net.minecraft.core.Direction facing)
    Returns the first open slot in the ICapabilityProvider, for a given Direction.
    static int
    getFirstSlotOfItemHandlerContainingEquipment(@NotNull net.minecraftforge.items.IItemHandler itemHandler, @NotNull EquipmentTypeEntry equipmentType, int minimalLevel, int maximumLevel)
    Returns a slot number if an IItemHandler contains given equipment type.
    static @NotNull List<net.minecraft.world.item.ItemStack>
    getInventoryAsListFromProviderForSide(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable net.minecraft.core.Direction facing)
    Returns an IItemHandler as list of item stacks.
    static int
    getItemCountInItemHandler(@Nullable net.minecraftforge.items.IItemHandler itemHandler, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
    Returns the amount of occurrences in the IItemHandler.
    static int
    getItemCountInItemHandler(@Nullable net.minecraftforge.items.IItemHandler itemHandler, @NotNull net.minecraft.world.item.Item targetItem)
    Returns the amount of occurrences in the IItemHandler.
    static int
    getItemCountInItemHandler(@Nullable net.minecraftforge.items.IItemHandler itemHandler, @NotNull net.minecraft.world.level.block.Block block)
    Returns the amount of occurrences in the IItemHandler.
    static int
    getItemCountInItemHandlers(@Nullable Collection<net.minecraftforge.items.IItemHandler> itemHandlers, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackPredicate)
     
    static int
    getItemCountInProvider(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
    Returns the amount of occurrences in the ICapabilityProvider.
    static int
    getItemCountInProvider(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @NotNull net.minecraft.world.item.Item targetItem)
    Returns the amount of occurrences in the ICapabilityProvider.
    static int
    getItemCountInProvider(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @NotNull net.minecraft.world.level.block.Block block)
    Returns the amount of occurrences in the ICapabilityProvider.
    static int
    getItemCountInProviderForSide(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable net.minecraft.core.Direction facing, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
    Returns the amount of occurrences in the ICapabilityProvider for a given Direction.
    static int
    getItemCountInProviderForSide(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable net.minecraft.core.Direction facing, @NotNull net.minecraft.world.item.Item targetItem)
    Returns the amount of occurrences in the ICapabilityProvider for a given Direction.
    static int
    getItemCountInProviderForSide(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable net.minecraft.core.Direction facing, @NotNull net.minecraft.world.level.block.Block block)
    Returns the amount of occurrences in the ICapabilityProvider for a given Direction.
    static int
    getItemCountInStackLick(@NotNull List<net.minecraft.world.item.ItemStack> stacks, @NotNull Predicate<net.minecraft.world.item.ItemStack> stackPredicate)
    Calculates howmany items match the given predicate that are in the list.
    static net.minecraft.world.item.Item
    getItemFromBlock(net.minecraft.world.level.block.Block block)
    Converts a Block to its Item so it can be compared.
    static @NotNull List<net.minecraft.world.item.ItemStack>
    getItemHandlerAsList(@NotNull net.minecraftforge.items.IItemHandler itemHandler)
    Returns an IItemHandler as list of item stacks.
    static @NotNull Set<net.minecraftforge.items.IItemHandler>
    getItemHandlersFromProvider(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider)
    Method to get all the IItemHandlers from a given Provider.
    static Map<net.minecraft.world.item.ItemStack,Integer>
    getMergedCountedStacksFromList(@NotNull List<net.minecraft.world.item.ItemStack> stacks)
    This method calculates the amount of items in itemstacks are contained within a list.
    static net.minecraft.world.item.ItemStack
    getOrCreateItemAndPutToHotbarAndSelectOrDrop(net.minecraft.world.item.Item item, net.minecraft.world.entity.player.Player player, Supplier<net.minecraft.world.item.ItemStack> itemStackFactory, boolean messageOnDrop)
    If item is already in inventory then it's moved to hotbar and returned.
    static @NotNull List<net.minecraft.world.item.ItemStack>
    getProviderAsList(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider)
    Returns an ICapabilityProvider as list of item stacks.
    static int
    hasBuildingEnoughElseCount(@NotNull ICommonBuilding provider, @NotNull ItemStorage stack, int count)
    Check if a building has more than a count in stack.
    static int
    hasBuildingEnoughElseCount(@NotNull ICommonBuilding provider, @NotNull Predicate<net.minecraft.world.item.ItemStack> stack, int count)
    Check if a building has more than a count in stack.
    static boolean
    hasEnoughInProvider(net.minecraft.world.level.block.entity.BlockEntity entity, net.minecraft.world.item.ItemStack stack, int count)
    Check if there is enough of a given stack in the provider.
    static boolean
    hasItemHandlerEquipmentWithLevel(@NotNull net.minecraftforge.items.IItemHandler itemHandler, EquipmentTypeEntry equipmentType, int requiredLevel, int maximumLevel)
    Verifies if there is one equipment with an acceptable level in a worker's inventory.
    static boolean
    hasItemInItemHandler(@Nullable net.minecraftforge.items.IItemHandler itemHandler, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
    Checks if a player has an item in the IItemHandler.
    static boolean
    hasItemInItemHandler(@Nullable net.minecraftforge.items.IItemHandler itemHandler, @NotNull net.minecraft.world.item.Item item)
    Checks if a player has an item in the IItemHandler.
    static boolean
    hasItemInItemHandler(@Nullable net.minecraftforge.items.IItemHandler itemHandler, @NotNull net.minecraft.world.level.block.Block block)
    Checks if a player has a block in the IItemHandler.
    static boolean
    hasItemInProvider(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider Provider, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
    Checks if a player has an item in the ICapabilityProvider.
    static boolean
    hasItemInProvider(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider Provider, @NotNull net.minecraft.world.item.Item item)
    Checks if a player has an item in the ICapabilityProvider.
    static boolean
    hasItemInProvider(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider Provider, @NotNull net.minecraft.world.level.block.Block block)
    Checks if a player has a block in the ICapabilityProvider.
    static boolean
    hasItemInProviderForSide(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable net.minecraft.core.Direction facing, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
    Checks if a player has an item in the ICapabilityProvider, for a given Direction.
    static boolean
    hasItemInProviderForSide(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable net.minecraft.core.Direction facing, @NotNull net.minecraft.world.item.Item item)
    Checks if a player has an item in the ICapabilityProvider, for a given Direction.
    static boolean
    hasItemInProviderForSide(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable net.minecraft.core.Direction facing, @NotNull net.minecraft.world.level.block.Block block)
    Checks if a player has a block in the ICapabilityProvider, for a given Direction.
    static boolean
    hasProviderIItemHandler(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider)
    Method used to check if a ICapabilityProvider has any IItemHandler
    static boolean
    Calculate the number of empty slots in a given building.
    static boolean
    isEquipmentInItemHandler(@NotNull net.minecraftforge.items.IItemHandler itemHandler, @NotNull EquipmentTypeEntry equipmentType, int minimalLevel, int maximumLevel)
    Checks if the IItemHandler contains the following equipmentType with the given minimal Level.
    static boolean
    isEquipmentInProvider(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @NotNull EquipmentTypeEntry equipmentType, int minimalLevel, int maximumLevel)
    Checks if the ICapabilityProvider contains the following equipmentType with the given minimal Level.
    static boolean
    isEquipmentInProviderForSide(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable net.minecraft.core.Direction facing, @NotNull EquipmentTypeEntry equipmentType, int minimalLevel, int maximumLevel)
    Checks if the ICapabilityProvider contains the following EquipmentType with the given minimal Level, for a given Direction.
    static boolean
    isItemHandlerFull(@Nullable net.minecraftforge.items.IItemHandler itemHandler)
    Returns if the IItemHandler is full.
    static boolean
    isProviderFull(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider)
    Returns if the ICapabilityProvider is full.
    static boolean
    isProviderFull(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable net.minecraft.core.Direction facing)
    Returns if the ICapabilityProvider is full, for a given Direction.
    static boolean
    isProviderSided(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider)
    Method used to check if this provider is sided.
    static void
    mergeItemStackIntoNextBestSlotInItemHandlers(@NotNull net.minecraftforge.items.IItemHandler sourceHandler, int sourceIndex, @NotNull net.minecraftforge.items.IItemHandler targetHandler)
    Method to merge the ItemStacks from the given source IItemHandler to the given target IItemHandler.
    static net.minecraft.world.item.ItemStack
    mergeItemStackIntoNextBestSlotInItemHandlers(net.minecraft.world.item.ItemStack stack, @NotNull net.minecraftforge.items.IItemHandler targetHandler)
    Method to merge the ItemStacks from the given source IItemHandler to the given target IItemHandler.
    static boolean
    moveItemStacksWithPossibleSwap(@NotNull net.minecraftforge.items.IItemHandler targetInventory, @NotNull Collection<net.minecraftforge.items.IItemHandler> sourceInventories, @NotNull List<net.minecraft.world.item.ItemStack> toSwap, @NotNull Predicate<net.minecraft.world.item.ItemStack> toKeepInTarget)
    Attempts a swap with the given itemstacks, from the source to the target inventory.
    static long
    openSlotCount(@Nullable net.minecraftforge.items.IItemHandler itemHandler)
    Count all open slots in inventory.
    static List<net.minecraft.world.item.ItemStack>
    processItemStackListAndMerge(@NotNull List<net.minecraft.world.item.ItemStack> stacks)
    Unifies a list of stacks so that they are all packed to together to the max stack size.
    static boolean
    putItemToHotbarAndSelectOrDrop(net.minecraft.world.item.ItemStack itemStack, net.minecraft.world.entity.player.Player player)
    Tries to put given itemstack in hotbar and select it, fails when player inventory is full, successes otherwise.
    static boolean
    putItemToHotbarAndSelectOrDropMessage(net.minecraft.world.item.ItemStack itemStack, net.minecraft.world.entity.player.Player player)
    Tries to put given itemstack in hotbar, fails when player inventory is full, successes otherwise.
    static void
    reduceBucketAwareStackInItemHandler(net.minecraftforge.items.IItemHandler invWrapper, net.minecraft.world.item.ItemStack itemStack)
    Search for a certain itemStack in the inventory and decrease it by 1.
    static void
    reduceBucketAwareStackInItemHandler(net.minecraftforge.items.IItemHandler invWrapper, net.minecraft.world.item.ItemStack itemStack, int quantity)
    Search for a certain itemStack in the inventory and decrease it by a certain quantity.
    reduceBuildingThenPlayerInventory(IBuilding building, net.minecraft.world.entity.player.Player player, ItemStorage itemsToTake, Predicate<net.minecraft.world.item.ItemStack> buildingPredicate, Predicate<net.minecraft.world.item.ItemStack> playerPredicate)
    This method will first try to remove items from the building inventory, then from the player inventory.
    static void
    reduceStackInItemHandler(net.minecraftforge.items.IItemHandler invWrapper, net.minecraft.world.item.ItemStack itemStack)
    Search for a certain itemStack in the inventory and decrease it by 1.
    static void
    reduceStackInItemHandler(net.minecraftforge.items.IItemHandler invWrapper, net.minecraft.world.item.ItemStack itemStack, int quantity)
    Search for a certain itemStack in the inventory and decrease it by a certain quantity.
    static void
    removeStackFromItemHandler(net.minecraftforge.items.IItemHandler handler, net.minecraft.world.item.ItemStack input, int count)
    Force remove a stack with a certain amount from a given Itemhandler
    static boolean
    removeStacksFromItemHandler(net.minecraftforge.items.IItemHandler handler, List<net.minecraft.world.item.ItemStack> input)
    Remove a list of stacks from a given Itemhandler
    static boolean
    removeStacksFromProvider(net.minecraftforge.common.capabilities.ICapabilityProvider provider, List<net.minecraft.world.item.ItemStack> input)
    Remove a list of stacks from a given provider
    static boolean
    shrinkItemCountInItemHandler(net.minecraftforge.items.IItemHandler itemHandler, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
    Shrinks a specific stack in an item handler.
    static void
    spawnItemStack(net.minecraft.world.level.Level worldIn, double x, double y, double z, net.minecraft.world.item.ItemStack stack)
    Spawn an itemStack in the world.
    static List<net.minecraft.world.item.ItemStack>
    splitMergedCountedStacksIntoMaxContentStacks(@NotNull Map<net.minecraft.world.item.ItemStack,Integer> mergedCountedStacks)
    This method splits a map with an entry for each unique unified itemstack and its count into a list of itemstacks that represent the maps, taken the max stack size into account.
    static boolean
    swapItemStacksInItemHandlers(@NotNull net.minecraftforge.items.IItemHandler sourceHandler, int sourceIndex, @NotNull net.minecraftforge.items.IItemHandler targetHandler, int targetIndex)
    Method to swap the ItemStacks from the given source IItemHandler to the given target IItemHandler.
    static boolean
    transferAllItemHandler(net.minecraftforge.items.IItemHandler origin, net.minecraftforge.items.IItemHandler target)
    Attempt to transfer as much item as possible from origin to target inventory
    static it.unimi.dsi.fastutil.objects.Object2IntMap<net.minecraft.world.item.ItemStack>
    transferFoodUpToSaturation(net.minecraftforge.common.capabilities.ICapabilityProvider source, net.minecraftforge.items.IItemHandler target, int requiredSaturation, Predicate<net.minecraft.world.item.ItemStack> foodPredicate)
    Transfers food items from the source with the required saturation value, or as much as possible.
    static boolean
    transferItemStackIntoNextBestSlotFromProvider(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider sourceProvider, int sourceIndex, @NotNull net.minecraftforge.items.IItemHandler targetHandler)
    Method to swap the ItemStacks from the given source ICapabilityProvider to the given target IItemHandler.
    static boolean
    transferItemStackIntoNextBestSlotInItemHandler(@NotNull IBuilding building, ItemStorage storage, int qty, @NotNull net.minecraftforge.items.IItemHandler targetHandler)
    Method to transfer an ItemStacks from the given source IBuilding to the given target IItemHandler.
    static boolean
    transferItemStackIntoNextBestSlotInItemHandler(@NotNull IBuilding building, ItemStorage storage, @NotNull net.minecraftforge.items.IItemHandler targetHandler)
    Method to transfer an ItemStacks from the given source IBuilding to the given target IItemHandler.
    static boolean
    transferItemStackIntoNextBestSlotInItemHandler(@NotNull net.minecraftforge.items.IItemHandler sourceHandler, int sourceIndex, @NotNull net.minecraftforge.items.IItemHandler targetHandler)
    Method to swap the ItemStacks from the given source IItemHandler to the given target IItemHandler.
    static boolean
    transferItemStackIntoNextBestSlotInItemHandler(@NotNull net.minecraftforge.items.IItemHandler sourceHandler, Predicate<net.minecraft.world.item.ItemStack> predicate, @NotNull net.minecraftforge.items.IItemHandler targetHandler)
    Method to transfer an ItemStacks from the given source IItemHandler to the given target IItemHandler.
    static boolean
    transferItemStackIntoNextBestSlotInItemHandler(net.minecraft.world.item.ItemStack stack, @NotNull net.minecraftforge.items.IItemHandler targetHandler)
    Method to put a given Itemstack in a given target IItemHandler.
    static net.minecraft.world.item.ItemStack
    transferItemStackIntoNextBestSlotInItemHandlerWithResult(net.minecraft.world.item.ItemStack stack, @NotNull net.minecraftforge.items.IItemHandler targetHandler)
    Method to put a given Itemstack in a given target IItemHandler.
    static boolean
    transferItemStackIntoNextFreeSlotFromItemHandler(@NotNull net.minecraftforge.items.IItemHandler handler, @NotNull Predicate<net.minecraft.world.item.ItemStack> stackPredicate, int count, @NotNull net.minecraftforge.items.IItemHandler targetHandler)
    Method to swap the ItemStacks from the given source IItemHandler to the given target IItemHandler.
    static boolean
    transferItemStackIntoNextFreeSlotFromProvider(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider sourceProvider, int sourceIndex, @NotNull net.minecraftforge.items.IItemHandler targetHandler)
    Method to swap the ItemStacks from the given source ICapabilityProvider to the given target IItemHandler.
    static boolean
    transferItemStackIntoNextFreeSlotInItemHandler(@NotNull net.minecraftforge.items.IItemHandler sourceHandler, int sourceIndex, @NotNull net.minecraftforge.items.IItemHandler targetHandler)
    Method to swap the ItemStacks from the given source IItemHandler to the given target IItemHandler.
    static boolean
    transferItemStackIntoNextFreeSlotInProvider(@NotNull net.minecraftforge.items.IItemHandler sourceHandler, int sourceIndex, @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider targetProvider)
    Method to swap the ItemStacks from the given source IItemHandler to the given target ICapabilityProvider.
    static int
    transferXInItemHandlerIntoSlotInItemHandler(net.minecraftforge.items.IItemHandler sourceHandler, Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, net.minecraftforge.items.IItemHandler targetHandler, int slot)
    Takes an item matching a predicate and moves it form one handler across multiple slots to the other to a specific slot.
    static int
    transferXOfFirstSlotInItemHandlerWithIntoInItemHandler(net.minecraftforge.items.IItemHandler sourceHandler, Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, net.minecraftforge.items.IItemHandler targetHandler, int slot)
    Takes an item matching a predicate and moves it form one handler to the other to a specific slot.
    static boolean
    transferXOfFirstSlotInItemHandlerWithIntoNextFreeSlotInItemHandler(@NotNull net.minecraftforge.items.IItemHandler sourceHandler, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull net.minecraftforge.items.IItemHandler targetHandler)
     
    static int
    transferXOfFirstSlotInItemHandlerWithIntoNextFreeSlotInItemHandlerWithResult(@NotNull net.minecraftforge.items.IItemHandler sourceHandler, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull net.minecraftforge.items.IItemHandler targetHandler)
     
    static boolean
    transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandler(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider sourceProvider, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull net.minecraftforge.items.IItemHandler targetHandler)
     
    static int
    transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandlerWithResult(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider sourceProvider, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull net.minecraftforge.items.IItemHandler targetHandler)
    Transfer items over and return the leftover that couldn't be transfered (0 if full amount was transfered).
    static boolean
    transferXOfFirstSlotInProviderWithIntoNextFreeSlotInProvider(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider sourceProvider, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider targetProvider)
     
    static int
    transferXOfFirstSlotInProviderWithIntoNextFreeSlotInProviderWithResult(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider sourceProvider, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider targetProvider)
     
    static boolean
    transferXOfItemStackIntoNextFreeSlotFromProvider(@NotNull net.minecraftforge.common.capabilities.ICapabilityProvider sourceProvider, int sourceIndex, int count, @NotNull net.minecraftforge.items.IItemHandler targetHandler)
    Method to swap the ItemStacks from the given source ICapabilityProvider to the given target IItemHandler.
    static boolean
    transferXOfItemStackIntoNextFreeSlotInItemHandler(@NotNull net.minecraftforge.items.IItemHandler sourceHandler, int sourceIndex, int count, @NotNull net.minecraftforge.items.IItemHandler targetHandler)
    Method to swap the ItemStacks from the given source IItemHandler to the given target IItemHandler.
    static boolean
    tryRemoveStackFromItemHandler(net.minecraftforge.items.IItemHandler handler, net.minecraft.world.item.ItemStack input)
    Tries to remove a stack with its size from a given Itemhandler.

    Methods inherited from class java.lang.Object

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

    • filterItemHandler

      @NotNull public static @NotNull List<net.minecraft.world.item.ItemStack> filterItemHandler(@NotNull @NotNull net.minecraftforge.items.IItemHandler itemHandler, @NotNull @NotNull net.minecraft.world.level.block.Block block)
      Filters a list of items, matches the stack using compareItems(ItemStack, Item), in an IItemHandler. Uses the MetaData and getItemFromBlock(Block) as parameters for the Predicate.
      Parameters:
      itemHandler - Inventory to filter in
      block - Block to filter
      Returns:
      List of item stacks
    • filterItemHandler

      @NotNull public static @NotNull List<net.minecraft.world.item.ItemStack> filterItemHandler(@NotNull @NotNull net.minecraftforge.items.IItemHandler itemHandler, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
      Filters a list of items, that match the given predicate, in an IItemHandler.
      Parameters:
      itemHandler - The IItemHandler to get items from.
      itemStackSelectionPredicate - The predicate to match the stack to.
      Returns:
      List of item stacks that match the given predicate.
    • getItemFromBlock

      public static net.minecraft.world.item.Item getItemFromBlock(net.minecraft.world.level.block.Block block)
      Converts a Block to its Item so it can be compared.
      Parameters:
      block - the block to convert
      Returns:
      an item from the registry
    • filterItemHandler

      @NotNull public static @NotNull List<net.minecraft.world.item.ItemStack> filterItemHandler(@NotNull @NotNull net.minecraftforge.items.IItemHandler itemHandler, @NotNull @NotNull net.minecraft.world.item.Item targetItem)
      Filters a list of items, matches the stack using compareItems(ItemStack, Item), with targetItem and itemDamage as parameters, in an IItemHandler.
      Parameters:
      itemHandler - Inventory to get items from
      targetItem - Item to look for
      Returns:
      List of item stacks with the given item in inventory
    • findFirstSlotInItemHandlerWith

      public static int findFirstSlotInItemHandlerWith(@NotNull @NotNull net.minecraftforge.items.IItemHandler itemHandler, @NotNull @NotNull net.minecraft.world.level.block.Block block)
      Returns the index of the first occurrence of the block in the IItemHandler.
      Parameters:
      itemHandler - IItemHandler to check.
      block - Block to find.
      Returns:
      Index of the first occurrence.
    • findFirstSlotInItemHandlerWith

      public static int findFirstSlotInItemHandlerWith(@NotNull @NotNull net.minecraftforge.items.IItemHandler itemHandler, @NotNull @NotNull net.minecraft.world.item.Item targetItem)
      Returns the index of the first occurrence of the Item with the given ItemDamage in the IItemHandler.
      Parameters:
      itemHandler - IItemHandler to check
      targetItem - Item to find.
      Returns:
      Index of the first occurrence
    • findFirstSlotInItemHandlerWith

      public static int findFirstSlotInItemHandlerWith(@NotNull @NotNull net.minecraftforge.items.IItemHandler itemHandler, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
      Returns the index of the first occurrence of an ItemStack that matches the given predicate in the IItemHandler.
      Parameters:
      itemHandler - ItemHandler to check
      itemStackSelectionPredicate - The predicate to match.
      Returns:
      Index of the first occurrence
    • shrinkItemCountInItemHandler

      public static boolean shrinkItemCountInItemHandler(net.minecraftforge.items.IItemHandler itemHandler, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
      Shrinks a specific stack in an item handler.
      Parameters:
      itemHandler - the handler..
      itemStackSelectionPredicate - the predicate..
      Returns:
      true if successful.
    • findAllSlotsInItemHandlerWith

      public static List<Integer> findAllSlotsInItemHandlerWith(@NotNull @NotNull net.minecraftforge.items.IItemHandler itemHandler, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
      Returns the indexes of all occurrences of an ItemStack that matches the given predicate in the IItemHandler.
      Parameters:
      itemHandler - ItemHandler to check
      itemStackSelectionPredicate - The predicate to match.
      Returns:
      list of Indexes of the occurrences
    • getItemCountInItemHandler

      public static int getItemCountInItemHandler(@Nullable @Nullable net.minecraftforge.items.IItemHandler itemHandler, @NotNull @NotNull net.minecraft.world.level.block.Block block)
      Returns the amount of occurrences in the IItemHandler.
      Parameters:
      itemHandler - IItemHandler to scan.
      block - The block to count
      Returns:
      Amount of occurrences of stacks that match the given block and ItemDamage
    • getItemCountInItemHandler

      public static int getItemCountInItemHandler(@Nullable @Nullable net.minecraftforge.items.IItemHandler itemHandler, @NotNull @NotNull net.minecraft.world.item.Item targetItem)
      Returns the amount of occurrences in the IItemHandler.
      Parameters:
      itemHandler - IItemHandler to scan.
      targetItem - Item to count
      Returns:
      Amount of occurrences of stacks that match the given item and ItemDamage
    • getItemCountInItemHandler

      public static int getItemCountInItemHandler(@Nullable @Nullable net.minecraftforge.items.IItemHandler itemHandler, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
      Returns the amount of occurrences in the IItemHandler.
      Parameters:
      itemHandler - IItemHandler to scan.
      itemStackSelectionPredicate - The predicate used to select the stacks to count.
      Returns:
      Amount of occurrences of stacks that match the given predicate.
    • getItemCountInItemHandlers

      public static int getItemCountInItemHandlers(@Nullable @Nullable Collection<net.minecraftforge.items.IItemHandler> itemHandlers, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackPredicate)
    • hasItemInItemHandler

      public static boolean hasItemInItemHandler(@Nullable @Nullable net.minecraftforge.items.IItemHandler itemHandler, @NotNull @NotNull net.minecraft.world.level.block.Block block)
      Checks if a player has a block in the IItemHandler. Checked by getItemCountInItemHandler(IItemHandler, Block) > 0;
      Parameters:
      itemHandler - IItemHandler to scan
      block - Block to count
      Returns:
      True when in IItemHandler, otherwise false
    • hasItemInItemHandler

      public static boolean hasItemInItemHandler(@Nullable @Nullable net.minecraftforge.items.IItemHandler itemHandler, @NotNull @NotNull net.minecraft.world.item.Item item)
      Checks if a player has an item in the IItemHandler. Checked by getItemCountInItemHandler(IItemHandler, Item) > 0;
      Parameters:
      itemHandler - IItemHandler to scan
      item - Item to count
      Returns:
      True when in IItemHandler, otherwise false
    • hasItemInItemHandler

      public static boolean hasItemInItemHandler(@Nullable @Nullable net.minecraftforge.items.IItemHandler itemHandler, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
      Checks if a player has an item in the IItemHandler. Checked by getItemCountInItemHandler(IItemHandler, Predicate) > 0;
      Parameters:
      itemHandler - IItemHandler to scan
      itemStackSelectionPredicate - The predicate to match the ItemStack to.
      Returns:
      True when in IItemHandler, otherwise false
    • isItemHandlerFull

      public static boolean isItemHandlerFull(@Nullable @Nullable net.minecraftforge.items.IItemHandler itemHandler)
      Returns if the IItemHandler is full.
      Parameters:
      itemHandler - The IItemHandler.
      Returns:
      True if the IItemHandler is full, false when not.
    • getFirstOpenSlotFromItemHandler

      public static int getFirstOpenSlotFromItemHandler(@Nullable @Nullable net.minecraftforge.items.IItemHandler itemHandler)
      Returns the first open slot in the IItemHandler.
      Parameters:
      itemHandler - The IItemHandler to check.
      Returns:
      slot index or -1 if none found.
    • openSlotCount

      public static long openSlotCount(@Nullable @Nullable net.minecraftforge.items.IItemHandler itemHandler)
      Count all open slots in inventory.
      Parameters:
      itemHandler - the inventory.
      Returns:
      the amount of open slots.
    • forceItemStackToItemHandler

      @Nullable public static @Nullable net.minecraft.world.item.ItemStack forceItemStackToItemHandler(@NotNull @NotNull net.minecraftforge.items.IItemHandler itemHandler, @NotNull @NotNull net.minecraft.world.item.ItemStack itemStack, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackToKeepPredicate)
      Force stack to handler.
      Parameters:
      itemHandler - IItemHandler to add itemstack to.
      itemStack - ItemStack to add.
      itemStackToKeepPredicate - The Predicate that determines which ItemStacks to keep in the inventory. Return false to replace.
      Returns:
      itemStack which has been replaced, null if none has been replaced.
    • getAmountOfStacksInItemHandler

      public static int getAmountOfStacksInItemHandler(@NotNull @NotNull net.minecraftforge.items.IItemHandler itemHandler)
      Returns the amount of item stacks in an inventory. This equals getItemHandlerAsList(IItemHandler).length();.
      Parameters:
      itemHandler - IItemHandler to count item stacks of.
      Returns:
      Amount of item stacks in the IItemHandler.
    • getItemHandlerAsList

      @NotNull public static @NotNull List<net.minecraft.world.item.ItemStack> getItemHandlerAsList(@NotNull @NotNull net.minecraftforge.items.IItemHandler itemHandler)
      Returns an IItemHandler as list of item stacks.
      Parameters:
      itemHandler - Inventory to convert.
      Returns:
      List of item stacks.
    • filterProvider

      @NotNull public static @NotNull List<net.minecraft.world.item.ItemStack> filterProvider(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, net.minecraft.world.level.block.Block block)
      Filters a list of items, matches the stack using compareItems(ItemStack, Item), in an ICapabilityProvider. Uses the MetaData and getItemFromBlock(Block) as parameters for the Predicate.
      Parameters:
      provider - Provider to filter in
      block - Block to filter
      Returns:
      List of item stacks
    • filterProvider

      @NotNull public static @NotNull List<net.minecraft.world.item.ItemStack> filterProvider(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
      Filters a list of items, that match the given predicate, in an ICapabilityProvider.
      Parameters:
      provider - The ICapabilityProvider to get items from.
      itemStackSelectionPredicate - The predicate to match the stack to.
      Returns:
      List of item stacks that match the given predicate.
    • getItemHandlersFromProvider

      @NotNull public static @NotNull Set<net.minecraftforge.items.IItemHandler> getItemHandlersFromProvider(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider)
      Method to get all the IItemHandlers from a given Provider.
      Parameters:
      provider - The provider to get the IItemHandlers from.
      Returns:
      A list with all the unique IItemHandlers a provider has.
    • filterProvider

      @NotNull public static @NotNull List<net.minecraft.world.item.ItemStack> filterProvider(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable @Nullable net.minecraft.world.item.Item targetItem)
      Filters a list of items, matches the stack using compareItems(ItemStack, Item), with targetItem and itemDamage as parameters, in an ICapabilityProvider.
      Parameters:
      provider - Provider to get items from
      targetItem - Item to look for
      Returns:
      List of item stacks with the given item in inventory
    • findFirstSlotInProviderWith

      public static int findFirstSlotInProviderWith(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, net.minecraft.world.level.block.Block block)
      Returns the index of the first occurrence of the block in the ICapabilityProvider.
      Parameters:
      provider - ICapabilityProvider to check.
      block - Block to find.
      Returns:
      Index of the first occurrence.
    • findFirstSlotInProviderWith

      public static int findFirstSlotInProviderWith(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, net.minecraft.world.item.Item targetItem)
      Returns the index of the first occurrence of the Item with the given ItemDamage in the ICapabilityProvider.
      Parameters:
      provider - ICapabilityProvider to check
      targetItem - Item to find.
      Returns:
      Index of the first occurrence
    • findAllSlotsInProviderWith

      public static Map<net.minecraftforge.items.IItemHandler,List<Integer>> findAllSlotsInProviderWith(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
      Returns a map with all itemhandlers and slots matching the predicate in the provider. the given predicate in the ICapabilityProvider.
      Parameters:
      provider - Provider to check
      itemStackSelectionPredicate - The predicate to match.
      Returns:
      Index of the first occurrence
    • findFirstSlotInProviderNotEmptyWith

      public static int findFirstSlotInProviderNotEmptyWith(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
      Returns the index of the first occurrence of an ItemStack that matches the given predicate in the ICapabilityProvider.
      Parameters:
      provider - Provider to check
      itemStackSelectionPredicate - The predicate to match.
      Returns:
      Index of the first occurrence
    • findFirstSlotInProviderNotEmptyWith

      public static int findFirstSlotInProviderNotEmptyWith(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, List<Predicate<net.minecraft.world.item.ItemStack>> itemStackSelectionPredicate)
      Returns the index of the first occurrence of an ItemStack that matches the given predicate in the ICapabilityProvider.
      Parameters:
      provider - Provider to check
      itemStackSelectionPredicate - The list of predicates to match.
      Returns:
      Index of the first occurrence
    • findFirstSlotInItemHandlerNotEmptyWith

      public static int findFirstSlotInItemHandlerNotEmptyWith(@NotNull @NotNull net.minecraftforge.items.IItemHandler itemHandler, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
      Returns the index of the first occurrence of an ItemStack that matches the given predicate in the IItemHandler. Also applies the not empty check.
      Parameters:
      itemHandler - ItemHandler to check
      itemStackSelectionPredicate - The predicate to match.
      Returns:
      Index of the first occurrence
    • getItemCountInProvider

      public static int getItemCountInProvider(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @NotNull @NotNull net.minecraft.world.level.block.Block block)
      Returns the amount of occurrences in the ICapabilityProvider.
      Parameters:
      provider - ICapabilityProvider to scan.
      block - The block to count
      Returns:
      Amount of occurrences of stacks that match the given block and ItemDamage
    • getItemCountInProvider

      public static int getItemCountInProvider(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @NotNull @NotNull net.minecraft.world.item.Item targetItem)
      Returns the amount of occurrences in the ICapabilityProvider.
      Parameters:
      provider - ICapabilityProvider to scan.
      targetItem - Item to count.
      Returns:
      Amount of occurrences of stacks that match the given item and ItemDamage
    • getItemCountInProvider

      public static int getItemCountInProvider(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
      Returns the amount of occurrences in the ICapabilityProvider.
      Parameters:
      provider - ICapabilityProvider to scan.
      itemStackSelectionPredicate - The predicate used to select the stacks to count.
      Returns:
      Amount of occurrences of stacks that match the given predicate.
    • getDurabilityInProvider

      public static int getDurabilityInProvider(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
      Returns the sum of the durability of occurrences in the ICapabilityProvider.
      Parameters:
      provider - ICapabilityProvider to scan.
      itemStackSelectionPredicate - The predicate used to select the stacks to count.
      Returns:
      Amount of occurrences of stacks that match the given predicate.
    • hasBuildingEnoughElseCount

      public static int hasBuildingEnoughElseCount(@NotNull @NotNull ICommonBuilding provider, @NotNull @NotNull ItemStorage stack, int count)
      Check if a building has more than a count in stack. Return the count it has if it has less.
      Parameters:
      provider - building to check in.
      stack - the stack to check.
      Returns:
      Amount of occurrences of stacks that match the given predicate.
    • hasBuildingEnoughElseCount

      public static int hasBuildingEnoughElseCount(@NotNull @NotNull ICommonBuilding provider, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> stack, int count)
      Check if a building has more than a count in stack. Return the count it has if it has less.
      Parameters:
      provider - building to check in.
      stack - the stack to check.
      Returns:
      Amount of occurrences of stacks that match the given predicate.
    • getCountFromBuilding

      public static int getCountFromBuilding(@NotNull @NotNull IBuilding provider, @NotNull @NotNull List<ItemStorage> stacks)
      Count the number of items of different types a building has.
      Parameters:
      provider - the building to check.
      stacks - the stacks to check for.
      Returns:
      Amount of occurrences of stacks that match the given stacks.
    • getCountFromBuilding

      public static int getCountFromBuilding(@NotNull @NotNull IBuilding provider, @NotNull @NotNull ItemStorage stack)
      Count the number of items a building has.
      Parameters:
      provider - building to check in.
      stack - the stack to check.
      Returns:
      Amount of occurrences of stacks that match the given stack.
    • countEmptySlotsInBuilding

      public static int countEmptySlotsInBuilding(IBuilding ownBuilding)
      Calculate the number of empty slots in a given building.
      Parameters:
      ownBuilding - the building to check.
      Returns:
      the number of empty slots.
    • isBuildingFull

      public static boolean isBuildingFull(IBuilding ownBuilding)
      Calculate the number of empty slots in a given building.
      Parameters:
      ownBuilding - the building to check.
      Returns:
      the number of empty slots.
    • getCountFromBuilding

      public static int getCountFromBuilding(@NotNull @NotNull IBuilding provider, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> predicate)
      Count the number of items a building has.
      Parameters:
      provider - building to check in.
      predicate - the predicate to match.
      Returns:
      Amount of occurrences of stacks that match the given stack.
    • getCountFromBuildingWithLimit

      public static int getCountFromBuildingWithLimit(@NotNull @NotNull IBuilding provider, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> predicate, Function<net.minecraft.world.item.ItemStack,Integer> limit)
      Count the number of items a building has. Only count up to "limit" of a particular item.
      Parameters:
      provider - building to check in.
      predicate - the predicate to match.
      Returns:
      Amount of occurrences of stacks that match the given stack.
    • hasItemInProvider

      public static boolean hasItemInProvider(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider Provider, @NotNull @NotNull net.minecraft.world.level.block.Block block)
      Checks if a player has a block in the ICapabilityProvider. Checked by getItemCountInProvider(ICapabilityProvider, Block) > 0;
      Parameters:
      Provider - ICapabilityProvider to scan
      block - Block to count
      Returns:
      True when in ICapabilityProvider, otherwise false
    • hasItemInProvider

      public static boolean hasItemInProvider(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider Provider, @NotNull @NotNull net.minecraft.world.item.Item item)
      Checks if a player has an item in the ICapabilityProvider. Checked by getItemCountInProvider(ICapabilityProvider, Item) > 0;
      Parameters:
      Provider - ICapabilityProvider to scan
      item - Item to count
      Returns:
      True when in ICapabilityProvider, otherwise false
    • hasItemInProvider

      public static boolean hasItemInProvider(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider Provider, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
      Checks if a player has an item in the ICapabilityProvider. Checked by getItemCountInProvider(ICapabilityProvider, Predicate) > 0;
      Parameters:
      Provider - ICapabilityProvider to scan
      itemStackSelectionPredicate - The predicate to match the ItemStack to.
      Returns:
      True when in ICapabilityProvider, otherwise false
    • isProviderFull

      public static boolean isProviderFull(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider)
      Returns if the ICapabilityProvider is full.
      Parameters:
      provider - The ICapabilityProvider.
      Returns:
      True if the ICapabilityProvider is full, false when not.
    • getFirstOpenSlotFromProvider

      public static int getFirstOpenSlotFromProvider(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider)
      Returns the first open slot in the ICapabilityProvider.
      Parameters:
      provider - The ICapabilityProvider to check.
      Returns:
      slot index or -1 if none found.
    • isEquipmentInProvider

      public static boolean isEquipmentInProvider(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @NotNull @NotNull EquipmentTypeEntry equipmentType, int minimalLevel, int maximumLevel)
      Checks if the ICapabilityProvider contains the following equipmentType with the given minimal Level.
      Parameters:
      provider - The ICapabilityProvider to scan.
      equipmentType - The EquipmentType of the equipment to find.
      minimalLevel - The minimal level to find.
      maximumLevel - The maximum level to find.
      Returns:
      True if equipment with the given equipmentType was found in the given ICapabilityProvider, false when not.
    • addItemStackToProvider

      public static boolean addItemStackToProvider(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable @Nullable net.minecraft.world.item.ItemStack itemStack)
      Add stack to provider.
      Parameters:
      provider - ICapabilityProvider to add itemstack to.
      itemStack - ItemStack to add.
      Returns:
      True if successful, otherwise false.
    • addItemStackToItemHandler

      public static boolean addItemStackToItemHandler(@NotNull @NotNull net.minecraftforge.items.IItemHandler itemHandler, @Nullable @Nullable net.minecraft.world.item.ItemStack itemStack)
      Add stack to item handler.
      Parameters:
      itemHandler - IItemHandler to add itemstack to.
      itemStack - ItemStack to add.
      Returns:
      True if successful, otherwise false.
    • addItemStackToProviderWithResult

      public static net.minecraft.world.item.ItemStack addItemStackToProviderWithResult(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable @Nullable net.minecraft.world.item.ItemStack itemStack)
      Add stack to provider with result.
      Parameters:
      provider - ICapabilityProvider to add itemstack to.
      itemStack - ItemStack to add.
      Returns:
      Empty when fully transfered without swapping, otherwise return the remain of a partial transfer
    • addItemStackToItemHandlerWithResult

      public static net.minecraft.world.item.ItemStack addItemStackToItemHandlerWithResult(@NotNull @NotNull net.minecraftforge.items.IItemHandler itemHandler, @Nullable @Nullable net.minecraft.world.item.ItemStack itemStack)
      Add stack to handler with result.
      Parameters:
      itemHandler - IItemHandler to add itemstack to.
      itemStack - ItemStack to add.
      Returns:
      Empty when fully transfered, otherwise return the remain of a partial transfer of the itemStack.
    • forceItemStackToProvider

      @Nullable public static @Nullable net.minecraft.world.item.ItemStack forceItemStackToProvider(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @NotNull @NotNull net.minecraft.world.item.ItemStack itemStack, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackToKeepPredicate)
      Force stack to provider.
      Parameters:
      provider - ICapabilityProvider to add itemstack to.
      itemStack - ItemStack to add.
      itemStackToKeepPredicate - The Predicate that determines which ItemStacks to keep in the inventory. Return false to replace.
      Returns:
      itemStack which has been replaced.
    • getAmountOfStacksInProvider

      public static int getAmountOfStacksInProvider(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider)
      Returns the amount of item stacks in an inventory. This equals getProviderAsList(ICapabilityProvider).length();.
      Parameters:
      provider - ICapabilityProvider to count item stacks of.
      Returns:
      Amount of item stacks in the ICapabilityProvider.
    • getProviderAsList

      @NotNull public static @NotNull List<net.minecraft.world.item.ItemStack> getProviderAsList(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider)
      Returns an ICapabilityProvider as list of item stacks.
      Parameters:
      provider - provider to convert.
      Returns:
      List of item stacks.
    • hasProviderIItemHandler

      public static boolean hasProviderIItemHandler(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider)
      Method used to check if a ICapabilityProvider has any IItemHandler
      Parameters:
      provider - The provider to check.
      Returns:
      True when the provider has any IItemHandler, false when not.
    • isProviderSided

      public static boolean isProviderSided(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider)
      Method used to check if this provider is sided.
      Parameters:
      provider - The provider to check for.
      Returns:
      True when the provider has multiple distinct IItemHandler of different sides, false when not
    • getInventoryAsListFromProviderForSide

      @NotNull public static @NotNull List<net.minecraft.world.item.ItemStack> getInventoryAsListFromProviderForSide(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable @Nullable net.minecraft.core.Direction facing)
      Returns an IItemHandler as list of item stacks.
      Parameters:
      provider - The ICapabilityProvider that holds the IItemHandler for the given Direction
      facing - The facing to get the IItemHandler from. Can be null for the internal one
      Returns:
      List of item stacks.
    • filterItemHandlerFromProviderForSide

      @NotNull public static @NotNull List<net.minecraft.world.item.ItemStack> filterItemHandlerFromProviderForSide(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable @Nullable net.minecraft.core.Direction facing, @NotNull @NotNull net.minecraft.world.level.block.Block block)
      Filters a list of items, matches the stack using compareItems(ItemStack, Item), in an IItemHandler. Uses the MetaData and getItemFromBlock(Block) as parameters for the Predicate.
      Parameters:
      provider - The ICapabilityProvider that holds the IItemHandler for the given Direction
      facing - The facing to get the IItemHandler from. Can be null for the internal one
      block - Block to filter
      Returns:
      List of item stacks
    • filterItemHandlerFromProviderForSide

      @NotNull public static @NotNull List<net.minecraft.world.item.ItemStack> filterItemHandlerFromProviderForSide(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable @Nullable net.minecraft.core.Direction facing, @NotNull @NotNull net.minecraft.world.item.Item targetItem, int itemDamage)
      Filters a list of items, matches the stack using compareItems(ItemStack, Item), with targetItem and itemDamage as parameters, in an IItemHandler.
      Parameters:
      provider - The ICapabilityProvider that holds the IItemHandler for the given Direction
      facing - The facing to get the IItemHandler from. Can be null for the internal one
      targetItem - Item to look for
      itemDamage - the damage value.
      Returns:
      List of item stacks with the given item in inventory
    • filterItemHandlerFromProviderForSide

      @NotNull public static @NotNull List<net.minecraft.world.item.ItemStack> filterItemHandlerFromProviderForSide(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable @Nullable net.minecraft.core.Direction facing, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
      Filters a list of items, that match the given predicate, in an IItemHandler.
      Parameters:
      provider - The ICapabilityProvider that holds the IItemHandler for the given Direction
      facing - The facing to get the IItemHandler from. Can be null for the internal one
      itemStackSelectionPredicate - The predicate to match the stack to.
      Returns:
      List of item stacks that match the given predicate.
    • findFirstSlotInProviderForSideWith

      public static int findFirstSlotInProviderForSideWith(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable @Nullable net.minecraft.core.Direction facing, @NotNull @NotNull net.minecraft.world.level.block.Block block, int itemDamage)
      Returns the index of the first occurrence of the block in the ICapabilityProvider for a given Direction.
      Parameters:
      provider - ICapabilityProvider to check.
      facing - The facing to check for.
      block - Block to find.
      itemDamage - the damage value.
      Returns:
      Index of the first occurrence.
    • findFirstSlotInProviderForSideWith

      public static int findFirstSlotInProviderForSideWith(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable @Nullable net.minecraft.core.Direction facing, @NotNull @NotNull net.minecraft.world.item.Item targetItem)
      Returns the index of the first occurrence of the Item with the given ItemDamage in the ICapabilityProvider for a given Direction.
      Parameters:
      provider - ICapabilityProvider to check
      facing - The facing to check for.
      targetItem - Item to find.
      Returns:
      Index of the first occurrence
    • findFirstSlotInProviderForSideWith

      public static int findFirstSlotInProviderForSideWith(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable @Nullable net.minecraft.core.Direction facing, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
      Returns the index of the first occurrence of an ItemStack that matches the given predicate in the ICapabilityProvider for a given Direction.
      Parameters:
      provider - Provider to check
      facing - The facing to check for.
      itemStackSelectionPredicate - The predicate to match.
      Returns:
      Index of the first occurrence
    • getItemCountInProviderForSide

      public static int getItemCountInProviderForSide(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable @Nullable net.minecraft.core.Direction facing, @NotNull @NotNull net.minecraft.world.level.block.Block block)
      Returns the amount of occurrences in the ICapabilityProvider for a given Direction.
      Parameters:
      provider - ICapabilityProvider to scan.
      facing - The facing to count in.
      block - The block to count
      Returns:
      Amount of occurrences of stacks that match the given block and ItemDamage
    • getItemCountInProviderForSide

      public static int getItemCountInProviderForSide(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable @Nullable net.minecraft.core.Direction facing, @NotNull @NotNull net.minecraft.world.item.Item targetItem)
      Returns the amount of occurrences in the ICapabilityProvider for a given Direction.
      Parameters:
      provider - ICapabilityProvider to scan.
      facing - The facing to count in.
      targetItem - Item to count
      Returns:
      Amount of occurrences of stacks that match the given item and ItemDamage
    • getItemCountInProviderForSide

      public static int getItemCountInProviderForSide(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable @Nullable net.minecraft.core.Direction facing, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
      Returns the amount of occurrences in the ICapabilityProvider for a given Direction.
      Parameters:
      provider - ICapabilityProvider to scan.
      facing - The facing to count in.
      itemStackSelectionPredicate - The predicate used to select the stacks to count.
      Returns:
      Amount of occurrences of stacks that match the given predicate.
    • hasItemInProviderForSide

      public static boolean hasItemInProviderForSide(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable @Nullable net.minecraft.core.Direction facing, @NotNull @NotNull net.minecraft.world.level.block.Block block)
      Checks if a player has a block in the ICapabilityProvider, for a given Direction. Checked by getItemCountInProvider(ICapabilityProvider, Block) > 0;
      Parameters:
      provider - ICapabilityProvider to scan
      facing - The side to check for.
      block - Block to count
      Returns:
      True when in ICapabilityProvider, otherwise false
    • hasItemInProviderForSide

      public static boolean hasItemInProviderForSide(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable @Nullable net.minecraft.core.Direction facing, @NotNull @NotNull net.minecraft.world.item.Item item)
      Checks if a player has an item in the ICapabilityProvider, for a given Direction. Checked by getItemCountInProvider(ICapabilityProvider, Item) > 0;
      Parameters:
      provider - ICapabilityProvider to scan
      facing - The side to check for.
      item - Item to count
      Returns:
      True when in ICapabilityProvider, otherwise false
    • hasItemInProviderForSide

      public static boolean hasItemInProviderForSide(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable @Nullable net.minecraft.core.Direction facing, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate)
      Checks if a player has an item in the ICapabilityProvider, for a given Direction. Checked by getItemCountInProvider(ICapabilityProvider, Predicate) > 0;
      Parameters:
      provider - ICapabilityProvider to scan
      facing - The side to check for.
      itemStackSelectionPredicate - The predicate to match the ItemStack to.
      Returns:
      True when in ICapabilityProvider, otherwise false
    • isProviderFull

      public static boolean isProviderFull(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable @Nullable net.minecraft.core.Direction facing)
      Returns if the ICapabilityProvider is full, for a given Direction.
      Parameters:
      provider - The ICapabilityProvider.
      facing - The side to check for.
      Returns:
      True if the ICapabilityProvider is full, false when not.
    • getFirstOpenSlotFromProviderForSide

      public static int getFirstOpenSlotFromProviderForSide(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable @Nullable net.minecraft.core.Direction facing)
      Returns the first open slot in the ICapabilityProvider, for a given Direction.
      Parameters:
      provider - The ICapabilityProvider to check.
      facing - The side to check for.
      Returns:
      slot index or -1 if none found.
    • isEquipmentInProviderForSide

      public static boolean isEquipmentInProviderForSide(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider, @Nullable @Nullable net.minecraft.core.Direction facing, @NotNull @NotNull EquipmentTypeEntry equipmentType, int minimalLevel, int maximumLevel)
      Checks if the ICapabilityProvider contains the following EquipmentType with the given minimal Level, for a given Direction.
      Parameters:
      provider - The ICapabilityProvider to scan.
      facing - The side to check for.
      equipmentType - The equipment type to find.
      minimalLevel - The minimal level to find.
      maximumLevel - The maximum level to find.
      Returns:
      True if equipment with the given equipmentType was found in the given ICapabilityProvider, false when not.
    • isEquipmentInItemHandler

      public static boolean isEquipmentInItemHandler(@NotNull @NotNull net.minecraftforge.items.IItemHandler itemHandler, @NotNull @NotNull EquipmentTypeEntry equipmentType, int minimalLevel, int maximumLevel)
      Checks if the IItemHandler contains the following equipmentType with the given minimal Level.
      Parameters:
      itemHandler - The IItemHandler to scan.
      equipmentType - The equipmentType of the equipment to find.
      minimalLevel - The minimal level to find.
      maximumLevel - The maximum level to find.
      Returns:
      True if equipment with the given EquipmentType was found in the given IItemHandler, false when not.
    • clearItemHandler

      public static void clearItemHandler(@NotNull @NotNull net.minecraftforge.items.IItemHandler itemHandler)
      Clears an entire IItemHandler.
      Parameters:
      itemHandler - IItemHandler to clear.
    • getFirstSlotOfItemHandlerContainingEquipment

      public static int getFirstSlotOfItemHandlerContainingEquipment(@NotNull @NotNull net.minecraftforge.items.IItemHandler itemHandler, @NotNull @NotNull EquipmentTypeEntry equipmentType, int minimalLevel, int maximumLevel)
      Returns a slot number if an IItemHandler contains given equipment type.
      Parameters:
      itemHandler - the IItemHandler to get the slot from.
      equipmentType - the equipment type to look for.
      minimalLevel - The minimal level to find.
      maximumLevel - The maximum level to find.
      Returns:
      slot number if found, -1 if not found.
    • hasItemHandlerEquipmentWithLevel

      public static boolean hasItemHandlerEquipmentWithLevel(@NotNull @NotNull net.minecraftforge.items.IItemHandler itemHandler, EquipmentTypeEntry equipmentType, int requiredLevel, int maximumLevel)
      Verifies if there is one equipment with an acceptable level in a worker's inventory.
      Parameters:
      itemHandler - the worker's inventory
      equipmentType - the type of equipment needed
      requiredLevel - the minimum equipment level
      maximumLevel - the worker's hut level
      Returns:
      true if equipment is acceptable
    • transferItemStackIntoNextFreeSlotInProvider

      public static boolean transferItemStackIntoNextFreeSlotInProvider(@NotNull @NotNull net.minecraftforge.items.IItemHandler sourceHandler, int sourceIndex, @NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider targetProvider)
      Method to swap the ItemStacks from the given source IItemHandler to the given target ICapabilityProvider.
      Parameters:
      sourceHandler - The IItemHandler that works as Source.
      sourceIndex - The index of the slot that is being extracted from.
      targetProvider - The ICapabilityProvider that works as Target.
      Returns:
      True when the swap was successful, false when not.
    • transferItemStackIntoNextFreeSlotInItemHandler

      public static boolean transferItemStackIntoNextFreeSlotInItemHandler(@NotNull @NotNull net.minecraftforge.items.IItemHandler sourceHandler, int sourceIndex, @NotNull @NotNull net.minecraftforge.items.IItemHandler targetHandler)
      Method to swap the ItemStacks from the given source IItemHandler to the given target IItemHandler.
      Parameters:
      sourceHandler - The IItemHandler that works as Source.
      sourceIndex - The index of the slot that is being extracted from.
      targetHandler - The IItemHandler that works as Target.
      Returns:
      True when the swap was successful, false when not.
    • transferXOfItemStackIntoNextFreeSlotInItemHandler

      public static boolean transferXOfItemStackIntoNextFreeSlotInItemHandler(@NotNull @NotNull net.minecraftforge.items.IItemHandler sourceHandler, int sourceIndex, int count, @NotNull @NotNull net.minecraftforge.items.IItemHandler targetHandler)
      Method to swap the ItemStacks from the given source IItemHandler to the given target IItemHandler.
      Parameters:
      sourceHandler - The IItemHandler that works as Source.
      sourceIndex - The index of the slot that is being extracted from.
      count - the quantity.
      targetHandler - The IItemHandler that works as Target.
      Returns:
      True when the swap was successful, false when not.
    • transferItemStackIntoNextBestSlotInItemHandler

      public static boolean transferItemStackIntoNextBestSlotInItemHandler(@NotNull @NotNull net.minecraftforge.items.IItemHandler sourceHandler, int sourceIndex, @NotNull @NotNull net.minecraftforge.items.IItemHandler targetHandler)
      Method to swap the ItemStacks from the given source IItemHandler to the given target IItemHandler. Trying to merge existing itemStacks if possible.
      Parameters:
      sourceHandler - The IItemHandler that works as Source.
      sourceIndex - The index of the slot that is being extracted from.
      targetHandler - The IItemHandler that works as Target.
      Returns:
      True when the swap was successful, false when not.
    • transferItemStackIntoNextBestSlotInItemHandler

      public static boolean transferItemStackIntoNextBestSlotInItemHandler(@NotNull @NotNull net.minecraftforge.items.IItemHandler sourceHandler, Predicate<net.minecraft.world.item.ItemStack> predicate, @NotNull @NotNull net.minecraftforge.items.IItemHandler targetHandler)
      Method to transfer an ItemStacks from the given source IItemHandler to the given target IItemHandler.
      Parameters:
      sourceHandler - The IItemHandler that works as Source.
      predicate - the predicate for the stack.
      targetHandler - The IItemHandler that works as Target.
      Returns:
      true when the swap was successful, false when not.
    • transferItemStackIntoNextBestSlotInItemHandler

      public static boolean transferItemStackIntoNextBestSlotInItemHandler(@NotNull @NotNull IBuilding building, ItemStorage storage, int qty, @NotNull @NotNull net.minecraftforge.items.IItemHandler targetHandler)
      Method to transfer an ItemStacks from the given source IBuilding to the given target IItemHandler.
      Parameters:
      building - The IBuilding that works as Source.
      storage - the ItemStorage.
      qty - the qty.
      targetHandler - The IItemHandler that works as Target.
      Returns:
      true when the swap was successful, false when not.
    • transferItemStackIntoNextBestSlotInItemHandler

      public static boolean transferItemStackIntoNextBestSlotInItemHandler(@NotNull @NotNull IBuilding building, ItemStorage storage, @NotNull @NotNull net.minecraftforge.items.IItemHandler targetHandler)
      Method to transfer an ItemStacks from the given source IBuilding to the given target IItemHandler.
      Parameters:
      building - The IBuilding that works as Source.
      storage - the ItemStorage.
      targetHandler - The IItemHandler that works as Target.
      Returns:
      true when the swap was successful, false when not.
    • transferItemStackIntoNextBestSlotInItemHandler

      public static boolean transferItemStackIntoNextBestSlotInItemHandler(net.minecraft.world.item.ItemStack stack, @NotNull @NotNull net.minecraftforge.items.IItemHandler targetHandler)
      Method to put a given Itemstack in a given target IItemHandler. Trying to merge existing itemStacks if possible.
      Parameters:
      stack - the itemStack to transfer.
      targetHandler - The IItemHandler that works as Target.
      Returns:
      True when the swap was successful, false when not.
    • transferItemStackIntoNextBestSlotInItemHandlerWithResult

      public static net.minecraft.world.item.ItemStack transferItemStackIntoNextBestSlotInItemHandlerWithResult(net.minecraft.world.item.ItemStack stack, @NotNull @NotNull net.minecraftforge.items.IItemHandler targetHandler)
      Method to put a given Itemstack in a given target IItemHandler. Trying to merge existing itemStacks if possible.
      Parameters:
      stack - the itemStack to transfer.
      targetHandler - The IItemHandler that works as Target.
      Returns:
      the rest of the stack.
    • mergeItemStackIntoNextBestSlotInItemHandlers

      public static void mergeItemStackIntoNextBestSlotInItemHandlers(@NotNull @NotNull net.minecraftforge.items.IItemHandler sourceHandler, int sourceIndex, @NotNull @NotNull net.minecraftforge.items.IItemHandler targetHandler)
      Method to merge the ItemStacks from the given source IItemHandler to the given target IItemHandler. Trying to merge itemStacks or returning stack if not possible.
      Parameters:
      sourceHandler - The IItemHandler that works as Source.
      sourceIndex - The index of the slot that is being extracted from.
      targetHandler - The IItemHandler that works as Target.
    • mergeItemStackIntoNextBestSlotInItemHandlers

      public static net.minecraft.world.item.ItemStack mergeItemStackIntoNextBestSlotInItemHandlers(net.minecraft.world.item.ItemStack stack, @NotNull @NotNull net.minecraftforge.items.IItemHandler targetHandler)
      Method to merge the ItemStacks from the given source IItemHandler to the given target IItemHandler. Trying to merge itemStacks or returning stack if not possible.
      Parameters:
      stack - the stack to add.
      targetHandler - The IItemHandler that works as Target.
      Returns:
      True when the swap was successful, false when not.
    • transferXOfFirstSlotInProviderWithIntoNextFreeSlotInProvider

      public static boolean transferXOfFirstSlotInProviderWithIntoNextFreeSlotInProvider(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider sourceProvider, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider targetProvider)
    • transferXOfFirstSlotInProviderWithIntoNextFreeSlotInProviderWithResult

      public static int transferXOfFirstSlotInProviderWithIntoNextFreeSlotInProviderWithResult(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider sourceProvider, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider targetProvider)
    • transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandler

      public static boolean transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandler(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider sourceProvider, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull @NotNull net.minecraftforge.items.IItemHandler targetHandler)
    • transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandlerWithResult

      public static int transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandlerWithResult(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider sourceProvider, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull @NotNull net.minecraftforge.items.IItemHandler targetHandler)
      Transfer items over and return the leftover that couldn't be transfered (0 if full amount was transfered).
      Parameters:
      sourceProvider -
      itemStackSelectionPredicate -
      amount -
      targetHandler -
      Returns:
      missing reminder compared to amount.
    • transferXOfFirstSlotInItemHandlerWithIntoNextFreeSlotInItemHandler

      public static boolean transferXOfFirstSlotInItemHandlerWithIntoNextFreeSlotInItemHandler(@NotNull @NotNull net.minecraftforge.items.IItemHandler sourceHandler, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull @NotNull net.minecraftforge.items.IItemHandler targetHandler)
    • transferXOfFirstSlotInItemHandlerWithIntoNextFreeSlotInItemHandlerWithResult

      public static int transferXOfFirstSlotInItemHandlerWithIntoNextFreeSlotInItemHandlerWithResult(@NotNull @NotNull net.minecraftforge.items.IItemHandler sourceHandler, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull @NotNull net.minecraftforge.items.IItemHandler targetHandler)
    • transferXInItemHandlerIntoSlotInItemHandler

      public static int transferXInItemHandlerIntoSlotInItemHandler(net.minecraftforge.items.IItemHandler sourceHandler, Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, net.minecraftforge.items.IItemHandler targetHandler, int slot)
      Takes an item matching a predicate and moves it form one handler across multiple slots to the other to a specific slot.
      Parameters:
      sourceHandler - the source handler.
      itemStackSelectionPredicate - the predicate.
      amount - the max amount to extract
      targetHandler - the target.
      slot - the slot to put it in.
      Returns:
      the count of items actually transferred
    • transferXOfFirstSlotInItemHandlerWithIntoInItemHandler

      public static int transferXOfFirstSlotInItemHandlerWithIntoInItemHandler(net.minecraftforge.items.IItemHandler sourceHandler, Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, net.minecraftforge.items.IItemHandler targetHandler, int slot)
      Takes an item matching a predicate and moves it form one handler to the other to a specific slot.
      Parameters:
      sourceHandler - the source handler.
      itemStackSelectionPredicate - the predicate.
      amount - the max amount to extract
      targetHandler - the target.
      slot - the slot to put it in.
      Returns:
      the count of items actually transferred
    • transferItemStackIntoNextFreeSlotFromProvider

      public static boolean transferItemStackIntoNextFreeSlotFromProvider(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider sourceProvider, int sourceIndex, @NotNull @NotNull net.minecraftforge.items.IItemHandler targetHandler)
      Method to swap the ItemStacks from the given source ICapabilityProvider to the given target IItemHandler.
      Parameters:
      sourceProvider - The ICapabilityProvider that works as Source.
      sourceIndex - The index of the slot that is being extracted from.
      targetHandler - The IItemHandler that works as Target.
      Returns:
      True when the swap was successful, false when not.
    • transferItemStackIntoNextFreeSlotFromItemHandler

      public static boolean transferItemStackIntoNextFreeSlotFromItemHandler(@NotNull @NotNull net.minecraftforge.items.IItemHandler handler, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> stackPredicate, int count, @NotNull @NotNull net.minecraftforge.items.IItemHandler targetHandler)
      Method to swap the ItemStacks from the given source IItemHandler to the given target IItemHandler.
      Parameters:
      handler - The IItemHandler that works as Source.
      stackPredicate - The type of stack to pickup.
      count - how much to pick up.
      targetHandler - The IItemHandler that works as Target.
      Returns:
      True when the swap was successful, false when not.
    • transferXOfItemStackIntoNextFreeSlotFromProvider

      public static boolean transferXOfItemStackIntoNextFreeSlotFromProvider(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider sourceProvider, int sourceIndex, int count, @NotNull @NotNull net.minecraftforge.items.IItemHandler targetHandler)
      Method to swap the ItemStacks from the given source ICapabilityProvider to the given target IItemHandler.
      Parameters:
      sourceProvider - The ICapabilityProvider that works as Source.
      sourceIndex - The index of the slot that is being extracted from.
      count - the quantity.
      targetHandler - The IItemHandler that works as Target.
      Returns:
      True when the swap was successful, false when not.
    • transferItemStackIntoNextBestSlotFromProvider

      public static boolean transferItemStackIntoNextBestSlotFromProvider(@NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider sourceProvider, int sourceIndex, @NotNull @NotNull net.minecraftforge.items.IItemHandler targetHandler)
      Method to swap the ItemStacks from the given source ICapabilityProvider to the given target IItemHandler.
      Parameters:
      sourceProvider - The ICapabilityProvider that works as Source.
      sourceIndex - The index of the slot that is being extracted from.
      targetHandler - The IItemHandler that works as Target.
      Returns:
      True when the swap was successful, false when not.
    • swapItemStacksInItemHandlers

      public static boolean swapItemStacksInItemHandlers(@NotNull @NotNull net.minecraftforge.items.IItemHandler sourceHandler, int sourceIndex, @NotNull @NotNull net.minecraftforge.items.IItemHandler targetHandler, int targetIndex)
      Method to swap the ItemStacks from the given source IItemHandler to the given target IItemHandler.
      Parameters:
      sourceHandler - The IItemHandler that works as Source.
      sourceIndex - The index of the slot that is being extracted from.
      targetHandler - The IItemHandler that works as Target.
      targetIndex - The index of the slot that is being inserted into.
      Returns:
      True when the swap was successful, false when not.
    • removeStacksFromProvider

      public static boolean removeStacksFromProvider(net.minecraftforge.common.capabilities.ICapabilityProvider provider, List<net.minecraft.world.item.ItemStack> input)
      Remove a list of stacks from a given provider
      Parameters:
      provider - the provider.
      input - the list of stacks.
      Returns:
      true if succesful.
    • removeStacksFromItemHandler

      public static boolean removeStacksFromItemHandler(net.minecraftforge.items.IItemHandler handler, List<net.minecraft.world.item.ItemStack> input)
      Remove a list of stacks from a given Itemhandler
      Parameters:
      handler - the itemHandler.
      input - the list of stacks.
      Returns:
      true if succesful.
    • tryRemoveStackFromItemHandler

      public static boolean tryRemoveStackFromItemHandler(net.minecraftforge.items.IItemHandler handler, net.minecraft.world.item.ItemStack input)
      Tries to remove a stack with its size from a given Itemhandler. Only removes sth if the whole size can be removed.
      Parameters:
      handler - the itemHandler.
      input - the stack to remove.
      Returns:
      true if removed the stack
    • removeStackFromItemHandler

      public static void removeStackFromItemHandler(net.minecraftforge.items.IItemHandler handler, net.minecraft.world.item.ItemStack input, int count)
      Force remove a stack with a certain amount from a given Itemhandler
      Parameters:
      handler - the itemHandler.
      input - the stack to remove.
      count - the amount to remove.
    • findSlotInProviderNotFullWithItem

      public static int findSlotInProviderNotFullWithItem(net.minecraftforge.common.capabilities.ICapabilityProvider provider, net.minecraft.world.item.Item item, int amount)
      Check if a certain item is in the provider but without the provider being full.
      Parameters:
      provider - the provider to check.
      item - the item.
      amount - stack size to be considered.
      Returns:
      the slot or -1.
    • findSlotInItemHandlerNotFullWithItem

      public static int findSlotInItemHandlerNotFullWithItem(net.minecraftforge.items.IItemHandler handler, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount)
      Check if a certain item is in the handler but without the provider being full. Return as soon as an empty slot and a matching slot has been found. Returns the last matching slot it found.
      Parameters:
      handler - the handler to check.
      itemStackSelectionPredicate - the selection predicate..
      amount - stack size to be considered.
      Returns:
      the slot or -1.
    • findSlotInItemHandlerNotFullWithItem

      public static boolean findSlotInItemHandlerNotFullWithItem(net.minecraftforge.items.IItemHandler handler, net.minecraft.world.item.ItemStack inStack)
      Check if a similar item is in the handler but without the provider being full. Return as soon as an empty slot and a matching slot has been found. Returns the last matching slot it found.
      Parameters:
      handler - the handler to check.
      inStack - the ItemStack
      Returns:
      true if fitting.
    • dropItemHandler

      public static void dropItemHandler(net.minecraftforge.items.IItemHandler handler, net.minecraft.world.level.Level world, int x, int y, int z)
      Drop an actual itemHandler in the world.
      Parameters:
      handler - the handler.
      world - the world.
      x - the x pos.
      y - the y pos.
      z - the z pos.
    • transferAllItemHandler

      public static boolean transferAllItemHandler(net.minecraftforge.items.IItemHandler origin, net.minecraftforge.items.IItemHandler target)
      Attempt to transfer as much item as possible from origin to target inventory
      Parameters:
      origin - the handler.
      target - the world.
      Returns:
      true if all item transfered, false if some item remain in origin
    • spawnItemStack

      public static void spawnItemStack(net.minecraft.world.level.Level worldIn, double x, double y, double z, net.minecraft.world.item.ItemStack stack)
      Spawn an itemStack in the world.
      Parameters:
      worldIn - the world.
      x - the x pos.
      y - the y pos.
      z - the z pos.
      stack - the stack to drop.
    • getItemCountInStackLick

      public static int getItemCountInStackLick(@NotNull @NotNull List<net.minecraft.world.item.ItemStack> stacks, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> stackPredicate)
      Calculates howmany items match the given predicate that are in the list.
      Parameters:
      stacks - the stacks to count in.
      stackPredicate - the condition to count for.
      Returns:
      The sum of the itemstack sizes that match the predicate
    • areAllItemsInItemHandler

      public static boolean areAllItemsInItemHandler(@NotNull @NotNull List<net.minecraft.world.item.ItemStack> stacks, @NotNull @NotNull net.minecraftforge.items.IItemHandler handler)
      Checks if all stacks given in the list are in the itemhandler given
      Parameters:
      stacks - The stacks that should be in the itemhandler
      handler - The itemhandler to check in
      Returns:
      True when all stacks are in the handler, false when not
    • areAllItemsInProvider

      public static boolean areAllItemsInProvider(@NotNull @NotNull List<net.minecraft.world.item.ItemStack> stacks, @NotNull @NotNull net.minecraftforge.common.capabilities.ICapabilityProvider provider)
      Checks if all stacks given in the list are in the capability provider given
      Parameters:
      stacks - The stacks that should be in the itemhandler
      provider - The provider to check in
      Returns:
      True when all stacks are in the handler, false when not
    • areAllItemsInItemHandlerList

      public static boolean areAllItemsInItemHandlerList(@NotNull @NotNull List<net.minecraft.world.item.ItemStack> stacks, @NotNull @NotNull Collection<net.minecraftforge.items.IItemHandler> handlers)
      Checks if all stacks given in the list are in at least one of the given the itemhandlers
      Parameters:
      stacks - The stacks that should be in the itemhandlers
      handlers - The itemhandlers to check in
      Returns:
      True when all stacks are in at least one of the handlers, false when not
    • getMergedCountedStacksFromList

      public static Map<net.minecraft.world.item.ItemStack,Integer> getMergedCountedStacksFromList(@NotNull @NotNull List<net.minecraft.world.item.ItemStack> stacks)
      This method calculates the amount of items in itemstacks are contained within a list.
      Parameters:
      stacks - The stacks to count.
      Returns:
      A map with a entry for each unique unified itemstack and its count in the list.
    • splitMergedCountedStacksIntoMaxContentStacks

      public static List<net.minecraft.world.item.ItemStack> splitMergedCountedStacksIntoMaxContentStacks(@NotNull @NotNull Map<net.minecraft.world.item.ItemStack,Integer> mergedCountedStacks)
      This method splits a map with an entry for each unique unified itemstack and its count into a list of itemstacks that represent the maps, taken the max stack size into account.
      Parameters:
      mergedCountedStacks - the map with the unique unified itemstacks and their counts.
      Returns:
      The list of itemstacks that represent the map, taken the max stack size into account.
    • getContainedFromItemHandler

      public static List<net.minecraft.world.item.ItemStack> getContainedFromItemHandler(@NotNull @NotNull List<net.minecraft.world.item.ItemStack> stacks, @NotNull @NotNull net.minecraftforge.items.IItemHandler handler)
      Searches a given itemhandler for the stacks given and returns the list that is contained in the itemhandler
      Parameters:
      stacks - The stacks to search for
      handler - The handler to search in
      Returns:
      The sublist of the stacks list contained in the itemhandler.
    • processItemStackListAndMerge

      public static List<net.minecraft.world.item.ItemStack> processItemStackListAndMerge(@NotNull @NotNull List<net.minecraft.world.item.ItemStack> stacks)
      Unifies a list of stacks so that they are all packed to together to the max stack size.
      Parameters:
      stacks - The stacks to pack.
      Returns:
      The packed stacks
    • moveItemStacksWithPossibleSwap

      public static boolean moveItemStacksWithPossibleSwap(@NotNull @NotNull net.minecraftforge.items.IItemHandler targetInventory, @NotNull @NotNull Collection<net.minecraftforge.items.IItemHandler> sourceInventories, @NotNull @NotNull List<net.minecraft.world.item.ItemStack> toSwap, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> toKeepInTarget)
      Attempts a swap with the given itemstacks, from the source to the target inventory. Itemstacks in the target that match the given toKeepInTarget predicate will not be swapped out, if swapping is needed
      Parameters:
      targetInventory - The target inventory.
      sourceInventories - The source inventory.
      toSwap - The list of stacks to swap.
      toKeepInTarget - The predicate that determines what not to swap in the target.
      Returns:
      True when moving was successfull, false when not
    • reduceStackInItemHandler

      public static void reduceStackInItemHandler(net.minecraftforge.items.IItemHandler invWrapper, net.minecraft.world.item.ItemStack itemStack)
      Search for a certain itemStack in the inventory and decrease it by 1.
      Parameters:
      invWrapper - the inventory item handler.
      itemStack - the itemStack to decrease.
    • reduceStackInItemHandler

      public static void reduceStackInItemHandler(net.minecraftforge.items.IItemHandler invWrapper, net.minecraft.world.item.ItemStack itemStack, int quantity)
      Search for a certain itemStack in the inventory and decrease it by a certain quantity.
      Parameters:
      invWrapper - the inventory item handler.
      itemStack - the itemStack to decrease.
      quantity - the quantity.
    • reduceBucketAwareStackInItemHandler

      public static void reduceBucketAwareStackInItemHandler(net.minecraftforge.items.IItemHandler invWrapper, net.minecraft.world.item.ItemStack itemStack)
      Search for a certain itemStack in the inventory and decrease it by 1. This is "bucket-aware", in that if a full bucket is used by the decrease, an empty bucket replaces it.
      Parameters:
      invWrapper - the inventory item handler.
      itemStack - the itemStack to decrease.
    • reduceBucketAwareStackInItemHandler

      public static void reduceBucketAwareStackInItemHandler(net.minecraftforge.items.IItemHandler invWrapper, net.minecraft.world.item.ItemStack itemStack, int quantity)
      Search for a certain itemStack in the inventory and decrease it by a certain quantity. This is "bucket-aware", in that if a full bucket is used by the decrease, an empty bucket replaces it.
      Parameters:
      invWrapper - the inventory item handler.
      itemStack - the itemStack to decrease.
      quantity - the quantity.
    • attemptReduceStackInItemHandler

      public static boolean attemptReduceStackInItemHandler(net.minecraftforge.items.IItemHandler invWrapper, net.minecraft.world.item.ItemStack itemStack, int quantity)
      Search for a certain itemStack in the inventory and decrease it by a certain quantity.
      Parameters:
      invWrapper - the inventory item handler.
      itemStack - the itemStack to decrease.
      quantity - the quantity.
      Returns:
      true if successfully.
    • attemptReduceStackInItemHandler

      public static boolean attemptReduceStackInItemHandler(net.minecraftforge.items.IItemHandler invWrapper, net.minecraft.world.item.ItemStack itemStack, int quantity, boolean ignoreDamage, boolean ignoreNBT)
      Search for a certain itemStack in the inventory and decrease it by a certain quantity.
      Parameters:
      invWrapper - the inventory item handler.
      itemStack - the itemStack to decrease.
      quantity - the quantity.
      ignoreDamage - ignore damage values.
      ignoreNBT - ignore NBT values.
      Returns:
      true if successfully.
    • getAllItemsForProviders

      public static Map<ItemStorage,ItemStorage> getAllItemsForProviders(net.minecraftforge.common.capabilities.ICapabilityProvider provider, net.minecraftforge.items.IItemHandler... handlers)
      Sums up all items in the given provider/handlers
      Parameters:
      provider - inventory provider
      handlers - inventory handlers
      Returns:
      Map of IdentityItemstorage
    • getAllItemsForProviders

      public static Map<ItemStorage,ItemStorage> getAllItemsForProviders(net.minecraftforge.items.IItemHandler... handlers)
      Sums up all items in the given handlers
      Parameters:
      handlers - inventory handlers
      Returns:
      Map of IdentityItemstorage
    • getAllItemsForProviders

      public static Map<ItemStorage,ItemStorage> getAllItemsForProviders(Set<net.minecraftforge.items.IItemHandler> handlerList)
      Sums up all items in the given handlers
      Parameters:
      handlerList - inventory handlers
      Returns:
      Map of IdentityItemstorage
    • doStorageSetsMatch

      public static boolean doStorageSetsMatch(Map<ItemStorage,ItemStorage> first, Map<ItemStorage,ItemStorage> second, boolean showTrace)
      Returns whether two sets of itemstorage has the same content
      Parameters:
      first - First set of item storages
      second - Second set of item storages
      showTrace - whther to print a stacktrace on false
      Returns:
      true if matching
    • transferFoodUpToSaturation

      public static it.unimi.dsi.fastutil.objects.Object2IntMap<net.minecraft.world.item.ItemStack> transferFoodUpToSaturation(net.minecraftforge.common.capabilities.ICapabilityProvider source, net.minecraftforge.items.IItemHandler target, int requiredSaturation, Predicate<net.minecraft.world.item.ItemStack> foodPredicate)
      Transfers food items from the source with the required saturation value, or as much as possible.
      Parameters:
      source - to extract items from
      target - to insert intems into
      requiredSaturation - required saturation value
      foodPredicate - food choosing predicate
    • putItemToHotbarAndSelectOrDrop

      public static boolean putItemToHotbarAndSelectOrDrop(net.minecraft.world.item.ItemStack itemStack, net.minecraft.world.entity.player.Player player)
      Tries to put given itemstack in hotbar and select it, fails when player inventory is full, successes otherwise.
      Parameters:
      itemStack - itemstack to put into player's inv
      player - player entity
      Returns:
      true if item was put into player's inv, false if dropped
    • putItemToHotbarAndSelectOrDropMessage

      public static boolean putItemToHotbarAndSelectOrDropMessage(net.minecraft.world.item.ItemStack itemStack, net.minecraft.world.entity.player.Player player)
      Tries to put given itemstack in hotbar, fails when player inventory is full, successes otherwise. If fails sends a message to player about dropped item.
      Parameters:
      itemStack - itemstack to put into player's inv
      player - player entity
      Returns:
      true if item was put into player's inv, false if dropped
    • getOrCreateItemAndPutToHotbarAndSelectOrDrop

      public static net.minecraft.world.item.ItemStack getOrCreateItemAndPutToHotbarAndSelectOrDrop(net.minecraft.world.item.Item item, net.minecraft.world.entity.player.Player player, Supplier<net.minecraft.world.item.ItemStack> itemStackFactory, boolean messageOnDrop)
      If item is already in inventory then it's moved to hotbar and returned. Else putItemToHotbarAndSelectOrDrop(net.minecraft.world.item.ItemStack, net.minecraft.world.entity.player.Player) is called with itemstack created from given factory.
      Parameters:
      item - item to search for
      player - player inventory to check and use
      itemStackFactory - factory for new item if not found
      messageOnDrop - if true message player when new item was dropped
      Returns:
      itemstack in hotbar or dropped in front of player
    • hasEnoughInProvider

      public static boolean hasEnoughInProvider(net.minecraft.world.level.block.entity.BlockEntity entity, net.minecraft.world.item.ItemStack stack, int count)
      Check if there is enough of a given stack in the provider.
      Parameters:
      entity - the provider.
      stack - the stack to count.
      count - the count.
      Returns:
      true if enough.
    • getBuildingInventory

      public static List<net.minecraft.world.item.ItemStack> getBuildingInventory(IBuilding building)
    • getFirstMatch

      public static net.minecraft.world.item.ItemStack getFirstMatch(List<net.minecraft.world.item.ItemStack> stacks, Predicate<net.minecraft.world.item.ItemStack> stackPredicate)
      Gets the first matching itemstack from a list
      Parameters:
      stacks -
      stackPredicate -
      Returns:
    • reduceBuildingThenPlayerInventory

      public static ItemStorage reduceBuildingThenPlayerInventory(IBuilding building, net.minecraft.world.entity.player.Player player, ItemStorage itemsToTake, Predicate<net.minecraft.world.item.ItemStack> buildingPredicate, Predicate<net.minecraft.world.item.ItemStack> playerPredicate)
      This method will first try to remove items from the building inventory, then from the player inventory. If the building inventory has enough items, then the player inventory will not be touched.
      Parameters:
      building - the building to take items from.
      player - the player to take items from.
      itemsToTake - the items to take from the building and player inventory.
      Returns:
      a ItemStorage (item and amount) which could not be satisfied from the building and player inventory. For successful complete removal, the amount will be 0.