Class FullItemFluidStorage
java.lang.Object
net.fabricmc.fabric.api.transfer.v1.fluid.base.FullItemFluidStorage
- All Implemented Interfaces:
ExtractionOnlyStorage<FluidVariant>
,SingleSlotStorage<FluidVariant>
,Storage<FluidVariant>
,StorageView<FluidVariant>
@Experimental
public final class FullItemFluidStorage
extends Object
implements ExtractionOnlyStorage<FluidVariant>, SingleSlotStorage<FluidVariant>
Base implementation of a fluid storage for a full item.
The full item contains some fixed amount of a fluid variant, which can be extracted entirely to yield an empty item.
The default behavior is to copy the NBT from the full item to the empty item,
however there is a second constructor that allows customizing the mapping.
This is used similarly to EmptyItemFluidStorage
.
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
ConstructorDescriptionFullItemFluidStorage
(ContainerItemContext context, Function<ItemVariant, ItemVariant> fullToEmptyMapping, FluidVariant containedFluid, long containedAmount) Create a new instance, with a custom mapping function.FullItemFluidStorage
(ContainerItemContext context, net.minecraft.item.Item emptyItem, FluidVariant containedFluid, long containedAmount) Create a new instance. -
Method Summary
Modifier and TypeMethodDescriptionlong
extract
(FluidVariant resource, long maxAmount, TransactionContext transaction) Try to extract up to some amount of a resource from this storage.long
long
boolean
Returntrue
if theStorageView.getResource()
contained in this storage view is blank, orfalse
otherwise.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.ExtractionOnlyStorage
insert, supportsInsertion
Methods inherited from interface net.fabricmc.fabric.api.transfer.v1.storage.base.SingleSlotStorage
iterator
Methods inherited from interface net.fabricmc.fabric.api.transfer.v1.storage.Storage
exactView, getVersion, iterable, simulateExtract, simulateInsert, supportsExtraction
-
Constructor Details
-
FullItemFluidStorage
public FullItemFluidStorage(ContainerItemContext context, net.minecraft.item.Item emptyItem, FluidVariant containedFluid, long containedAmount) Create a new instance.- Parameters:
context
- The current context.emptyItem
- The new item after a successful extract operation.containedFluid
- The contained fluid variant.containedAmount
- How much ofcontainedFluid
is contained.
-
FullItemFluidStorage
public FullItemFluidStorage(ContainerItemContext context, Function<ItemVariant, ItemVariant> fullToEmptyMapping, FluidVariant containedFluid, long containedAmount) Create a new instance, with a custom mapping function. The mapping function allows customizing how the NBT of the empty item depends on the NBT of the full item. The default behavior with the other constructor is to just copy the full NBT.- Parameters:
context
- The current context.fullToEmptyMapping
- A function mapping the full item variant, to the variant that should be used for the empty item after a successful extract operation.containedFluid
- The contained fluid variant.containedAmount
- How much ofcontainedFluid
is contained.
-
-
Method Details
-
extract
Description copied from interface:Storage
Try to extract up to some amount of a resource from this storage.- Specified by:
extract
in interfaceStorage<FluidVariant>
- Specified by:
extract
in interfaceStorageView<FluidVariant>
- 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 nonnegative integer not greater than maxAmount: the amount that was extracted.
-
isResourceBlank
public boolean isResourceBlank()Description copied from interface:StorageView
Returntrue
if theStorageView.getResource()
contained in this storage view is blank, orfalse
otherwise.This function is mostly useful when dealing with storages of arbitrary types. For transfer variant storages, this should always be equivalent to
getResource().isBlank()
.- Specified by:
isResourceBlank
in interfaceStorageView<FluidVariant>
-
getResource
- Specified by:
getResource
in interfaceStorageView<FluidVariant>
- Returns:
- The resource stored in this view. May not be blank if
StorageView.isResourceBlank()
isfalse
.
-
getAmount
public long getAmount()- Specified by:
getAmount
in interfaceStorageView<FluidVariant>
- Returns:
- The amount of
StorageView.getResource()
stored in this view.
-
getCapacity
public long getCapacity()- Specified by:
getCapacity
in interfaceStorageView<FluidVariant>
- Returns:
- The total amount of
StorageView.getResource()
that could be stored in this view, or an estimate of the number of resources that could be stored if this view has a blank resource.
-