public class FluidHandlerItemStack extends java.lang.Object implements IFluidHandlerItem, ICapabilityProvider
FluidHandlerItemStackSimple
Additional examples are provided to enable consumable fluid containers (see FluidHandlerItemStack.Consumable),
fluid containers with different empty and full items (see FluidHandlerItemStack.SwapEmpty,| Modifier and Type | Class and Description |
|---|---|
static class |
FluidHandlerItemStack.Consumable
Destroys the container item when it's emptied.
|
static class |
FluidHandlerItemStack.SwapEmpty
Swaps the container item for a different one when it's emptied.
|
IFluidHandler.FluidAction| Modifier and Type | Field and Description |
|---|---|
protected int |
capacity |
protected ItemStack |
container |
static java.lang.String |
FLUID_NBT_KEY |
private LazyOptional<IFluidHandlerItem> |
holder |
| Constructor and Description |
|---|
FluidHandlerItemStack(ItemStack container,
int capacity) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
canDrainFluidType(FluidStack fluid) |
boolean |
canFillFluidType(FluidStack fluid) |
FluidStack |
drain(FluidStack resource,
IFluidHandler.FluidAction action)
Drains fluid out of internal tanks, distribution is left entirely to the IFluidHandler.
|
FluidStack |
drain(int maxDrain,
IFluidHandler.FluidAction action)
Drains fluid out of internal tanks, distribution is left entirely to the IFluidHandler.
|
int |
fill(FluidStack resource,
IFluidHandler.FluidAction doFill)
Fills fluid into internal tanks, distribution is left entirely to the IFluidHandler.
|
<T> LazyOptional<T> |
getCapability(Capability<T> capability,
Direction facing)
Retrieves the Optional handler for the capability requested on the specific side.
|
ItemStack |
getContainer()
Get the container currently acted on by this fluid handler.
|
FluidStack |
getFluid() |
FluidStack |
getFluidInTank(int tank)
Returns the FluidStack in a given tank.
|
int |
getTankCapacity(int tank)
Retrieves the maximum fluid amount for a given tank.
|
int |
getTanks()
Returns the number of fluid storage units ("tanks") available
|
boolean |
isFluidValid(int tank,
FluidStack stack)
This function is a way to determine which fluids can exist inside a given handler.
|
protected void |
setContainerToEmpty()
Override this method for special handling.
|
protected void |
setFluid(FluidStack fluid) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetCapabilitypublic static final java.lang.String FLUID_NBT_KEY
private final LazyOptional<IFluidHandlerItem> holder
@Nonnull protected ItemStack container
protected int capacity
public FluidHandlerItemStack(@Nonnull
ItemStack container,
int capacity)
container - The container itemStack, data is stored on it directly as NBT.capacity - The maximum capacity of this fluid tank.@Nonnull public ItemStack getContainer()
IFluidHandlerItemgetContainer in interface IFluidHandlerItem@Nonnull public FluidStack getFluid()
protected void setFluid(FluidStack fluid)
public int getTanks()
IFluidHandlergetTanks in interface IFluidHandler@Nonnull public FluidStack getFluidInTank(int tank)
IFluidHandlerIMPORTANT: This FluidStack MUST NOT be modified. This method is not for altering internal contents. Any implementers who are able to detect modification via this method should throw an exception. It is ENTIRELY reasonable and likely that the stack returned here will be a copy.
SERIOUSLY: DO NOT MODIFY THE RETURNED FLUIDSTACK
getFluidInTank in interface IFluidHandlertank - Tank to query.public int getTankCapacity(int tank)
IFluidHandlergetTankCapacity in interface IFluidHandlertank - Tank to query.public boolean isFluidValid(int tank,
@Nonnull
FluidStack stack)
IFluidHandlerisFluidValid in interface IFluidHandlertank - Tank to query for validitystack - Stack to test with for validitypublic int fill(FluidStack resource, IFluidHandler.FluidAction doFill)
IFluidHandlerfill in interface IFluidHandlerresource - FluidStack representing the Fluid and maximum amount of fluid to be filled.doFill - If SIMULATE, fill will only be simulated.@Nonnull public FluidStack drain(FluidStack resource, IFluidHandler.FluidAction action)
IFluidHandlerdrain in interface IFluidHandlerresource - FluidStack representing the Fluid and maximum amount of fluid to be drained.action - If SIMULATE, drain will only be simulated.@Nonnull public FluidStack drain(int maxDrain, IFluidHandler.FluidAction action)
IFluidHandlerdrain in interface IFluidHandlermaxDrain - Maximum amount of fluid to drain.action - If SIMULATE, drain will only be simulated.public boolean canFillFluidType(FluidStack fluid)
public boolean canDrainFluidType(FluidStack fluid)
protected void setContainerToEmpty()
@Nonnull public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> capability, @Nullable Direction facing)
ICapabilityProvidergetCapability in interface ICapabilityProvider