Class FluidStorage
Storage<FluidVariant>
instances.-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Event
<FluidStorage.CombinedItemApiProvider> Allows multiple API providers to returnStorage<FluidVariant>
implementations for some items.static final ItemApiLookup
<Storage<FluidVariant>, ContainerItemContext> Item access to fluid variant storages.static final BlockApiLookup
<Storage<FluidVariant>, @Nullable Direction> Sided block access to fluid variant storages. -
Method Summary
Modifier and TypeMethodDescriptioncombinedItemApiProvider
(Item item) Get or create and register aFluidStorage.CombinedItemApiProvider
event for the passed item.
-
Field Details
-
SIDED
Sided block access to fluid variant storages. Fluid amounts are always expressed in droplets. TheDirection
parameter may be null, meaning that the full inventory (ignoring side restrictions) should be queried. Refer toBlockApiLookup
for documentation on how to use this field.A simple way to expose fluid variant storages for a block entity hierarchy is to extend
SidedStorageBlockEntity
.When the operations supported by a storage change, that is if the return value of
Storage.supportsInsertion()
orStorage.supportsExtraction()
changes, the storage should notify its neighbors with a block update so that they can refresh their connections if necessary.This may be queried safely both on the logical server and on the logical client threads. On the server thread (i.e. with a server world), all transfer functionality is always supported. On the client thread (i.e. with a client world), contents of queried Storages are unreliable and should not be modified.
-
ITEM
Item access to fluid variant storages. Querying should happen throughContainerItemContext.find(net.fabricmc.fabric.api.lookup.v1.item.ItemApiLookup<A, net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext>)
.Fluid amounts are always expressed in droplets. By default, Fabric API only registers storage support for buckets that have a 1:1 mapping to their fluid, and for water potions.
combinedItemApiProvider(net.minecraft.item.Item)
andGENERAL_COMBINED_PROVIDER
should be used for API provider registration when multiple mods may want to offer a storage for the same item.Base implementations are provided:
EmptyItemFluidStorage
andFullItemFluidStorage
.This may be queried both client-side and server-side. Returned APIs should behave the same regardless of the logical side.
-
GENERAL_COMBINED_PROVIDER
Allows multiple API providers to returnStorage<FluidVariant>
implementations for some items.combinedItemApiProvider(net.minecraft.item.Item)
is per-item while this one is queried for all items, hence the "general" name.Implementation note: This event is invoked both through an API Lookup fallback, and by the
combinedItemApiProvider
events. This means that per-item combined providers registered throughcombinedItemApiProvider
DO NOT prevent these general providers from running, however regular providers registered throughItemApiLookup#register...
that return a non-null API instance DO prevent it.
-
-
Method Details
-
combinedItemApiProvider
Get or create and register aFluidStorage.CombinedItemApiProvider
event for the passed item. Allows multiple API providers to provide aStorage<FluidVariant>
implementation for the same item.When the item is queried for an API through
ITEM
, all the providers registered through the event will be invoked. All non-nullStorage<FluidVariant>
instances returned by the providers will be combined in a single storage, that will be the final result of the query, ornull
if no storage is offered by the event handlers.This is appropriate to use when multiple mods could wish to expose the Fluid API for some items, for example when dealing with items added by the base Minecraft game such as buckets or empty bottles. A typical usage example is a mod adding support for filling empty bottles with a honey fluid: Fabric API already registers a storage for empty bottles to allow filling them with water through the event, and a mod can register an event handler that will attach a second storage allowing empty bottles to be filled with its honey fluid.
- Throws:
IllegalStateException
- If an incompatible provider is already registered for the item.
-