Interface InsertionOnlyStorage<T>
- All Superinterfaces:
Iterable<StorageView<T>>
,Storage<T>
- All Known Implementing Classes:
EmptyItemFluidStorage
Storage
that supports insertion, and not extraction. By default, it doesn't have any storage view either.
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.
-
Method Summary
Modifier and TypeMethodDescriptiondefault long
extract
(T resource, long maxAmount, TransactionContext transaction) Try to extract up to some amount of a resource from this storage.default Iterator<StorageView<T>>
iterator()
Iterate through the contents of this storage.default boolean
Return false if callingStorage.extract(T, long, net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext)
will absolutely always return 0, or true otherwise or in doubt.Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface net.fabricmc.fabric.api.transfer.v1.storage.Storage
exactView, getVersion, insert, nonEmptyIterator, nonEmptyViews, simulateExtract, simulateInsert, supportsInsertion
-
Method Details
-
supportsExtraction
default boolean supportsExtraction()Description copied from interface:Storage
Return false if callingStorage.extract(T, long, net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext)
will absolutely always return 0, or true otherwise or in doubt.Note: This function is meant to be used by pipes or other devices that can transfer resources to know if they should interact with this storage at all.
- Specified by:
supportsExtraction
in interfaceStorage<T>
-
extract
Description copied from interface:Storage
Try to extract up to some amount of a resource from this storage.- Specified by:
extract
in interfaceStorage<T>
- Parameters:
resource
- The resource to extract. May not be blank.maxAmount
- The maximum amount of resource to extract. May not be negative.transaction
- The transaction this operation is part of.- Returns:
- A non-negative integer not greater than maxAmount: the amount that was extracted.
-
iterator
Description copied from interface:Storage
Iterate through the contents of this storage. Every visitedStorageView
represents a stored resource and an amount. The iterator doesn't guarantee that a single resource only occurs once during an iteration. Calling remove on the iterator is not allowed.Storage.insert(T, long, net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext)
andStorage.extract(T, long, net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext)
may be called safely during iteration. Extractions should be visible to an open iterator, but insertions are not required to. In particular, inventories with a fixed amount of slots may wish to make insertions visible to iterators, but inventories with a dynamic or very large amount of slots should not do that to ensure timely termination of the iteration.If a modification is made to the storage during iteration, the iterator might become invalid at the end of the outermost transaction. In particular, if multiple storage views are extracted from, the entire iteration should be wrapped in a transaction.
-