Class FluidTank
- java.lang.Object
-
- net.minecraftforge.fluids.capability.templates.FluidTank
-
- All Implemented Interfaces:
IFluidHandler
,IFluidTank
public class FluidTank extends java.lang.Object implements IFluidHandler, IFluidTank
Flexible implementation of a Fluid Storage object. NOT REQUIRED.- Author:
- King Lemming
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface net.minecraftforge.fluids.capability.IFluidHandler
IFluidHandler.FluidAction
-
-
Field Summary
Fields Modifier and Type Field Description protected int
capacity
protected FluidStack
fluid
protected java.util.function.Predicate<FluidStack>
validator
-
Constructor Summary
Constructors Constructor Description FluidTank(int capacity)
FluidTank(int capacity, java.util.function.Predicate<FluidStack> validator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FluidStack
drain(int maxDrain, IFluidHandler.FluidAction action)
Drains fluid out of internal tanks, distribution is left entirely to the IFluidHandler.FluidStack
drain(FluidStack resource, IFluidHandler.FluidAction action)
Drains fluid out of internal tanks, distribution is left entirely to the IFluidHandler.int
fill(FluidStack resource, IFluidHandler.FluidAction action)
Fills fluid into internal tanks, distribution is left entirely to the IFluidHandler.int
getCapacity()
FluidStack
getFluid()
int
getFluidAmount()
FluidStack
getFluidInTank(int tank)
Returns the FluidStack in a given tank.int
getSpace()
int
getTankCapacity(int tank)
Retrieves the maximum fluid amount for a given tank.int
getTanks()
Returns the number of fluid storage units ("tanks") availableboolean
isEmpty()
boolean
isFluidValid(int tank, FluidStack stack)
This function is a way to determine which fluids can exist inside a given handler.boolean
isFluidValid(FluidStack stack)
protected void
onContentsChanged()
FluidTank
readFromNBT(CompoundNBT nbt)
FluidTank
setCapacity(int capacity)
void
setFluid(FluidStack stack)
FluidTank
setValidator(java.util.function.Predicate<FluidStack> validator)
CompoundNBT
writeToNBT(CompoundNBT nbt)
-
-
-
Field Detail
-
validator
protected java.util.function.Predicate<FluidStack> validator
-
fluid
@Nonnull protected FluidStack fluid
-
capacity
protected int capacity
-
-
Constructor Detail
-
FluidTank
public FluidTank(int capacity)
-
FluidTank
public FluidTank(int capacity, java.util.function.Predicate<FluidStack> validator)
-
-
Method Detail
-
setCapacity
public FluidTank setCapacity(int capacity)
-
setValidator
public FluidTank setValidator(java.util.function.Predicate<FluidStack> validator)
-
isFluidValid
public boolean isFluidValid(FluidStack stack)
- Specified by:
isFluidValid
in interfaceIFluidTank
- Parameters:
stack
- Fluidstack holding the Fluid to be queried.- Returns:
- If the tank can hold the fluid (EVER, not at the time of query).
-
getCapacity
public int getCapacity()
- Specified by:
getCapacity
in interfaceIFluidTank
- Returns:
- Capacity of this fluid tank.
-
getFluid
@Nonnull public FluidStack getFluid()
- Specified by:
getFluid
in interfaceIFluidTank
- Returns:
- FluidStack representing the fluid in the tank, null if the tank is empty.
-
getFluidAmount
public int getFluidAmount()
- Specified by:
getFluidAmount
in interfaceIFluidTank
- Returns:
- Current amount of fluid in the tank.
-
readFromNBT
public FluidTank readFromNBT(CompoundNBT nbt)
-
writeToNBT
public CompoundNBT writeToNBT(CompoundNBT nbt)
-
getTanks
public int getTanks()
Description copied from interface:IFluidHandler
Returns the number of fluid storage units ("tanks") available- Specified by:
getTanks
in interfaceIFluidHandler
- Returns:
- The number of tanks available
-
getFluidInTank
@Nonnull public FluidStack getFluidInTank(int tank)
Description copied from interface:IFluidHandler
Returns 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:
getFluidInTank
in interfaceIFluidHandler
- Parameters:
tank
- Tank to query.- Returns:
- FluidStack in a given tank. FluidStack.EMPTY if the tank is empty.
-
getTankCapacity
public int getTankCapacity(int tank)
Description copied from interface:IFluidHandler
Retrieves the maximum fluid amount for a given tank.- Specified by:
getTankCapacity
in interfaceIFluidHandler
- Parameters:
tank
- Tank to query.- Returns:
- The maximum fluid amount held by the tank.
-
isFluidValid
public boolean isFluidValid(int tank, @Nonnull FluidStack stack)
Description copied from interface:IFluidHandler
This 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:
isFluidValid
in interfaceIFluidHandler
- Parameters:
tank
- Tank to query for validitystack
- 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.'
-
fill
public int fill(FluidStack resource, IFluidHandler.FluidAction action)
Description copied from interface:IFluidHandler
Fills fluid into internal tanks, distribution is left entirely to the IFluidHandler.- Specified by:
fill
in interfaceIFluidHandler
- Specified by:
fill
in interfaceIFluidTank
- Parameters:
resource
- FluidStack representing the Fluid and maximum amount of fluid to be filled.action
- If SIMULATE, fill will only be simulated.- Returns:
- Amount of resource that was (or would have been, if simulated) filled.
-
drain
@Nonnull public FluidStack drain(FluidStack resource, IFluidHandler.FluidAction action)
Description copied from interface:IFluidHandler
Drains fluid out of internal tanks, distribution is left entirely to the IFluidHandler.- Specified by:
drain
in interfaceIFluidHandler
- Specified by:
drain
in interfaceIFluidTank
- 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.
-
drain
@Nonnull public FluidStack drain(int maxDrain, IFluidHandler.FluidAction action)
Description copied from interface:IFluidHandler
Drains fluid out of internal tanks, distribution is left entirely to the IFluidHandler. This method is not Fluid-sensitive.- Specified by:
drain
in interfaceIFluidHandler
- Specified by:
drain
in interfaceIFluidTank
- 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.
-
onContentsChanged
protected void onContentsChanged()
-
setFluid
public void setFluid(FluidStack stack)
-
isEmpty
public boolean isEmpty()
-
getSpace
public int getSpace()
-
-