Class ItemStacksResourceHandler
java.lang.Object
net.neoforged.neoforge.transfer.StacksResourceHandler<ItemStack,ItemResource>
net.neoforged.neoforge.transfer.item.ItemStacksResourceHandler
- All Implemented Interfaces:
ValueIOSerializable,ResourceHandler<ItemResource>
Base implementation of a
ResourceHandler<ItemResource> backed by a list of ItemStacks.
The following methods will typically be overridden:
- (optional)
StacksResourceHandler.isValid(int, T)to limit which resources are allowed in this handler; by default any resource is allowed. - (optional)
getCapacity(int, net.neoforged.neoforge.transfer.item.ItemResource)to specify the capacity of this handler; by default the maximum stack size is used. - (recommended)
StacksResourceHandler.onContentsChanged(int, S)to react to changes in this handler, for example to triggersetChanged().
- See Also:
-
Field Summary
Fields inherited from class net.neoforged.neoforge.transfer.StacksResourceHandler
codec, emptyStack, stacks, VALUE_IO_KEY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ItemStackCreates a copy of a stack, for use as a snapshot.intgetAmountFrom(ItemStack stack) Retrieves the amount from a stack.protected intgetCapacity(int index, ItemResource resource) Return the maximum capacity of this handler for the passed resource.getResourceFrom(ItemStack stack) Retrieves the resource from a stack.protected ItemStackgetStackFrom(ItemResource resource, int amount) Creates a stack from a resource and an amount.booleanmatches(ItemStack stack, ItemResource resource) Checks if the passed resource corresponds to the stack.Methods inherited from class net.neoforged.neoforge.transfer.StacksResourceHandler
copyToList, deserialize, extract, getAmountAsLong, getCapacityAsLong, getResource, insert, isValid, onContentsChanged, serialize, set, sizeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.neoforged.neoforge.transfer.ResourceHandler
extract, getAmountAsInt, getCapacityAsInt, insert
-
Constructor Details
-
ItemStacksResourceHandler
public ItemStacksResourceHandler(int size) -
ItemStacksResourceHandler
-
-
Method Details
-
getResourceFrom
Description copied from class:StacksResourceHandlerRetrieves the resource from a stack. In the case of anItemStackanItemResourcewould be returned for example.- Specified by:
getResourceFromin classStacksResourceHandler<ItemStack,ItemResource>
-
getAmountFrom
Description copied from class:StacksResourceHandlerRetrieves the amount from a stack. In the case of anItemStackthe count would be returned for example.- Specified by:
getAmountFromin classStacksResourceHandler<ItemStack,ItemResource>
-
getStackFrom
Description copied from class:StacksResourceHandlerCreates a stack from a resource and an amount.If the stack would be empty, consider returning
StacksResourceHandler.emptyStackinstead of creating a new empty stack instance.- Specified by:
getStackFromin classStacksResourceHandler<ItemStack,ItemResource>
-
getCapacity
Description copied from class:StacksResourceHandlerReturn the maximum capacity of this handler for the passed resource. If the passed resource is empty, an estimate should be returned.- Specified by:
getCapacityin classStacksResourceHandler<ItemStack,ItemResource> - Returns:
- The maximum capacity of this handler for the passed resource.
-
copyOf
Description copied from class:StacksResourceHandlerCreates a copy of a stack, for use as a snapshot.If using an immutable stack type such as
ResourceStack, it can be returned as is. In the case of a mutable stack type such as an item or fluid stack, a copy should be returned.- Specified by:
copyOfin classStacksResourceHandler<ItemStack,ItemResource>
-
matches
Description copied from class:StacksResourceHandlerChecks if the passed resource corresponds to the stack.- Overrides:
matchesin classStacksResourceHandler<ItemStack,ItemResource> - Parameters:
stack- the stack, usually the current stored valueresource- the resource, usually the received value in insert or extract- Returns:
trueif the stack and resource match;falseotherwise.
-