Package net.neoforged.neoforge.transfer
Class RangedResourceHandler<T extends Resource>
java.lang.Object
net.neoforged.neoforge.transfer.DelegatingResourceHandler<T>
net.neoforged.neoforge.transfer.RangedResourceHandler<T>
- All Implemented Interfaces:
ResourceHandler<T>
A resource handler that wraps a range of indices of another handler.
-
Field Summary
FieldsFields inherited from class net.neoforged.neoforge.transfer.DelegatingResourceHandler
delegate -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedRangedResourceHandler(Supplier<ResourceHandler<T>> delegate, int start, int end) protectedRangedResourceHandler(ResourceHandler<T> delegate, int start, int end) -
Method Summary
Modifier and TypeMethodDescriptionprotected intconvertIndex(int index) Converts the external index to the internal index to use for the delegated-to handler.intextract(T resource, int amount, TransactionContext transaction) Tries to extract up to the given amount of a resource from the handler.intinsert(T resource, int amount, TransactionContext transaction) Inserts up to the given amount of a resource into the handler.static <T extends Resource>
RangedResourceHandler<T> of(Supplier<ResourceHandler<T>> delegate, int start, int end) Creates a wrapper for a range of indices, with the passed supplier being queried every time the handler is accessed.static <T extends Resource>
RangedResourceHandler<T> of(ResourceHandler<T> delegate, int start, int end) Creates a wrapper for a range of indices.static <T extends Resource>
RangedResourceHandler<T> ofSingleIndex(Supplier<ResourceHandler<T>> delegate, int index) Creates a wrapper for a single index, with the passed supplier being queried every time the handler is accessed.static <T extends Resource>
RangedResourceHandler<T> ofSingleIndex(ResourceHandler<T> delegate, int index) Creates a wrapper for a single index.intsize()Returns the current number of indices in this resource handler.Methods inherited from class net.neoforged.neoforge.transfer.DelegatingResourceHandler
extract, getAmountAsLong, getCapacityAsLong, getDelegate, getResource, insert, isValidMethods 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
getAmountAsInt, getCapacityAsInt
-
Field Details
-
start
protected int start -
end
protected int end
-
-
Constructor Details
-
RangedResourceHandler
-
RangedResourceHandler
-
-
Method Details
-
of
public static <T extends Resource> RangedResourceHandler<T> of(ResourceHandler<T> delegate, int start, int end) Creates a wrapper for a range of indices.- Parameters:
start- start of the range of indices, inclusiveend- end of the range of indices, exclusive
-
of
public static <T extends Resource> RangedResourceHandler<T> of(Supplier<ResourceHandler<T>> delegate, int start, int end) Creates a wrapper for a range of indices, with the passed supplier being queried every time the handler is accessed.- Parameters:
start- start of the range of indices, inclusiveend- end of the range of indices, exclusive
-
ofSingleIndex
public static <T extends Resource> RangedResourceHandler<T> ofSingleIndex(ResourceHandler<T> delegate, int index) Creates a wrapper for a single index. -
ofSingleIndex
public static <T extends Resource> RangedResourceHandler<T> ofSingleIndex(Supplier<ResourceHandler<T>> delegate, int index) Creates a wrapper for a single index, with the passed supplier being queried every time the handler is accessed. -
size
public int size()Description copied from interface:ResourceHandlerReturns the current number of indices in this resource handler.This size provides a bound on the valid indices for this handler, see the documentation of
ResourceHandler.- Specified by:
sizein interfaceResourceHandler<T extends Resource>- Overrides:
sizein classDelegatingResourceHandler<T extends Resource>- Returns:
- The size of the resource handler. Can be
0if the handler currently has no indices.
-
convertIndex
protected int convertIndex(int index) Description copied from class:DelegatingResourceHandlerConverts the external index to the internal index to use for the delegated-to handler.- Overrides:
convertIndexin classDelegatingResourceHandler<T extends Resource>
-
extract
Description copied from interface:ResourceHandlerTries to extract up to the given amount of a resource from the handler.This function is preferred to the index-specific overload since it lets the handler decide how to find indices that contain the resource.
This method is expected to be more efficient than callers trying to find indices that contain the resource themselves.
Changes to the handler are made in the context of a transaction.
- Specified by:
extractin interfaceResourceHandler<T extends Resource>- Overrides:
extractin classDelegatingResourceHandler<T extends Resource>- Parameters:
resource- The resource to extract. Must be non-empty.amount- The maximum amount of the resource to extract. Must be non-negative.transaction- The transaction that this operation is part of.- Returns:
- The amount that was extracted. Between
0(inclusive, nothing was extracted) andamount(inclusive, everything was extracted). - See Also:
-
insert
Description copied from interface:ResourceHandlerInserts up to the given amount of a resource into the handler.This function is preferred to the index-specific overload since it lets the handler decide how to distribute the resource.
This method is expected to be more efficient than callers trying to find a suitable index for insertion themselves.
Changes to the handler are made in the context of a transaction.
- Specified by:
insertin interfaceResourceHandler<T extends Resource>- Overrides:
insertin classDelegatingResourceHandler<T extends Resource>- Parameters:
resource- The resource to insert. Must be non-empty.amount- The maximum amount of the resource to insert. Must be non-negative.transaction- The transaction that this operation is part of.- Returns:
- The amount that was inserted. Between
0(inclusive, nothing was inserted) andamount(inclusive, everything was inserted). - See Also:
-