Interface IItemHandler
- All Known Subinterfaces:
IItemHandlerModifiable
- All Known Implementing Classes:
CombinedInvWrapper,ComponentItemHandler,EmptyItemHandler,EntityArmorInvWrapper,EntityEquipmentInvWrapper,EntityHandsInvWrapper,ForwardingItemHandler,InvWrapper,ItemResourceHandlerAdapter,ItemStackHandler,PlayerArmorInvWrapper,PlayerInvWrapper,PlayerMainInvWrapper,PlayerOffhandInvWrapper,RangedWrapper,SidedInvWrapper
-
Method Summary
Modifier and TypeMethodDescriptionextractItem(int slot, int amount, boolean simulate) Deprecated, for removal: This API element is subject to removal in a future version.intgetSlotLimit(int slot) Deprecated, for removal: This API element is subject to removal in a future version.UseResourceHandler.getCapacityAsInt(int, T)instead, passingItemResource.EMPTYas the resource to retrieve a general slot limit.intgetSlots()Deprecated, for removal: This API element is subject to removal in a future version.UseResourceHandler.size()instead.getStackInSlot(int slot) Deprecated, for removal: This API element is subject to removal in a future version.UseResourceHandler.getResource(int)andResourceHandler.getAmountAsInt(int)instead.insertItem(int slot, ItemStack stack, boolean simulate) Deprecated, for removal: This API element is subject to removal in a future version.booleanisItemValid(int slot, ItemStack stack) Deprecated, for removal: This API element is subject to removal in a future version.UseResourceHandler.isValid(int, T)instead, however note that it doesn't make the same strong guarantees regarding how long a resource is valid.static IItemHandlerof(ResourceHandler<ItemResource> handler) Deprecated, for removal: This API element is subject to removal in a future version.Creates a wrapper around an itemResourceHandler, to present it as a legacyIItemHandler.
-
Method Details
-
of
Deprecated, for removal: This API element is subject to removal in a future version.Creates a wrapper around an itemResourceHandler, to present it as a legacyIItemHandler.This class is intended to make migration easier for code that expects an
IItemHandler. -
getSlots
Deprecated, for removal: This API element is subject to removal in a future version.UseResourceHandler.size()instead.Returns the number of slots available- Returns:
- The number of slots available
-
getStackInSlot
Deprecated, for removal: This API element is subject to removal in a future version.UseResourceHandler.getResource(int)andResourceHandler.getAmountAsInt(int)instead. Alternatively use theItemUtil.getStack(net.neoforged.neoforge.transfer.ResourceHandler<net.neoforged.neoforge.transfer.item.ItemResource>, int)helper.Returns the ItemStack in a given slot. The result's stack size may be greater than the itemstack's max size. If the result is empty, then the slot is empty.IMPORTANT: This ItemStack MUST NOT be modified. This method is not for altering an inventory's contents. Any implementers who are able to detect modification through this method should throw an exception.
SERIOUSLY: DO NOT MODIFY THE RETURNED ITEMSTACK
- Parameters:
slot- Slot to query- Returns:
- ItemStack in given slot. Empty Itemstack if the slot is empty.
-
insertItem
@Deprecated(since="1.21.9", forRemoval=true) ItemStack insertItem(int slot, ItemStack stack, boolean simulate) Deprecated, for removal: This API element is subject to removal in a future version.UseResourceHandler.insert(int, T, int, net.neoforged.neoforge.transfer.transaction.TransactionContext)instead. Note thatResourceHandler.insert(int, T, int, net.neoforged.neoforge.transfer.transaction.TransactionContext)returns how much was inserted, unlike this method which returns the leftover (i.e. how much was not inserted). Alternatively use theItemUtil.insertItemReturnRemaining(net.neoforged.neoforge.transfer.ResourceHandler<net.neoforged.neoforge.transfer.item.ItemResource>, net.minecraft.world.item.ItemStack, boolean, net.neoforged.neoforge.transfer.transaction.TransactionContext)helper.Inserts an ItemStack into the given slot and return the remainder. The ItemStack should not be modified in this function!
Note: This behaviour is subtly different fromIFluidHandler.fill(FluidStack, IFluidHandler.FluidAction)- Parameters:
slot- Slot to insert into.stack- ItemStack to insert. This must not be modified by the item handler.simulate- If true, the insertion is only simulated- Returns:
- The remaining ItemStack that was not inserted (if the entire stack is accepted, then return an empty ItemStack). May be the same as the input ItemStack if unchanged, otherwise a new ItemStack. The returned ItemStack can be safely modified after.
-
extractItem
@Deprecated(since="1.21.9", forRemoval=true) ItemStack extractItem(int slot, int amount, boolean simulate) Deprecated, for removal: This API element is subject to removal in a future version.Extracts an ItemStack from the given slot.The returned value must be empty if nothing is extracted, otherwise its stack size must be less than or equal to
amountandItemStack.getMaxStackSize().- Parameters:
slot- Slot to extract from.amount- Amount to extract (may be greater than the current stack's max limit)simulate- If true, the extraction is only simulated- Returns:
- ItemStack extracted from the slot, must be empty if nothing can be extracted. The returned ItemStack can be safely modified after, so item handlers should return a new or copied stack.
-
getSlotLimit
Deprecated, for removal: This API element is subject to removal in a future version.UseResourceHandler.getCapacityAsInt(int, T)instead, passingItemResource.EMPTYas the resource to retrieve a general slot limit.Retrieves the maximum stack size allowed to exist in the given slot.- Parameters:
slot- Slot to query.- Returns:
- The maximum stack size allowed in the slot.
-
isItemValid
Deprecated, for removal: This API element is subject to removal in a future version.UseResourceHandler.isValid(int, T)instead, however note that it doesn't make the same strong guarantees regarding how long a resource is valid. In other words: the result ofisValidmight change.This function re-implements the vanilla function
Container.canPlaceItem(int, ItemStack). It should be used instead of simulated insertions in cases where the contents and state of the inventory are irrelevant, mainly for the purpose of automation and logic (for instance, testing if a minecart can wait to deposit its items into a full inventory, or if the items in the minecart can never be placed into the inventory and should move on).- isItemValid is false when insertion of the item is never valid.
- When isItemValid is true, no assumptions can be made and insertion must be simulated case-by-case.
- The actual items in the inventory, its fullness, or any other state are not considered by isItemValid.
- Parameters:
slot- Slot to query for validitystack- Stack to test with for validity- Returns:
- true if the slot can insert the ItemStack, not considering the current state of the inventory. false if the slot can never insert the ItemStack in any situation.
-
ResourceHandlerwith anItemResourceinstead. Code that is written againstIItemHandlerbut receives aResourceHandler<ItemResource>can temporarily useof(net.neoforged.neoforge.transfer.ResourceHandler<net.neoforged.neoforge.transfer.item.ItemResource>)to ease migration.