Class EmptyItemFluidStorage
- All Implemented Interfaces:
Iterable<StorageView<FluidVariant>>
,InsertionOnlyStorage<FluidVariant>
,Storage<FluidVariant>
For example, an empty bucket could be registered to accept exactly 81000 droplets of water and turn into a water bucket, like that:
FluidStorage.combinedItemApiProvider(Items.BUCKET) // Go through the combined API provider to make sure other mods can provide storages for empty buckets.
.register(context -> {// Register a provider for the bucket, returning a new storage every time:
return new EmptyItemFluidStorage(
context, // Pass the context.
Items.WATER_BUCKET, // The result after fluid is inserted.
Fluids.WATER, // Which fluid to accept.
FluidConstants.BUCKET // How much fluid to accept.
);
});
(This is just for illustration purposes! In practice, Fabric API already registers storages for most buckets,
and it is inefficient to have one storage registered per fluid
so Fabric API has a storage that accepts any fluid with a corresponding full bucket).
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.
-
Constructor Summary
ConstructorDescriptionEmptyItemFluidStorage
(ContainerItemContext context, Function<ItemVariant, ItemVariant> emptyToFullMapping, Fluid insertableFluid, long insertableAmount) Create a new instance, with a custom mapping function.EmptyItemFluidStorage
(ContainerItemContext context, Item fullItem, Fluid insertableFluid, long insertableAmount) Create a new instance. -
Method Summary
Modifier and TypeMethodDescriptionlong
insert
(FluidVariant resource, long maxAmount, TransactionContext transaction) Try to insert up to some amount of a resource into this storage.iterator()
Iterate through the contents of this storage.toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface net.fabricmc.fabric.api.transfer.v1.storage.base.InsertionOnlyStorage
extract, supportsExtraction
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface net.fabricmc.fabric.api.transfer.v1.storage.Storage
exactView, getVersion, nonEmptyIterator, nonEmptyViews, simulateExtract, simulateInsert, supportsInsertion
-
Constructor Details
-
EmptyItemFluidStorage
public EmptyItemFluidStorage(ContainerItemContext context, Item fullItem, Fluid insertableFluid, long insertableAmount) Create a new instance.- Parameters:
context
- The current context.fullItem
- The new item after a successful fill operation.insertableFluid
- The fluid that can be inserted. Fluid variant NBT is ignored.insertableAmount
- The amount of fluid that can be inserted.
-
EmptyItemFluidStorage
public EmptyItemFluidStorage(ContainerItemContext context, Function<ItemVariant, ItemVariant> emptyToFullMapping, Fluid insertableFluid, long insertableAmount) Create a new instance, with a custom mapping function. The mapping function allows customizing how the NBT of the full item depends on the NBT of the empty item. The default behavior with the other constructor is to just copy the full NBT.- Parameters:
context
- The current context.emptyToFullMapping
- A function mapping the empty item variant, to the variant that should be used for the full item.insertableFluid
- The fluid that can be inserted. Fluid variant NBT is ignored on insertion.insertableAmount
- The amount of fluid that can be inserted.- See Also:
-
-
Method Details
-
insert
Description copied from interface:Storage
Try to insert up to some amount of a resource into this storage.- Specified by:
insert
in interfaceStorage<FluidVariant>
- 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.
-
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.
- Specified by:
iterator
in interfaceInsertionOnlyStorage<FluidVariant>
- Specified by:
iterator
in interfaceIterable<StorageView<FluidVariant>>
- Specified by:
iterator
in interfaceStorage<FluidVariant>
- Returns:
- An iterator over the contents of this storage. Calling remove on the iterator is not allowed.
-
toString
-