Package net.neoforged.neoforge.transfer
Class ResourceStacksResourceHandler<R extends Resource>
java.lang.Object
net.neoforged.neoforge.transfer.StacksResourceHandler<ResourceStack<R>,R>
net.neoforged.neoforge.transfer.ResourceStacksResourceHandler<R>
- All Implemented Interfaces:
ValueIOSerializable,ResourceHandler<R>
public abstract class ResourceStacksResourceHandler<R extends Resource>
extends StacksResourceHandler<ResourceStack<R>,R>
Base implementation of a
ResourceHandler backed by a list of ResourceStacks.
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. - (required)
StacksResourceHandler.getCapacity(int, T)to specify the capacity of this handler. - (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
ConstructorsConstructorDescriptionResourceStacksResourceHandler(int size, R emptyResource, com.mojang.serialization.Codec<ResourceStack<R>> stackCodec) ResourceStacksResourceHandler(NonNullList<ResourceStack<R>> stacks, R emptyResource, com.mojang.serialization.Codec<ResourceStack<R>> stackCodec) -
Method Summary
Modifier and TypeMethodDescriptionprotected ResourceStack<R> copyOf(ResourceStack<R> stack) Creates a copy of a stack, for use as a snapshot.intgetAmountFrom(ResourceStack<R> stack) Retrieves the amount from a stack.getResourceFrom(ResourceStack<R> stack) Retrieves the resource from a stack.protected ResourceStack<R> getStackFrom(R resource, int amount) Creates a stack from a resource and an amount.booleanmatches(ResourceStack<R> stack, R resource) Checks if the passed resource corresponds to the stack.Methods inherited from class net.neoforged.neoforge.transfer.StacksResourceHandler
copyToList, deserialize, extract, getAmountAsLong, getCapacity, 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
-
ResourceStacksResourceHandler
public ResourceStacksResourceHandler(int size, R emptyResource, com.mojang.serialization.Codec<ResourceStack<R>> stackCodec) -
ResourceStacksResourceHandler
public ResourceStacksResourceHandler(NonNullList<ResourceStack<R>> stacks, R emptyResource, com.mojang.serialization.Codec<ResourceStack<R>> stackCodec)
-
-
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<ResourceStack<R extends Resource>,R extends Resource>
-
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<ResourceStack<R extends Resource>,R extends Resource>
-
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<ResourceStack<R extends Resource>,R extends 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<ResourceStack<R extends Resource>,R extends Resource>
-
matches
Description copied from class:StacksResourceHandlerChecks if the passed resource corresponds to the stack.- Overrides:
matchesin classStacksResourceHandler<ResourceStack<R extends Resource>,R extends Resource> - 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.
-