Class ItemUtil
java.lang.Object
net.neoforged.neoforge.transfer.item.ItemUtil
Helper functions to work with
ResourceHandlers of ItemResources.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ItemStackgetStack(ResourceHandler<ItemResource> handler, int index) Returns a new item stack with the contents of the handler at the given index.static ItemStackinsertItemReturnRemaining(ResourceHandler<ItemResource> handler, int index, ItemStack stack, boolean simulate, @Nullable TransactionContext transaction) Attempts to insert an item stack into the index of a handler, returning any leftover.static ItemStackinsertItemReturnRemaining(ResourceHandler<ItemResource> handler, ItemStack stack, boolean simulate, @Nullable TransactionContext transaction) Attempts to insert an item stack into a handler, leaving distribution to the handler, and returning any leftover.
-
Constructor Details
-
ItemUtil
private ItemUtil()
-
-
Method Details
-
getStack
Returns a new item stack with the contents of the handler at the given index.The result's stack size may be greater than the max stack size.
-
insertItemReturnRemaining
public static ItemStack insertItemReturnRemaining(ResourceHandler<ItemResource> handler, ItemStack stack, boolean simulate, @Nullable @Nullable TransactionContext transaction) Attempts to insert an item stack into a handler, leaving distribution to the handler, and returning any leftover.- Parameters:
handler- handler to insert intostack- the stack to insert, will not be modified by this functionsimulate-trueto simulate the result of the insert but leave the handler unmodified,falseto modify the handlertransaction- The transaction that this operation is part of. This method will always use a nested transaction that will be rolled back.nullcan be passed to conveniently have this method open its own root transaction.- Returns:
- the leftover: the stack of items that could not be inserted
-
insertItemReturnRemaining
public static ItemStack insertItemReturnRemaining(ResourceHandler<ItemResource> handler, int index, ItemStack stack, boolean simulate, @Nullable @Nullable TransactionContext transaction) Attempts to insert an item stack into the index of a handler, returning any leftover.- Parameters:
handler- handler to insert intoindex- index to insert intostack- the stack to insert, will not be modified by this functionsimulate-trueto simulate the result of the insert but leave the handler unmodified,falseto modify the handlertransaction- The transaction that this operation is part of. This method will always use a nested transaction that will be rolled back.nullcan be passed to conveniently have this method open its own root transaction.- Returns:
- the leftover: the stack of items that could not be inserted
-