Class FluidHandlerItemStack
java.lang.Object
net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack
- All Implemented Interfaces:
- ICapabilityProvider,- IFluidHandler,- IFluidHandlerItem
- Direct Known Subclasses:
- FluidHandlerItemStack.Consumable,- FluidHandlerItemStack.SwapEmpty
FluidHandlerItemStack is a template capability provider for ItemStacks.
 Data is stored directly in the vanilla NBT, in the same way as the old ItemFluidContainer.
 This class allows an ItemStack to contain any partial level of fluid up to its capacity, unlike 
FluidHandlerItemStackSimple
 Additional examples are provided to enable consumable fluid containers (see FluidHandlerItemStack.Consumable),
 fluid containers with different empty and full items (see FluidHandlerItemStack.SwapEmpty,- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classDestroys the container item when it's emptied.static classSwaps the container item for a different one when it's emptied.Nested classes/interfaces inherited from interface net.minecraftforge.fluids.capability.IFluidHandlerIFluidHandler.FluidAction
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected intprotected ItemStackstatic Stringprivate LazyOptional<IFluidHandlerItem>
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionbooleancanDrainFluidType(FluidStack fluid)booleancanFillFluidType(FluidStack fluid)drain(int maxDrain, IFluidHandler.FluidAction action)Drains fluid out of internal tanks, distribution is left entirely to the IFluidHandler.drain(FluidStack resource, IFluidHandler.FluidAction action)Drains fluid out of internal tanks, distribution is left entirely to the IFluidHandler.intfill(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.Get the container currently acted on by this fluid handler.getFluid()getFluidInTank(int tank)Returns the FluidStack in a given tank.intgetTankCapacity(int tank)Retrieves the maximum fluid amount for a given tank.intgetTanks()Returns the number of fluid storage units ("tanks") availablebooleanisFluidValid(int tank, FluidStack stack)This function is a way to determine which fluids can exist inside a given handler.protected voidOverride this method for special handling.protected voidsetFluid(FluidStack fluid)Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.minecraftforge.common.capabilities.ICapabilityProvidergetCapability
- 
Field Details- 
FLUID_NBT_KEY- See Also:
- Constant Field Values
 
- 
holder
- 
container
- 
capacityprotected int capacity
 
- 
- 
Constructor Details- 
FluidHandlerItemStack- Parameters:
- container- The container itemStack, data is stored on it directly as NBT.
- capacity- The maximum capacity of this fluid tank.
 
 
- 
- 
Method Details- 
getContainerDescription copied from interface:IFluidHandlerItemGet the container currently acted on by this fluid handler. The ItemStack may be different from its initial state, in the case of fluid containers that have different items for their filled and empty states. May be an empty item if the container was drained and is consumable.- Specified by:
- getContainerin interface- IFluidHandlerItem
 
- 
getFluid
- 
setFluid
- 
getTankspublic int getTanks()Description copied from interface:IFluidHandlerReturns the number of fluid storage units ("tanks") available- Specified by:
- getTanksin interface- IFluidHandler
- Returns:
- The number of tanks available
 
- 
getFluidInTankDescription copied from interface:IFluidHandlerReturns the FluidStack in a given tank.IMPORTANT: 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 - Specified by:
- getFluidInTankin interface- IFluidHandler
- Parameters:
- tank- Tank to query.
- Returns:
- FluidStack in a given tank. FluidStack.EMPTY if the tank is empty.
 
- 
getTankCapacitypublic int getTankCapacity(int tank)Description copied from interface:IFluidHandlerRetrieves the maximum fluid amount for a given tank.- Specified by:
- getTankCapacityin interface- IFluidHandler
- Parameters:
- tank- Tank to query.
- Returns:
- The maximum fluid amount held by the tank.
 
- 
isFluidValidDescription copied from interface:IFluidHandlerThis function is a way to determine which fluids can exist inside a given handler. General purpose tanks will basically always return TRUE for this.- Specified by:
- isFluidValidin interface- IFluidHandler
- Parameters:
- tank- Tank to query for validity
- stack- Stack to test with for validity
- Returns:
- TRUE if the tank can hold the FluidStack, not considering current state. (Basically, is a given fluid EVER allowed in this tank?) Return FALSE if the answer to that question is 'no.'
 
- 
fillDescription copied from interface:IFluidHandlerFills fluid into internal tanks, distribution is left entirely to the IFluidHandler.- Specified by:
- fillin interface- IFluidHandler
- Parameters:
- resource- FluidStack representing the Fluid and maximum amount of fluid to be filled.
- doFill- If SIMULATE, fill will only be simulated.
- Returns:
- Amount of resource that was (or would have been, if simulated) filled.
 
- 
drainDescription copied from interface:IFluidHandlerDrains fluid out of internal tanks, distribution is left entirely to the IFluidHandler.- Specified by:
- drainin interface- IFluidHandler
- Parameters:
- resource- FluidStack representing the Fluid and maximum amount of fluid to be drained.
- action- If SIMULATE, drain will only be simulated.
- Returns:
- FluidStack representing the Fluid and amount that was (or would have been, if simulated) drained.
 
- 
drainDescription copied from interface:IFluidHandlerDrains fluid out of internal tanks, distribution is left entirely to the IFluidHandler.This method is not Fluid-sensitive. - Specified by:
- drainin interface- IFluidHandler
- Parameters:
- maxDrain- Maximum amount of fluid to drain.
- action- If SIMULATE, drain will only be simulated.
- Returns:
- FluidStack representing the Fluid and amount that was (or would have been, if simulated) drained.
 
- 
canFillFluidType
- 
canDrainFluidType
- 
setContainerToEmptyprotected void setContainerToEmpty()Override this method for special handling. Can be used to swap out or destroy the container.
- 
getCapability@Nonnull public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> capability, @Nullable Direction facing)Description copied from interface:ICapabilityProviderRetrieves the Optional handler for the capability requested on the specific side. The return value CAN be the same for multiple faces. Modders are encouraged to cache this value, using the listener capabilities of the Optional to be notified if the requested capability get lost.- Specified by:
- getCapabilityin interface- ICapabilityProvider
- Parameters:
- capability- The capability to check
- facing- The Side to check from, CAN BE NULL. Null is defined to represent 'internal' or 'self'
- Returns:
- The requested an optional holding the requested capability.
 
 
-