Class EmptyItemFluidStorage
- All Implemented Interfaces:
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, net.minecraft.fluid.Fluid insertableFluid, long insertableAmount) Create a new instance, with a custom mapping function.EmptyItemFluidStorage
(ContainerItemContext context, net.minecraft.item.Item fullItem, net.minecraft.fluid.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
(TransactionContext transaction) Iterate through the contents of this storage, for the scope of the passed transaction.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.fabricmc.fabric.api.transfer.v1.storage.base.InsertionOnlyStorage
extract, supportsExtraction
Methods inherited from interface net.fabricmc.fabric.api.transfer.v1.storage.Storage
exactView, getVersion, iterable, simulateExtract, simulateInsert, supportsInsertion
-
Constructor Details
-
EmptyItemFluidStorage
public EmptyItemFluidStorage(ContainerItemContext context, net.minecraft.item.Item fullItem, net.minecraft.fluid.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, net.minecraft.fluid.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 nonnegative integer not greater than maxAmount: the amount that was inserted.
-
iterator
Description copied from interface:Storage
Iterate through the contents of this storage, for the scope of the passed transaction. Every visitedStorageView
represents a stored resource and an amount. The iterator doesn't guarantee that a single resource only occurs once during an iteration.The returned iterator and any view it returns are only valid for the scope of to the passed transaction. They should not be used once that transaction is closed.
More precisely, as soon as the transaction is closed,
hasNext()
must returnfalse
, and any call tonext()
must throw aNoSuchElementException
.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.- Specified by:
iterator
in interfaceStorage<FluidVariant>
- Parameters:
transaction
- The transaction to which the scope of the returned iterator is tied.- Returns:
- An iterator over the contents of this storage.
-