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.
|
Modifier and Type | Field and Description |
---|---|
protected int |
capacity |
protected ItemStack |
container |
static java.lang.String |
FLUID_NBT_KEY |
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,
boolean doDrain)
Drains fluid out of internal tanks, distribution is left entirely to the IFluidHandler.
|
FluidStack |
drain(int maxDrain,
boolean doDrain)
Drains fluid out of internal tanks, distribution is left entirely to the IFluidHandler.
|
int |
fill(FluidStack resource,
boolean doFill)
Fills fluid into internal tanks, distribution is left entirely to the IFluidHandler.
|
<T> T |
getCapability(Capability<T> capability,
EnumFacing facing)
Retrieves the handler for the capability requested on the specific side.
|
ItemStack |
getContainer()
Get the container currently acted on by this fluid handler.
|
FluidStack |
getFluid() |
IFluidTankProperties[] |
getTankProperties()
Returns an array of objects which represent the internal tanks.
|
boolean |
hasCapability(Capability<?> capability,
EnumFacing facing)
Determines if this object has support for the capability in question on the specific side.
|
protected void |
setContainerToEmpty()
Override this method for special handling.
|
protected void |
setFluid(FluidStack fluid) |
public static final java.lang.String FLUID_NBT_KEY
@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()
IFluidHandlerItem
getContainer
in interface IFluidHandlerItem
@Nullable public FluidStack getFluid()
protected void setFluid(FluidStack fluid)
public IFluidTankProperties[] getTankProperties()
IFluidHandler
getTankProperties
in interface IFluidHandler
public int fill(FluidStack resource, boolean doFill)
IFluidHandler
fill
in interface IFluidHandler
resource
- FluidStack representing the Fluid and maximum amount of fluid to be filled.doFill
- If false, fill will only be simulated.public FluidStack drain(FluidStack resource, boolean doDrain)
IFluidHandler
drain
in interface IFluidHandler
resource
- FluidStack representing the Fluid and maximum amount of fluid to be drained.doDrain
- If false, drain will only be simulated.public FluidStack drain(int maxDrain, boolean doDrain)
IFluidHandler
drain
in interface IFluidHandler
maxDrain
- Maximum amount of fluid to drain.doDrain
- If false, drain will only be simulated.public boolean canFillFluidType(FluidStack fluid)
public boolean canDrainFluidType(FluidStack fluid)
protected void setContainerToEmpty()
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing)
ICapabilityProvider
hasCapability
in interface ICapabilityProvider
capability
- The capability to checkfacing
- The Side to check from:
CAN BE NULL. Null is defined to represent 'internal' or 'self'@Nullable public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing)
ICapabilityProvider
getCapability
in interface ICapabilityProvider
capability
- The capability to checkfacing
- The Side to check from:
CAN BE NULL. Null is defined to represent 'internal' or 'self'ICapabilityProvider.hasCapability(Capability, EnumFacing)
would return false.