Class EmptyItemFluidStorage

java.lang.Object
net.fabricmc.fabric.api.transfer.v1.fluid.base.EmptyItemFluidStorage
All Implemented Interfaces:
Iterable<StorageView<FluidVariant>>, InsertionOnlyStorage<FluidVariant>, Storage<FluidVariant>

@Experimental public final class EmptyItemFluidStorage extends Object implements InsertionOnlyStorage<FluidVariant>
Base implementation of a fluid storage for an empty item. The empty item can be filled with an exact amount of some fluid to yield a full item instead. The default behavior is to copy the NBT from the empty item to the full item, however there is a second constructor that allows customizing the mapping.

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 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