Class CombinedStorage<T,S extends Storage<T>>

java.lang.Object
net.fabricmc.fabric.api.transfer.v1.storage.base.CombinedStorage<T,S>
Type Parameters:
T - The type of the stored resources.
S - The class of every part. ? extends Storage<T> can be used if the parts are of different types. 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.
All Implemented Interfaces:
Iterable<StorageView<T>>, Storage<T>
Direct Known Subclasses:
CombinedSlottedStorage

@Experimental public class CombinedStorage<T,S extends Storage<T>> extends Object implements Storage<T>
A Storage wrapping multiple storages.

The storages passed to the constructor will be iterated in order.

  • Field Details

  • Constructor Details

    • CombinedStorage

      public CombinedStorage(List<S> parts)
  • Method Details

    • supportsInsertion

      public boolean supportsInsertion()
      Description copied from interface: Storage
      Return false if calling Storage.insert(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:
      supportsInsertion in interface Storage<T>
    • insert

      public long insert(T resource, long maxAmount, TransactionContext transaction)
      Description copied from interface: Storage
      Try to insert up to some amount of a resource into this storage.
      Specified by:
      insert in interface Storage<T>
      Parameters:
      resource - The resource to insert. May not be blank.
      maxAmount - The maximum amount of resource to insert. 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 inserted.
    • supportsExtraction

      public boolean supportsExtraction()
      Description copied from interface: Storage
      Return false if calling Storage.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 interface Storage<T>
    • extract

      public long extract(T resource, long maxAmount, TransactionContext transaction)
      Description copied from interface: Storage
      Try to extract up to some amount of a resource from this storage.
      Specified by:
      extract in interface Storage<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

      public Iterator<StorageView<T>> iterator()
      Description copied from interface: Storage
      Iterate through the contents of this storage. Every visited StorageView 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) and Storage.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.

      Specified by:
      iterator in interface Iterable<T>
      Specified by:
      iterator in interface Storage<T>
      Returns:
      An iterator over the contents of this storage. Calling remove on the iterator is not allowed.
    • toString

      public String toString()
      Overrides:
      toString in class Object