Package com.minecolonies.api.util
Class InventoryUtils
java.lang.Object
com.minecolonies.api.util.InventoryUtils
Utility methods for the inventories.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanaddItemStackToItemHandler(@NotNull net.neoforged.neoforge.items.IItemHandler itemHandler, @Nullable net.minecraft.world.item.ItemStack itemStack) Add stack to item handler.static net.minecraft.world.item.ItemStackaddItemStackToItemHandlerWithResult(@NotNull net.neoforged.neoforge.items.IItemHandler itemHandler, @Nullable net.minecraft.world.item.ItemStack itemStack) Add stack to handler with result.static booleanaddItemStackToProvider(@NotNull IItemHandlerCapProvider provider, @Nullable net.minecraft.world.item.ItemStack itemStack) Add stack to provider.static net.minecraft.world.item.ItemStackaddItemStackToProviderWithResult(@NotNull IItemHandlerCapProvider provider, @Nullable net.minecraft.world.item.ItemStack itemStack) Add stack to provider with result.static booleanareAllItemsInItemHandler(@NotNull List<net.minecraft.world.item.ItemStack> stacks, @NotNull net.neoforged.neoforge.items.IItemHandler handler) Checks if all stacks given in the list are in the itemhandler givenstatic booleanareAllItemsInItemHandlerList(@NotNull List<net.minecraft.world.item.ItemStack> stacks, @NotNull Collection<net.neoforged.neoforge.items.IItemHandler> handlers) Checks if all stacks given in the list are in at least one of the given the itemhandlersstatic booleanareAllItemsInProvider(@NotNull List<net.minecraft.world.item.ItemStack> stacks, @NotNull IItemHandlerCapProvider provider) Checks if all stacks given in the list are in the capability provider givenstatic booleanattemptReduceStackInItemHandler(net.neoforged.neoforge.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 booleanattemptReduceStackInItemHandler(net.neoforged.neoforge.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 voidclearItemHandler(@NotNull net.neoforged.neoforge.items.IItemHandler itemHandler) Clears an entireIItemHandler.static intcountEmptySlotsInBuilding(IBuilding ownBuilding) Calculate the number of empty slots in a given building.static booleandoStorageSetsMatch(Map<ItemStorage, ItemStorage> first, Map<ItemStorage, ItemStorage> second, boolean showTrace) Returns whether two sets of itemstorage has the same contentstatic voiddropItemHandler(net.neoforged.neoforge.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.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate) Filters a list of items, that match the given predicate, in anIItemHandler.static @NotNull List<net.minecraft.world.item.ItemStack> filterItemHandler(@NotNull net.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull net.minecraft.world.item.Item targetItem) Filters a list of items, matches the stack usingcompareItems(ItemStack, Item), with targetItem and itemDamage as parameters, in anIItemHandler.static @NotNull List<net.minecraft.world.item.ItemStack> filterItemHandler(@NotNull net.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull net.minecraft.world.level.block.Block block) Filters a list of items, matches the stack usingcompareItems(ItemStack, Item), in anIItemHandler.static @NotNull List<net.minecraft.world.item.ItemStack> filterItemHandlerFromProviderForSide(@NotNull IItemHandlerCapProvider 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 anIItemHandler.static @NotNull List<net.minecraft.world.item.ItemStack> filterItemHandlerFromProviderForSide(@NotNull IItemHandlerCapProvider provider, @Nullable net.minecraft.core.Direction facing, @NotNull net.minecraft.world.item.Item targetItem, int itemDamage) Filters a list of items, matches the stack usingcompareItems(ItemStack, Item), with targetItem and itemDamage as parameters, in anIItemHandler.static @NotNull List<net.minecraft.world.item.ItemStack> filterItemHandlerFromProviderForSide(@NotNull IItemHandlerCapProvider provider, @Nullable net.minecraft.core.Direction facing, @NotNull net.minecraft.world.level.block.Block block) Filters a list of items, matches the stack usingcompareItems(ItemStack, Item), in anIItemHandler.static @NotNull List<net.minecraft.world.item.ItemStack> filterProvider(@NotNull IItemHandlerCapProvider provider, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate) Filters a list of items, that match the given predicate, in anICapabilityProvider.static @NotNull List<net.minecraft.world.item.ItemStack> filterProvider(@NotNull IItemHandlerCapProvider provider, @Nullable net.minecraft.world.item.Item targetItem) Filters a list of items, matches the stack usingcompareItems(ItemStack, Item), with targetItem and itemDamage as parameters, in anICapabilityProvider.static @NotNull List<net.minecraft.world.item.ItemStack> filterProvider(@NotNull IItemHandlerCapProvider provider, net.minecraft.world.level.block.Block block) Filters a list of items, matches the stack usingcompareItems(ItemStack, Item), in anICapabilityProvider.findAllSlotsInItemHandlerWith(@NotNull net.neoforged.neoforge.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 theIItemHandler.findAllSlotsInProviderWith(@NotNull IItemHandlerCapProvider provider, Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate) Returns a map with all itemhandlers and slots matching the predicate in the provider.static intfindFirstSlotInItemHandlerNotEmptyWith(@NotNull net.neoforged.neoforge.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 theIItemHandler.static intfindFirstSlotInItemHandlerWith(@NotNull net.neoforged.neoforge.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 theIItemHandler.static intfindFirstSlotInItemHandlerWith(@NotNull net.neoforged.neoforge.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 theIItemHandler.static intfindFirstSlotInItemHandlerWith(@NotNull net.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull net.minecraft.world.level.block.Block block) Returns the index of the first occurrence of the block in theIItemHandler.static intfindFirstSlotInProviderForSideWith(@NotNull IItemHandlerCapProvider 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 theICapabilityProviderfor a givenDirection.static intfindFirstSlotInProviderForSideWith(@NotNull IItemHandlerCapProvider 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 theICapabilityProviderfor a givenDirection.static intfindFirstSlotInProviderForSideWith(@NotNull IItemHandlerCapProvider 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 theICapabilityProviderfor a givenDirection.static intfindFirstSlotInProviderNotEmptyWith(@NotNull IItemHandlerCapProvider provider, Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate) Returns the index of the first occurrence of an ItemStack that matches the given predicate in theICapabilityProvider.static intfindFirstSlotInProviderNotEmptyWith(@NotNull IItemHandlerCapProvider 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 theICapabilityProvider.static intfindFirstSlotInProviderWith(@NotNull IItemHandlerCapProvider provider, net.minecraft.world.item.Item targetItem) Returns the index of the first occurrence of the Item with the given ItemDamage in theICapabilityProvider.static intfindFirstSlotInProviderWith(@NotNull IItemHandlerCapProvider provider, net.minecraft.world.level.block.Block block) Returns the index of the first occurrence of the block in theICapabilityProvider.static intfindSlotInItemHandlerNotFullWithItem(net.neoforged.neoforge.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 booleanfindSlotInItemHandlerNotFullWithItem(net.neoforged.neoforge.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 intfindSlotInProviderNotFullWithItem(IItemHandlerCapProvider 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.ItemStackforceItemStackToItemHandler(@NotNull net.neoforged.neoforge.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.ItemStackforceItemStackToProvider(@NotNull IItemHandlerCapProvider provider, @NotNull net.minecraft.world.item.ItemStack itemStack, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackToKeepPredicate) Force stack to provider.static Map<ItemStorage, ItemStorage> getAllItemsForProviders(IItemHandlerCapProvider provider, net.neoforged.neoforge.items.IItemHandler... handlers) Sums up all items in the given provider/handlersstatic Map<ItemStorage, ItemStorage> getAllItemsForProviders(Set<net.neoforged.neoforge.items.IItemHandler> handlerList) Sums up all items in the given handlersstatic Map<ItemStorage, ItemStorage> getAllItemsForProviders(net.neoforged.neoforge.items.IItemHandler... handlers) Sums up all items in the given handlersstatic intgetAmountOfStacksInItemHandler(@NotNull net.neoforged.neoforge.items.IItemHandler itemHandler) Returns the amount of item stacks in an inventory.static intgetAmountOfStacksInProvider(@NotNull IItemHandlerCapProvider provider) Returns the amount of item stacks in an inventory.static List<net.minecraft.world.item.ItemStack> getBuildingInventory(IBuilding building) static List<net.minecraft.world.item.ItemStack> getContainedFromItemHandler(@NotNull List<net.minecraft.world.item.ItemStack> stacks, @NotNull net.neoforged.neoforge.items.IItemHandler handler) Searches a given itemhandler for the stacks given and returns the list that is contained in the itemhandlerstatic intgetCountFromBuilding(@NotNull IBuilding provider, @NotNull ItemStorage stack) Count the number of items a building has.static intgetCountFromBuilding(@NotNull IBuilding provider, @NotNull List<ItemStorage> stacks) Count the number of items of different types a building has.static intgetCountFromBuilding(@NotNull IBuilding provider, @NotNull Predicate<net.minecraft.world.item.ItemStack> predicate) Count the number of items a building has.static intgetCountFromBuildingWithLimit(@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 intgetDurabilityInProvider(@NotNull IItemHandlerCapProvider provider, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate) Returns the sum of the durability of occurrences in theICapabilityProvider.static net.minecraft.world.item.ItemStackgetFirstMatch(List<net.minecraft.world.item.ItemStack> stacks, Predicate<net.minecraft.world.item.ItemStack> stackPredicate) Gets the first matching itemstack from a liststatic intgetFirstOpenSlotFromItemHandler(@Nullable net.neoforged.neoforge.items.IItemHandler itemHandler) Returns the first open slot in theIItemHandler.static intgetFirstOpenSlotFromProvider(@NotNull IItemHandlerCapProvider provider) Returns the first open slot in theICapabilityProvider.static intgetFirstOpenSlotFromProviderForSide(@NotNull IItemHandlerCapProvider provider, @Nullable net.minecraft.core.Direction facing) Returns the first open slot in theICapabilityProvider, for a givenDirection.static intgetFirstSlotOfItemHandlerContainingEquipment(@NotNull net.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull EquipmentTypeEntry equipmentType, int minimalLevel, int maximumLevel) Returns a slot number if anIItemHandlercontains given equipment type.static @NotNull List<net.minecraft.world.item.ItemStack> getInventoryAsListFromProviderForSide(@NotNull IItemHandlerCapProvider provider, @Nullable net.minecraft.core.Direction facing) Returns anIItemHandleras list of item stacks.static intgetItemCountInItemHandler(@Nullable net.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate) Returns the amount of occurrences in theIItemHandler.static intgetItemCountInItemHandler(@Nullable net.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull net.minecraft.world.item.Item targetItem) Returns the amount of occurrences in theIItemHandler.static intgetItemCountInItemHandler(@Nullable net.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull net.minecraft.world.level.block.Block block) Returns the amount of occurrences in theIItemHandler.static intgetItemCountInItemHandlers(@Nullable Collection<net.neoforged.neoforge.items.IItemHandler> itemHandlers, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackPredicate) static intgetItemCountInProvider(@NotNull IItemHandlerCapProvider provider, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate) Returns the amount of occurrences in theICapabilityProvider.static intgetItemCountInProvider(@NotNull IItemHandlerCapProvider provider, @NotNull net.minecraft.world.item.Item targetItem) Returns the amount of occurrences in theICapabilityProvider.static intgetItemCountInProvider(@NotNull IItemHandlerCapProvider provider, @NotNull net.minecraft.world.level.block.Block block) Returns the amount of occurrences in theICapabilityProvider.static intgetItemCountInProviderForSide(@NotNull IItemHandlerCapProvider provider, @Nullable net.minecraft.core.Direction facing, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate) Returns the amount of occurrences in theICapabilityProviderfor a givenDirection.static intgetItemCountInProviderForSide(@NotNull IItemHandlerCapProvider provider, @Nullable net.minecraft.core.Direction facing, @NotNull net.minecraft.world.item.Item targetItem) Returns the amount of occurrences in theICapabilityProviderfor a givenDirection.static intgetItemCountInProviderForSide(@NotNull IItemHandlerCapProvider provider, @Nullable net.minecraft.core.Direction facing, @NotNull net.minecraft.world.level.block.Block block) Returns the amount of occurrences in theICapabilityProviderfor a givenDirection.static intgetItemCountInStackLick(@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.ItemgetItemFromBlock(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.neoforged.neoforge.items.IItemHandler itemHandler) Returns anIItemHandleras list of item stacks.static @NotNull Set<net.neoforged.neoforge.items.IItemHandler> getItemHandlersFromProvider(@NotNull IItemHandlerCapProvider provider) Method to get all the IItemHandlers from a given Provider.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.ItemStackgetOrCreateItemAndPutToHotbarAndSelectOrDrop(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 IItemHandlerCapProvider provider) Returns anICapabilityProvideras list of item stacks.static inthasBuildingEnoughElseCount(@NotNull ICommonBuilding provider, @NotNull ItemStorage stack, int count) Check if a building has more than a count in stack.static inthasBuildingEnoughElseCount(@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 booleanhasEnoughInProvider(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 booleanhasItemHandlerEquipmentWithLevel(@NotNull net.neoforged.neoforge.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 booleanhasItemInItemHandler(@Nullable net.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate) Checks if a player has an item in theIItemHandler.static booleanhasItemInItemHandler(@Nullable net.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull net.minecraft.world.item.Item item) Checks if a player has an item in theIItemHandler.static booleanhasItemInItemHandler(@Nullable net.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull net.minecraft.world.level.block.Block block) Checks if a player has a block in theIItemHandler.static booleanhasItemInProvider(@NotNull IItemHandlerCapProvider Provider, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate) Checks if a player has an item in theICapabilityProvider.static booleanhasItemInProvider(@NotNull IItemHandlerCapProvider Provider, @NotNull net.minecraft.world.item.Item item) Checks if a player has an item in theICapabilityProvider.static booleanhasItemInProvider(@NotNull IItemHandlerCapProvider Provider, @NotNull net.minecraft.world.level.block.Block block) Checks if a player has a block in theICapabilityProvider.static booleanhasItemInProviderForSide(@NotNull IItemHandlerCapProvider provider, @Nullable net.minecraft.core.Direction facing, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate) Checks if a player has an item in theICapabilityProvider, for a givenDirection, Predicate)} > 0;static booleanhasItemInProviderForSide(@NotNull IItemHandlerCapProvider provider, @Nullable net.minecraft.core.Direction facing, @NotNull net.minecraft.world.item.Item item) Checks if a player has an item in theICapabilityProvider, for a givenDirection.static booleanhasItemInProviderForSide(@NotNull IItemHandlerCapProvider provider, @Nullable net.minecraft.core.Direction facing, @NotNull net.minecraft.world.level.block.Block block) Checks if a player has a block in theICapabilityProvider, for a givenDirection.; 0;static booleanhasProviderIItemHandler(@NotNull IItemHandlerCapProvider provider) Method used to check if aICapabilityProviderhas anyIItemHandlerstatic booleanisBuildingFull(IBuilding ownBuilding) Calculate the number of empty slots in a given building.static booleanisEquipmentInItemHandler(@NotNull net.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull EquipmentTypeEntry equipmentType, int minimalLevel, int maximumLevel) Checks if theIItemHandlercontains the following equipmentType with the given minimal Level.static booleanisItemHandlerFull(@Nullable net.neoforged.neoforge.items.IItemHandler itemHandler) Returns if theIItemHandleris full.static booleanisProviderFull(@NotNull IItemHandlerCapProvider provider) Returns if theICapabilityProvideris full.static booleanisProviderFull(@NotNull IItemHandlerCapProvider provider, @Nullable net.minecraft.core.Direction facing) Returns if theICapabilityProvideris full, for a givenDirection.static booleanisProviderSided(@NotNull IItemHandlerCapProvider provider) Method used to check if this provider is sided.static net.minecraft.world.item.ItemStackmergeItemStackIntoNextBestSlotInItemHandlers(net.minecraft.world.item.ItemStack stack, @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to merge the ItemStacks from the given sourceIItemHandlerto the given targetIItemHandler.static voidmergeItemStackIntoNextBestSlotInItemHandlers(@NotNull net.neoforged.neoforge.items.IItemHandler sourceHandler, int sourceIndex, @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to merge the ItemStacks from the given sourceIItemHandlerto the given targetIItemHandler.static booleanmoveItemStacksWithPossibleSwap(@NotNull net.neoforged.neoforge.items.IItemHandler targetInventory, @NotNull Collection<net.neoforged.neoforge.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 longopenSlotCount(@Nullable net.neoforged.neoforge.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 booleanputItemToHotbarAndSelectOrDrop(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 booleanputItemToHotbarAndSelectOrDropMessage(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 voidreduceBucketAwareStackInItemHandler(net.neoforged.neoforge.items.IItemHandler invWrapper, net.minecraft.world.item.ItemStack itemStack) Search for a certain itemStack in the inventory and decrease it by 1.static voidreduceBucketAwareStackInItemHandler(net.neoforged.neoforge.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 ItemStoragereduceBuildingThenPlayerInventory(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 voidreduceStackInItemHandler(net.neoforged.neoforge.items.IItemHandler invWrapper, net.minecraft.world.item.ItemStack itemStack) Search for a certain itemStack in the inventory and decrease it by 1.static voidreduceStackInItemHandler(net.neoforged.neoforge.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 voidremoveStackFromItemHandler(net.neoforged.neoforge.items.IItemHandler handler, net.minecraft.world.item.ItemStack input, int count) Force remove a stack with a certain amount from a given Itemhandlerstatic booleanremoveStacksFromItemHandler(net.neoforged.neoforge.items.IItemHandler handler, List<net.minecraft.world.item.ItemStack> input) Remove a list of stacks from a given Itemhandlerstatic booleanremoveStacksFromProvider(IItemHandlerCapProvider provider, List<net.minecraft.world.item.ItemStack> input) Remove a list of stacks from a given providerstatic booleanshrinkItemCountInItemHandler(net.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate) Shrinks a specific stack in an item handler.static voidspawnItemStack(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 booleanswapItemStacksInItemHandlers(@NotNull net.neoforged.neoforge.items.IItemHandler sourceHandler, int sourceIndex, @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler, int targetIndex) Method to swap the ItemStacks from the given sourceIItemHandlerto the given targetIItemHandler.static booleantransferAllItemHandler(net.neoforged.neoforge.items.IItemHandler origin, net.neoforged.neoforge.items.IItemHandler target) Attempt to transfer as much item as possible from origin to target inventorystatic it.unimi.dsi.fastutil.objects.Object2IntMap<net.minecraft.world.item.ItemStack> transferFoodUpToSaturation(IItemHandlerCapProvider source, net.neoforged.neoforge.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 booleantransferItemStackIntoNextBestSlotFromProvider(@NotNull IItemHandlerCapProvider sourceProvider, int sourceIndex, @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to swap the ItemStacks from the given sourceICapabilityProviderto the given targetIItemHandler.static booleantransferItemStackIntoNextBestSlotInItemHandler(@NotNull IBuilding building, ItemStorage storage, int qty, @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to transfer an ItemStacks from the given sourceIBuildingto the given targetIItemHandler.static booleantransferItemStackIntoNextBestSlotInItemHandler(@NotNull IBuilding building, ItemStorage storage, @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to transfer an ItemStacks from the given sourceIBuildingto the given targetIItemHandler.static booleantransferItemStackIntoNextBestSlotInItemHandler(net.minecraft.world.item.ItemStack stack, @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to put a given Itemstack in a given targetIItemHandler.static booleantransferItemStackIntoNextBestSlotInItemHandler(@NotNull net.neoforged.neoforge.items.IItemHandler sourceHandler, int sourceIndex, @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to swap the ItemStacks from the given sourceIItemHandlerto the given targetIItemHandler.static booleantransferItemStackIntoNextBestSlotInItemHandler(@NotNull net.neoforged.neoforge.items.IItemHandler sourceHandler, Predicate<net.minecraft.world.item.ItemStack> predicate, @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to transfer an ItemStacks from the given sourceIItemHandlerto the given targetIItemHandler.static net.minecraft.world.item.ItemStacktransferItemStackIntoNextBestSlotInItemHandlerWithResult(net.minecraft.world.item.ItemStack stack, @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to put a given Itemstack in a given targetIItemHandler.static booleantransferItemStackIntoNextFreeSlotFromItemHandler(@NotNull net.neoforged.neoforge.items.IItemHandler handler, @NotNull Predicate<net.minecraft.world.item.ItemStack> stackPredicate, int count, @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to swap the ItemStacks from the given sourceIItemHandlerto the given targetIItemHandler.static booleantransferItemStackIntoNextFreeSlotFromProvider(@NotNull IItemHandlerCapProvider sourceProvider, int sourceIndex, @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to swap the ItemStacks from the given sourceICapabilityProviderto the given targetIItemHandler.static booleantransferItemStackIntoNextFreeSlotInItemHandler(@NotNull net.neoforged.neoforge.items.IItemHandler sourceHandler, int sourceIndex, @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to swap the ItemStacks from the given sourceIItemHandlerto the given targetIItemHandler.static booleantransferItemStackIntoNextFreeSlotInProvider(@NotNull net.neoforged.neoforge.items.IItemHandler sourceHandler, int sourceIndex, @NotNull IItemHandlerCapProvider targetProvider) Method to swap the ItemStacks from the given sourceIItemHandlerto the given targetICapabilityProvider.static inttransferXInItemHandlerIntoSlotInItemHandler(net.neoforged.neoforge.items.IItemHandler sourceHandler, Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, net.neoforged.neoforge.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 inttransferXOfFirstSlotInItemHandlerWithIntoInItemHandler(net.neoforged.neoforge.items.IItemHandler sourceHandler, Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, net.neoforged.neoforge.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 booleantransferXOfFirstSlotInItemHandlerWithIntoNextFreeSlotInItemHandler(@NotNull net.neoforged.neoforge.items.IItemHandler sourceHandler, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) static inttransferXOfFirstSlotInItemHandlerWithIntoNextFreeSlotInItemHandlerWithResult(@NotNull net.neoforged.neoforge.items.IItemHandler sourceHandler, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) static booleantransferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandler(@NotNull IItemHandlerCapProvider sourceProvider, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) static inttransferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandlerWithResult(@NotNull IItemHandlerCapProvider sourceProvider, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Transfer items over and return the leftover that couldn't be transfered (0 if full amount was transfered).static booleantransferXOfFirstSlotInProviderWithIntoNextFreeSlotInProvider(@NotNull IItemHandlerCapProvider sourceProvider, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull IItemHandlerCapProvider targetProvider) static inttransferXOfFirstSlotInProviderWithIntoNextFreeSlotInProviderWithResult(@NotNull IItemHandlerCapProvider sourceProvider, @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull IItemHandlerCapProvider targetProvider) static booleantransferXOfItemStackIntoNextFreeSlotFromProvider(@NotNull IItemHandlerCapProvider sourceProvider, int sourceIndex, int count, @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to swap the ItemStacks from the given sourceICapabilityProviderto the given targetIItemHandler.static booleantransferXOfItemStackIntoNextFreeSlotInItemHandler(@NotNull net.neoforged.neoforge.items.IItemHandler sourceHandler, int sourceIndex, int count, @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to swap the ItemStacks from the given sourceIItemHandlerto the given targetIItemHandler.static booleantryRemoveStackFromItemHandler(net.neoforged.neoforge.items.IItemHandler handler, net.minecraft.world.item.ItemStack input) Tries to remove a stack with its size from a given Itemhandler.
-
Method Details
-
filterItemHandler
@NotNull public static @NotNull List<net.minecraft.world.item.ItemStack> filterItemHandler(@NotNull @NotNull net.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull @NotNull net.minecraft.world.level.block.Block block) Filters a list of items, matches the stack usingcompareItems(ItemStack, Item), in anIItemHandler. Uses the MetaData andgetItemFromBlock(Block)as parameters for the Predicate.- Parameters:
itemHandler- Inventory to filter inblock- Block to filter- Returns:
- List of item stacks
-
filterItemHandler
@NotNull public static @NotNull List<net.minecraft.world.item.ItemStack> filterItemHandler(@NotNull @NotNull net.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate) Filters a list of items, that match the given predicate, in anIItemHandler.- 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.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull @NotNull net.minecraft.world.item.Item targetItem) Filters a list of items, matches the stack usingcompareItems(ItemStack, Item), with targetItem and itemDamage as parameters, in anIItemHandler.- Parameters:
itemHandler- Inventory to get items fromtargetItem- Item to look for- Returns:
- List of item stacks with the given item in inventory
-
findFirstSlotInItemHandlerWith
public static int findFirstSlotInItemHandlerWith(@NotNull @NotNull net.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull @NotNull net.minecraft.world.level.block.Block block) Returns the index of the first occurrence of the block in theIItemHandler.- Parameters:
itemHandler-IItemHandlerto check.block- Block to find.- Returns:
- Index of the first occurrence.
-
findFirstSlotInItemHandlerWith
public static int findFirstSlotInItemHandlerWith(@NotNull @NotNull net.neoforged.neoforge.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 theIItemHandler.- Parameters:
itemHandler-IItemHandlerto checktargetItem- Item to find.- Returns:
- Index of the first occurrence
-
findFirstSlotInItemHandlerWith
public static int findFirstSlotInItemHandlerWith(@NotNull @NotNull net.neoforged.neoforge.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 theIItemHandler.- Parameters:
itemHandler- ItemHandler to checkitemStackSelectionPredicate- The predicate to match.- Returns:
- Index of the first occurrence
-
shrinkItemCountInItemHandler
public static boolean shrinkItemCountInItemHandler(net.neoforged.neoforge.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.neoforged.neoforge.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 theIItemHandler.- Parameters:
itemHandler- ItemHandler to checkitemStackSelectionPredicate- The predicate to match.- Returns:
- list of Indexes of the occurrences
-
getItemCountInItemHandler
public static int getItemCountInItemHandler(@Nullable @Nullable net.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull @NotNull net.minecraft.world.level.block.Block block) Returns the amount of occurrences in theIItemHandler.- Parameters:
itemHandler-IItemHandlerto 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.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull @NotNull net.minecraft.world.item.Item targetItem) Returns the amount of occurrences in theIItemHandler.- Parameters:
itemHandler-IItemHandlerto 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.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate) Returns the amount of occurrences in theIItemHandler.- Parameters:
itemHandler-IItemHandlerto 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.neoforged.neoforge.items.IItemHandler> itemHandlers, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackPredicate) -
hasItemInItemHandler
public static boolean hasItemInItemHandler(@Nullable @Nullable net.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull @NotNull net.minecraft.world.level.block.Block block) Checks if a player has a block in theIItemHandler. Checked bygetItemCountInItemHandler(IItemHandler, Block)> 0;- Parameters:
itemHandler-IItemHandlerto scanblock- Block to count- Returns:
- True when in
IItemHandler, otherwise false
-
hasItemInItemHandler
public static boolean hasItemInItemHandler(@Nullable @Nullable net.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull @NotNull net.minecraft.world.item.Item item) Checks if a player has an item in theIItemHandler. Checked bygetItemCountInItemHandler(IItemHandler, Item)> 0;- Parameters:
itemHandler-IItemHandlerto scanitem- Item to count- Returns:
- True when in
IItemHandler, otherwise false
-
hasItemInItemHandler
public static boolean hasItemInItemHandler(@Nullable @Nullable net.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate) Checks if a player has an item in theIItemHandler. Checked bygetItemCountInItemHandler(IItemHandler, Predicate)> 0;- Parameters:
itemHandler-IItemHandlerto scanitemStackSelectionPredicate- The predicate to match the ItemStack to.- Returns:
- True when in
IItemHandler, otherwise false
-
isItemHandlerFull
public static boolean isItemHandlerFull(@Nullable @Nullable net.neoforged.neoforge.items.IItemHandler itemHandler) Returns if theIItemHandleris full.- Parameters:
itemHandler- TheIItemHandler.- Returns:
- True if the
IItemHandleris full, false when not.
-
getFirstOpenSlotFromItemHandler
public static int getFirstOpenSlotFromItemHandler(@Nullable @Nullable net.neoforged.neoforge.items.IItemHandler itemHandler) Returns the first open slot in theIItemHandler.- Parameters:
itemHandler- TheIItemHandlerto check.- Returns:
- slot index or -1 if none found.
-
openSlotCount
public static long openSlotCount(@Nullable @Nullable net.neoforged.neoforge.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.neoforged.neoforge.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-IItemHandlerto add itemstack to.itemStack- ItemStack to add.itemStackToKeepPredicate- ThePredicatethat 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.neoforged.neoforge.items.IItemHandler itemHandler) Returns the amount of item stacks in an inventory. This equalsgetItemHandlerAsList(IItemHandler).length();.- Parameters:
itemHandler-IItemHandlerto 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.neoforged.neoforge.items.IItemHandler itemHandler) Returns anIItemHandleras 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 IItemHandlerCapProvider provider, net.minecraft.world.level.block.Block block) Filters a list of items, matches the stack usingcompareItems(ItemStack, Item), in anICapabilityProvider. Uses the MetaData andgetItemFromBlock(Block)as parameters for the Predicate.- Parameters:
provider- Provider to filter inblock- Block to filter- Returns:
- List of item stacks
-
filterProvider
@NotNull public static @NotNull List<net.minecraft.world.item.ItemStack> filterProvider(@NotNull @NotNull IItemHandlerCapProvider provider, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate) Filters a list of items, that match the given predicate, in anICapabilityProvider.- 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.neoforged.neoforge.items.IItemHandler> getItemHandlersFromProvider(@NotNull @NotNull IItemHandlerCapProvider 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 IItemHandlerCapProvider provider, @Nullable @Nullable net.minecraft.world.item.Item targetItem) Filters a list of items, matches the stack usingcompareItems(ItemStack, Item), with targetItem and itemDamage as parameters, in anICapabilityProvider.- Parameters:
provider- Provider to get items fromtargetItem- Item to look for- Returns:
- List of item stacks with the given item in inventory
-
findFirstSlotInProviderWith
public static int findFirstSlotInProviderWith(@NotNull @NotNull IItemHandlerCapProvider provider, net.minecraft.world.level.block.Block block) Returns the index of the first occurrence of the block in theICapabilityProvider.- Parameters:
provider-ICapabilityProviderto check.block- Block to find.- Returns:
- Index of the first occurrence.
-
findFirstSlotInProviderWith
public static int findFirstSlotInProviderWith(@NotNull @NotNull IItemHandlerCapProvider provider, net.minecraft.world.item.Item targetItem) Returns the index of the first occurrence of the Item with the given ItemDamage in theICapabilityProvider.- Parameters:
provider-ICapabilityProviderto checktargetItem- Item to find.- Returns:
- Index of the first occurrence
-
findAllSlotsInProviderWith
public static Map<net.neoforged.neoforge.items.IItemHandler,List<Integer>> findAllSlotsInProviderWith(@NotNull @NotNull IItemHandlerCapProvider 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 theICapabilityProvider.- Parameters:
provider- Provider to checkitemStackSelectionPredicate- The predicate to match.- Returns:
- Index of the first occurrence
-
findFirstSlotInProviderNotEmptyWith
public static int findFirstSlotInProviderNotEmptyWith(@NotNull @NotNull IItemHandlerCapProvider provider, Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate) Returns the index of the first occurrence of an ItemStack that matches the given predicate in theICapabilityProvider.- Parameters:
provider- Provider to checkitemStackSelectionPredicate- The predicate to match.- Returns:
- Index of the first occurrence
-
findFirstSlotInProviderNotEmptyWith
public static int findFirstSlotInProviderNotEmptyWith(@NotNull @NotNull IItemHandlerCapProvider 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 theICapabilityProvider.- Parameters:
provider- Provider to checkitemStackSelectionPredicate- The list of predicates to match.- Returns:
- Index of the first occurrence
-
findFirstSlotInItemHandlerNotEmptyWith
public static int findFirstSlotInItemHandlerNotEmptyWith(@NotNull @NotNull net.neoforged.neoforge.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 theIItemHandler. Also applies the not empty check.- Parameters:
itemHandler- ItemHandler to checkitemStackSelectionPredicate- The predicate to match.- Returns:
- Index of the first occurrence
-
getItemCountInProvider
public static int getItemCountInProvider(@NotNull @NotNull IItemHandlerCapProvider provider, @NotNull @NotNull net.minecraft.world.level.block.Block block) Returns the amount of occurrences in theICapabilityProvider.- Parameters:
provider-ICapabilityProviderto 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 IItemHandlerCapProvider provider, @NotNull @NotNull net.minecraft.world.item.Item targetItem) Returns the amount of occurrences in theICapabilityProvider.- Parameters:
provider-ICapabilityProviderto 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 IItemHandlerCapProvider provider, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate) Returns the amount of occurrences in theICapabilityProvider.- Parameters:
provider-ICapabilityProviderto 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 IItemHandlerCapProvider provider, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate) Returns the sum of the durability of occurrences in theICapabilityProvider.- Parameters:
provider-ICapabilityProviderto 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
Calculate the number of empty slots in a given building.- Parameters:
ownBuilding- the building to check.- Returns:
- the number of empty slots.
-
isBuildingFull
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 IItemHandlerCapProvider Provider, @NotNull @NotNull net.minecraft.world.level.block.Block block) Checks if a player has a block in theICapabilityProvider.- Parameters:
Provider-ICapabilityProviderto scanblock- Block to count- Returns:
- True when in
ICapabilityProvider, otherwise false
-
hasItemInProvider
public static boolean hasItemInProvider(@NotNull @NotNull IItemHandlerCapProvider Provider, @NotNull @NotNull net.minecraft.world.item.Item item) Checks if a player has an item in theICapabilityProvider.- Parameters:
Provider-ICapabilityProviderto scanitem- Item to count- Returns:
- True when in
ICapabilityProvider, otherwise false
-
hasItemInProvider
public static boolean hasItemInProvider(@NotNull @NotNull IItemHandlerCapProvider Provider, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate) Checks if a player has an item in theICapabilityProvider.- Parameters:
Provider-ICapabilityProviderto scanitemStackSelectionPredicate- The predicate to match the ItemStack to.- Returns:
- True when in
ICapabilityProvider, otherwise false
-
isProviderFull
Returns if theICapabilityProvideris full.- Parameters:
provider- TheICapabilityProvider.- Returns:
- True if the
ICapabilityProvideris full, false when not.
-
getFirstOpenSlotFromProvider
Returns the first open slot in theICapabilityProvider.- Parameters:
provider- TheICapabilityProviderto check.- Returns:
- slot index or -1 if none found.
-
addItemStackToProvider
public static boolean addItemStackToProvider(@NotNull @NotNull IItemHandlerCapProvider provider, @Nullable @Nullable net.minecraft.world.item.ItemStack itemStack) Add stack to provider.- Parameters:
provider-ICapabilityProviderto add itemstack to.itemStack- ItemStack to add.- Returns:
- True if successful, otherwise false.
-
addItemStackToItemHandler
public static boolean addItemStackToItemHandler(@NotNull @NotNull net.neoforged.neoforge.items.IItemHandler itemHandler, @Nullable @Nullable net.minecraft.world.item.ItemStack itemStack) Add stack to item handler.- Parameters:
itemHandler-IItemHandlerto add itemstack to.itemStack- ItemStack to add.- Returns:
- True if successful, otherwise false.
-
addItemStackToProviderWithResult
public static net.minecraft.world.item.ItemStack addItemStackToProviderWithResult(@NotNull @NotNull IItemHandlerCapProvider provider, @Nullable @Nullable net.minecraft.world.item.ItemStack itemStack) Add stack to provider with result.- Parameters:
provider-ICapabilityProviderto 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.neoforged.neoforge.items.IItemHandler itemHandler, @Nullable @Nullable net.minecraft.world.item.ItemStack itemStack) Add stack to handler with result.- Parameters:
itemHandler-IItemHandlerto 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 IItemHandlerCapProvider provider, @NotNull @NotNull net.minecraft.world.item.ItemStack itemStack, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackToKeepPredicate) Force stack to provider.- Parameters:
provider-ICapabilityProviderto add itemstack to.itemStack- ItemStack to add.itemStackToKeepPredicate- ThePredicatethat determines which ItemStacks to keep in the inventory. Return false to replace.- Returns:
- itemStack which has been replaced.
-
getAmountOfStacksInProvider
Returns the amount of item stacks in an inventory. This equalsinvalid reference
#getProviderAsList(ICapabilityProvider).length();.- Parameters:
provider-ICapabilityProviderto 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 IItemHandlerCapProvider provider) Returns anICapabilityProvideras list of item stacks.- Parameters:
provider- provider to convert.- Returns:
- List of item stacks.
-
hasProviderIItemHandler
Method used to check if aICapabilityProviderhas anyIItemHandler- Parameters:
provider- The provider to check.- Returns:
- True when the provider has any
IItemHandler, false when not.
-
isProviderSided
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 IItemHandlerCapProvider provider, @Nullable @Nullable net.minecraft.core.Direction facing) Returns anIItemHandleras list of item stacks.- Parameters:
provider- TheICapabilityProviderthat holds theIItemHandlerfor the givenDirectionfacing- The facing to get theIItemHandlerfrom. 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 IItemHandlerCapProvider 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 usingcompareItems(ItemStack, Item), in anIItemHandler. Uses the MetaData andgetItemFromBlock(Block)as parameters for the Predicate.- Parameters:
provider- TheICapabilityProviderthat holds theIItemHandlerfor the givenDirectionfacing- The facing to get theIItemHandlerfrom. Can be null for the internal oneblock- Block to filter- Returns:
- List of item stacks
-
filterItemHandlerFromProviderForSide
@NotNull public static @NotNull List<net.minecraft.world.item.ItemStack> filterItemHandlerFromProviderForSide(@NotNull @NotNull IItemHandlerCapProvider 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 usingcompareItems(ItemStack, Item), with targetItem and itemDamage as parameters, in anIItemHandler.- Parameters:
provider- TheICapabilityProviderthat holds theIItemHandlerfor the givenDirectionfacing- The facing to get theIItemHandlerfrom. Can be null for the internal onetargetItem- Item to look foritemDamage- 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 IItemHandlerCapProvider 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 anIItemHandler.- Parameters:
provider- TheICapabilityProviderthat holds theIItemHandlerfor the givenDirectionfacing- The facing to get theIItemHandlerfrom. Can be null for the internal oneitemStackSelectionPredicate- The predicate to match the stack to.- Returns:
- List of item stacks that match the given predicate.
-
findFirstSlotInProviderForSideWith
public static int findFirstSlotInProviderForSideWith(@NotNull @NotNull IItemHandlerCapProvider 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 theICapabilityProviderfor a givenDirection.- Parameters:
provider-ICapabilityProviderto 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 IItemHandlerCapProvider 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 theICapabilityProviderfor a givenDirection.- Parameters:
provider-ICapabilityProviderto checkfacing- The facing to check for.targetItem- Item to find.- Returns:
- Index of the first occurrence
-
findFirstSlotInProviderForSideWith
public static int findFirstSlotInProviderForSideWith(@NotNull @NotNull IItemHandlerCapProvider 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 theICapabilityProviderfor a givenDirection.- Parameters:
provider- Provider to checkfacing- The facing to check for.itemStackSelectionPredicate- The predicate to match.- Returns:
- Index of the first occurrence
-
getItemCountInProviderForSide
public static int getItemCountInProviderForSide(@NotNull @NotNull IItemHandlerCapProvider provider, @Nullable @Nullable net.minecraft.core.Direction facing, @NotNull @NotNull net.minecraft.world.level.block.Block block) Returns the amount of occurrences in theICapabilityProviderfor a givenDirection.- Parameters:
provider-ICapabilityProviderto 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 IItemHandlerCapProvider provider, @Nullable @Nullable net.minecraft.core.Direction facing, @NotNull @NotNull net.minecraft.world.item.Item targetItem) Returns the amount of occurrences in theICapabilityProviderfor a givenDirection.- Parameters:
provider-ICapabilityProviderto 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 IItemHandlerCapProvider provider, @Nullable @Nullable net.minecraft.core.Direction facing, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate) Returns the amount of occurrences in theICapabilityProviderfor a givenDirection.- Parameters:
provider-ICapabilityProviderto 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 IItemHandlerCapProvider 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 theICapabilityProvider, for a givenDirection.; 0;- Parameters:
provider-ICapabilityProviderto scanfacing- The side to check for.block- Block to count- Returns:
- True when in
ICapabilityProvider, otherwise false
-
hasItemInProviderForSide
public static boolean hasItemInProviderForSide(@NotNull @NotNull IItemHandlerCapProvider provider, @Nullable @Nullable net.minecraft.core.Direction facing, @NotNull @NotNull net.minecraft.world.item.Item item) Checks if a player has an item in theICapabilityProvider, for a givenDirection. 0;- Parameters:
provider-ICapabilityProviderto scanfacing- The side to check for.item- Item to count- Returns:
- True when in
ICapabilityProvider, otherwise false
-
hasItemInProviderForSide
public static boolean hasItemInProviderForSide(@NotNull @NotNull IItemHandlerCapProvider 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 theICapabilityProvider, for a givenDirection, Predicate)} > 0;- Parameters:
provider-ICapabilityProviderto scanfacing- 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 IItemHandlerCapProvider provider, @Nullable @Nullable net.minecraft.core.Direction facing) Returns if theICapabilityProvideris full, for a givenDirection.- Parameters:
provider- TheICapabilityProvider.facing- The side to check for.- Returns:
- True if the
ICapabilityProvideris full, false when not.
-
getFirstOpenSlotFromProviderForSide
public static int getFirstOpenSlotFromProviderForSide(@NotNull @NotNull IItemHandlerCapProvider provider, @Nullable @Nullable net.minecraft.core.Direction facing) Returns the first open slot in theICapabilityProvider, for a givenDirection.- Parameters:
provider- TheICapabilityProviderto check.facing- The side to check for.- Returns:
- slot index or -1 if none found.
-
isEquipmentInItemHandler
public static boolean isEquipmentInItemHandler(@NotNull @NotNull net.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull @NotNull EquipmentTypeEntry equipmentType, int minimalLevel, int maximumLevel) Checks if theIItemHandlercontains the following equipmentType with the given minimal Level.- Parameters:
itemHandler- TheIItemHandlerto 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.neoforged.neoforge.items.IItemHandler itemHandler) Clears an entireIItemHandler.- Parameters:
itemHandler-IItemHandlerto clear.
-
getFirstSlotOfItemHandlerContainingEquipment
public static int getFirstSlotOfItemHandlerContainingEquipment(@NotNull @NotNull net.neoforged.neoforge.items.IItemHandler itemHandler, @NotNull @NotNull EquipmentTypeEntry equipmentType, int minimalLevel, int maximumLevel) Returns a slot number if anIItemHandlercontains given equipment type.- Parameters:
itemHandler- theIItemHandlerto 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.neoforged.neoforge.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 inventoryequipmentType- the type of equipment neededrequiredLevel- the minimum equipment levelmaximumLevel- the worker's hut level- Returns:
- true if equipment is acceptable
-
transferItemStackIntoNextFreeSlotInProvider
public static boolean transferItemStackIntoNextFreeSlotInProvider(@NotNull @NotNull net.neoforged.neoforge.items.IItemHandler sourceHandler, int sourceIndex, @NotNull @NotNull IItemHandlerCapProvider targetProvider) Method to swap the ItemStacks from the given sourceIItemHandlerto the given targetICapabilityProvider.- Parameters:
sourceHandler- TheIItemHandlerthat works as Source.sourceIndex- The index of the slot that is being extracted from.targetProvider- TheICapabilityProviderthat works as Target.- Returns:
- True when the swap was successful, false when not.
-
transferItemStackIntoNextFreeSlotInItemHandler
public static boolean transferItemStackIntoNextFreeSlotInItemHandler(@NotNull @NotNull net.neoforged.neoforge.items.IItemHandler sourceHandler, int sourceIndex, @NotNull @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to swap the ItemStacks from the given sourceIItemHandlerto the given targetIItemHandler.- Parameters:
sourceHandler- TheIItemHandlerthat works as Source.sourceIndex- The index of the slot that is being extracted from.targetHandler- TheIItemHandlerthat works as Target.- Returns:
- True when the swap was successful, false when not.
-
transferXOfItemStackIntoNextFreeSlotInItemHandler
public static boolean transferXOfItemStackIntoNextFreeSlotInItemHandler(@NotNull @NotNull net.neoforged.neoforge.items.IItemHandler sourceHandler, int sourceIndex, int count, @NotNull @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to swap the ItemStacks from the given sourceIItemHandlerto the given targetIItemHandler.- Parameters:
sourceHandler- TheIItemHandlerthat works as Source.sourceIndex- The index of the slot that is being extracted from.count- the quantity.targetHandler- TheIItemHandlerthat works as Target.- Returns:
- True when the swap was successful, false when not.
-
transferItemStackIntoNextBestSlotInItemHandler
public static boolean transferItemStackIntoNextBestSlotInItemHandler(@NotNull @NotNull net.neoforged.neoforge.items.IItemHandler sourceHandler, int sourceIndex, @NotNull @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to swap the ItemStacks from the given sourceIItemHandlerto the given targetIItemHandler. Trying to merge existing itemStacks if possible.- Parameters:
sourceHandler- TheIItemHandlerthat works as Source.sourceIndex- The index of the slot that is being extracted from.targetHandler- TheIItemHandlerthat works as Target.- Returns:
- True when the swap was successful, false when not.
-
transferItemStackIntoNextBestSlotInItemHandler
public static boolean transferItemStackIntoNextBestSlotInItemHandler(@NotNull @NotNull net.neoforged.neoforge.items.IItemHandler sourceHandler, Predicate<net.minecraft.world.item.ItemStack> predicate, @NotNull @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to transfer an ItemStacks from the given sourceIItemHandlerto the given targetIItemHandler.- Parameters:
sourceHandler- TheIItemHandlerthat works as Source.predicate- the predicate for the stack.targetHandler- TheIItemHandlerthat 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.neoforged.neoforge.items.IItemHandler targetHandler) Method to transfer an ItemStacks from the given sourceIBuildingto the given targetIItemHandler.- Parameters:
building- TheIBuildingthat works as Source.storage- the ItemStorage.qty- the qty.targetHandler- TheIItemHandlerthat 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.neoforged.neoforge.items.IItemHandler targetHandler) Method to transfer an ItemStacks from the given sourceIBuildingto the given targetIItemHandler.- Parameters:
building- TheIBuildingthat works as Source.storage- the ItemStorage.targetHandler- TheIItemHandlerthat 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.neoforged.neoforge.items.IItemHandler targetHandler) Method to put a given Itemstack in a given targetIItemHandler. Trying to merge existing itemStacks if possible.- Parameters:
stack- the itemStack to transfer.targetHandler- TheIItemHandlerthat 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.neoforged.neoforge.items.IItemHandler targetHandler) Method to put a given Itemstack in a given targetIItemHandler. Trying to merge existing itemStacks if possible.- Parameters:
stack- the itemStack to transfer.targetHandler- TheIItemHandlerthat works as Target.- Returns:
- the rest of the stack.
-
mergeItemStackIntoNextBestSlotInItemHandlers
public static void mergeItemStackIntoNextBestSlotInItemHandlers(@NotNull @NotNull net.neoforged.neoforge.items.IItemHandler sourceHandler, int sourceIndex, @NotNull @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to merge the ItemStacks from the given sourceIItemHandlerto the given targetIItemHandler. Trying to merge itemStacks or returning stack if not possible.- Parameters:
sourceHandler- TheIItemHandlerthat works as Source.sourceIndex- The index of the slot that is being extracted from.targetHandler- TheIItemHandlerthat works as Target.
-
mergeItemStackIntoNextBestSlotInItemHandlers
public static net.minecraft.world.item.ItemStack mergeItemStackIntoNextBestSlotInItemHandlers(net.minecraft.world.item.ItemStack stack, @NotNull @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to merge the ItemStacks from the given sourceIItemHandlerto the given targetIItemHandler. Trying to merge itemStacks or returning stack if not possible.- Parameters:
stack- the stack to add.targetHandler- TheIItemHandlerthat works as Target.- Returns:
- True when the swap was successful, false when not.
-
transferXOfFirstSlotInProviderWithIntoNextFreeSlotInProvider
public static boolean transferXOfFirstSlotInProviderWithIntoNextFreeSlotInProvider(@NotNull @NotNull IItemHandlerCapProvider sourceProvider, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull @NotNull IItemHandlerCapProvider targetProvider) -
transferXOfFirstSlotInProviderWithIntoNextFreeSlotInProviderWithResult
public static int transferXOfFirstSlotInProviderWithIntoNextFreeSlotInProviderWithResult(@NotNull @NotNull IItemHandlerCapProvider sourceProvider, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull @NotNull IItemHandlerCapProvider targetProvider) -
transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandler
public static boolean transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandler(@NotNull @NotNull IItemHandlerCapProvider sourceProvider, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) -
transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandlerWithResult
public static int transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandlerWithResult(@NotNull @NotNull IItemHandlerCapProvider sourceProvider, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull @NotNull net.neoforged.neoforge.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.neoforged.neoforge.items.IItemHandler sourceHandler, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) -
transferXOfFirstSlotInItemHandlerWithIntoNextFreeSlotInItemHandlerWithResult
public static int transferXOfFirstSlotInItemHandlerWithIntoNextFreeSlotInItemHandlerWithResult(@NotNull @NotNull net.neoforged.neoforge.items.IItemHandler sourceHandler, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, @NotNull @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) -
transferXInItemHandlerIntoSlotInItemHandler
public static int transferXInItemHandlerIntoSlotInItemHandler(net.neoforged.neoforge.items.IItemHandler sourceHandler, Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, net.neoforged.neoforge.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 extracttargetHandler- the target.slot- the slot to put it in.- Returns:
- the count of items actually transferred
-
transferXOfFirstSlotInItemHandlerWithIntoInItemHandler
public static int transferXOfFirstSlotInItemHandlerWithIntoInItemHandler(net.neoforged.neoforge.items.IItemHandler sourceHandler, Predicate<net.minecraft.world.item.ItemStack> itemStackSelectionPredicate, int amount, net.neoforged.neoforge.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 extracttargetHandler- the target.slot- the slot to put it in.- Returns:
- the count of items actually transferred
-
transferItemStackIntoNextFreeSlotFromProvider
public static boolean transferItemStackIntoNextFreeSlotFromProvider(@NotNull @NotNull IItemHandlerCapProvider sourceProvider, int sourceIndex, @NotNull @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to swap the ItemStacks from the given sourceICapabilityProviderto the given targetIItemHandler.- Parameters:
sourceProvider- TheICapabilityProviderthat works as Source.sourceIndex- The index of the slot that is being extracted from.targetHandler- TheIItemHandlerthat works as Target.- Returns:
- True when the swap was successful, false when not.
-
transferItemStackIntoNextFreeSlotFromItemHandler
public static boolean transferItemStackIntoNextFreeSlotFromItemHandler(@NotNull @NotNull net.neoforged.neoforge.items.IItemHandler handler, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> stackPredicate, int count, @NotNull @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to swap the ItemStacks from the given sourceIItemHandlerto the given targetIItemHandler.- Parameters:
handler- TheIItemHandlerthat works as Source.stackPredicate- The type of stack to pickup.count- how much to pick up.targetHandler- TheIItemHandlerthat works as Target.- Returns:
- True when the swap was successful, false when not.
-
transferXOfItemStackIntoNextFreeSlotFromProvider
public static boolean transferXOfItemStackIntoNextFreeSlotFromProvider(@NotNull @NotNull IItemHandlerCapProvider sourceProvider, int sourceIndex, int count, @NotNull @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to swap the ItemStacks from the given sourceICapabilityProviderto the given targetIItemHandler.- Parameters:
sourceProvider- TheICapabilityProviderthat works as Source.sourceIndex- The index of the slot that is being extracted from.count- the quantity.targetHandler- TheIItemHandlerthat works as Target.- Returns:
- True when the swap was successful, false when not.
-
transferItemStackIntoNextBestSlotFromProvider
public static boolean transferItemStackIntoNextBestSlotFromProvider(@NotNull @NotNull IItemHandlerCapProvider sourceProvider, int sourceIndex, @NotNull @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler) Method to swap the ItemStacks from the given sourceICapabilityProviderto the given targetIItemHandler.- Parameters:
sourceProvider- TheICapabilityProviderthat works as Source.sourceIndex- The index of the slot that is being extracted from.targetHandler- TheIItemHandlerthat works as Target.- Returns:
- True when the swap was successful, false when not.
-
swapItemStacksInItemHandlers
public static boolean swapItemStacksInItemHandlers(@NotNull @NotNull net.neoforged.neoforge.items.IItemHandler sourceHandler, int sourceIndex, @NotNull @NotNull net.neoforged.neoforge.items.IItemHandler targetHandler, int targetIndex) Method to swap the ItemStacks from the given sourceIItemHandlerto the given targetIItemHandler.- Parameters:
sourceHandler- TheIItemHandlerthat works as Source.sourceIndex- The index of the slot that is being extracted from.targetHandler- TheIItemHandlerthat 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(IItemHandlerCapProvider 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.neoforged.neoforge.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.neoforged.neoforge.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.neoforged.neoforge.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(IItemHandlerCapProvider 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.neoforged.neoforge.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.neoforged.neoforge.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.neoforged.neoforge.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.neoforged.neoforge.items.IItemHandler origin, net.neoforged.neoforge.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.neoforged.neoforge.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 itemhandlerhandler- 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 IItemHandlerCapProvider provider) Checks if all stacks given in the list are in the capability provider given- Parameters:
stacks- The stacks that should be in the itemhandlerprovider- 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.neoforged.neoforge.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 itemhandlershandlers- 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.neoforged.neoforge.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 forhandler- 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.neoforged.neoforge.items.IItemHandler targetInventory, @NotNull @NotNull Collection<net.neoforged.neoforge.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.neoforged.neoforge.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.neoforged.neoforge.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.neoforged.neoforge.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.neoforged.neoforge.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.neoforged.neoforge.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.neoforged.neoforge.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(IItemHandlerCapProvider provider, net.neoforged.neoforge.items.IItemHandler... handlers) Sums up all items in the given provider/handlers- Parameters:
provider- inventory providerhandlers- inventory handlers- Returns:
- Map of IdentityItemstorage
-
getAllItemsForProviders
public static Map<ItemStorage,ItemStorage> getAllItemsForProviders(net.neoforged.neoforge.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.neoforged.neoforge.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 storagessecond- Second set of item storagesshowTrace- 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(IItemHandlerCapProvider source, net.neoforged.neoforge.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 fromtarget- to insert intems intorequiredSaturation- required saturation valuefoodPredicate- 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 invplayer- 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 invplayer- 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. ElseputItemToHotbarAndSelectOrDrop(net.minecraft.world.item.ItemStack, net.minecraft.world.entity.player.Player)is called with itemstack created from given factory.- Parameters:
item- item to search forplayer- player inventory to check and useitemStackFactory- factory for new item if not foundmessageOnDrop- 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
-
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.
-