Class StorageUtil
java.lang.Object
net.fabricmc.fabric.api.transfer.v1.storage.StorageUtil
Deprecated.
Experimental feature, we reserve the right to remove or change it without further notice.
The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
Helper functions to work with
Storage
s.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> int
calculateComparatorOutput(@Nullable Storage<T> storage, @Nullable TransactionContext transaction)
Deprecated.Compute the comparator output for a storage, similar toScreenHandler.calculateComparatorOutput(Inventory)
.static <T> @Nullable ResourceAmount<T>
findExtractableContent(@Nullable Storage<T> storage, @Nullable TransactionContext transaction)
Deprecated.Attempt to find a resource stored in the passed storage that can be extracted, and how much of it can be extracted.static <T> T
findExtractableResource(@Nullable Storage<T> storage, @Nullable TransactionContext transaction)
Deprecated.Attempt to find a resource stored in the passed storage that can be extracted.static <T> T
findStoredResource(@Nullable Storage<T> storage, @Nullable TransactionContext transaction)
Deprecated.Attempt to find a resource stored in the passed storage.static <T> long
move(@Nullable Storage<T> from, @Nullable Storage<T> to, Predicate<T> filter, long maxAmount, @Nullable TransactionContext transaction)
Deprecated.Move resources between two storages, matching the passed filter, and return the amount that was successfully transferred.
-
Constructor Details
-
StorageUtil
public StorageUtil()Deprecated.
-
-
Method Details
-
move
public static <T> long move(@Nullable @Nullable Storage<T> from, @Nullable @Nullable Storage<T> to, Predicate<T> filter, long maxAmount, @Nullable @Nullable TransactionContext transaction)Deprecated.Move resources between two storages, matching the passed filter, and return the amount that was successfully transferred.Here is a usage example with fluid variant storages:
// Source Storage<FluidVariant> source; // Target Storage<FluidVariant> target; // Move up to one bucket in total from source to target, outside of a transaction: long amountMoved = StorageUtil.move(source, target, variant -> true, FluidConstants.BUCKET, null); // Move exactly one bucket in total, only of water: try (Transaction transaction = Transaction.openOuter()) { Predicate<FluidVariant> filter = variant -> variant.isOf(Fluids.WATER); long waterMoved = StorageUtil.move(source, target, filter, FluidConstants.BUCKET, transaction); if (waterMoved == FluidConstants.BUCKET) { // Only commit if exactly one bucket was moved (no less!). transaction.commit(); } }
- Type Parameters:
T
- The type of resources to move.- Parameters:
from
- The source storage. May be null.to
- The target storage. May be null.filter
- The filter for transferred resources. Only resources for which this filter returnstrue
will be transferred. This filter will never be tested with a blank resource, and filters are encouraged to throw an exception if this guarantee is violated.maxAmount
- The maximum amount that will be transferred.transaction
- The transaction this transfer is part of, ornull
if a transaction should be opened just for this transfer.- Returns:
- The total amount of resources that was successfully transferred.
- Throws:
IllegalStateException
- If no transaction is passed and a transaction is already active on the current thread.
-
findStoredResource
@Nullable public static <T> T findStoredResource(@Nullable @Nullable Storage<T> storage, @Nullable @Nullable TransactionContext transaction)Deprecated.Attempt to find a resource stored in the passed storage.- Type Parameters:
T
- The type of the stored resources.- Parameters:
storage
- The storage to inspect, may be null.transaction
- The current transaction, ornull
if a transaction should be opened for this query.- Returns:
- A non-blank resource stored in the storage, or
null
if none could be found.
-
findExtractableResource
@Nullable public static <T> T findExtractableResource(@Nullable @Nullable Storage<T> storage, @Nullable @Nullable TransactionContext transaction)Deprecated.Attempt to find a resource stored in the passed storage that can be extracted.- Type Parameters:
T
- The type of the stored resources.- Parameters:
storage
- The storage to inspect, may be null.transaction
- The current transaction, ornull
if a transaction should be opened for this query.- Returns:
- A non-blank resource stored in the storage that can be extracted, or
null
if none could be found.
-
findExtractableContent
@Nullable public static <T> @Nullable ResourceAmount<T> findExtractableContent(@Nullable @Nullable Storage<T> storage, @Nullable @Nullable TransactionContext transaction)Deprecated.Attempt to find a resource stored in the passed storage that can be extracted, and how much of it can be extracted.- Type Parameters:
T
- The type of the stored resources.- Parameters:
storage
- The storage to inspect, may be null.transaction
- The current transaction, ornull
if a transaction should be opened for this query.- Returns:
- A non-blank resource stored in the storage that can be extracted and the strictly positive amount of it that can be extracted,
or
null
if none could be found.
-
calculateComparatorOutput
public static <T> int calculateComparatorOutput(@Nullable @Nullable Storage<T> storage, @Nullable @Nullable TransactionContext transaction)Deprecated.Compute the comparator output for a storage, similar toScreenHandler.calculateComparatorOutput(Inventory)
.- Type Parameters:
T
- The type of the stored resources.- Parameters:
storage
- The storage for which the comparator level should be computed.transaction
- The current transaction, ornull
if a transaction should be opened for this computation.- Returns:
- An integer between 0 and 15 (inclusive): the comparator output for the passed storage.
-