public class FluidTank extends java.lang.Object implements IFluidHandler, IFluidTank
IFluidHandler.FluidAction
Modifier and Type | Field and Description |
---|---|
protected int |
capacity |
protected FluidStack |
fluid |
protected java.util.function.Predicate<FluidStack> |
validator |
Constructor and Description |
---|
FluidTank(int capacity) |
FluidTank(int capacity,
java.util.function.Predicate<FluidStack> validator) |
Modifier and Type | Method and Description |
---|---|
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 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") available
|
boolean |
isEmpty() |
boolean |
isFluidValid(FluidStack stack) |
boolean |
isFluidValid(int tank,
FluidStack stack)
This function is a way to determine which fluids can exist inside a given handler.
|
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) |
protected java.util.function.Predicate<FluidStack> validator
@Nonnull protected FluidStack fluid
protected int capacity
public FluidTank(int capacity)
public FluidTank(int capacity, java.util.function.Predicate<FluidStack> validator)
public FluidTank setCapacity(int capacity)
public FluidTank setValidator(java.util.function.Predicate<FluidStack> validator)
public boolean isFluidValid(FluidStack stack)
isFluidValid
in interface IFluidTank
stack
- Fluidstack holding the Fluid to be queried.public int getCapacity()
getCapacity
in interface IFluidTank
@Nonnull public FluidStack getFluid()
getFluid
in interface IFluidTank
public int getFluidAmount()
getFluidAmount
in interface IFluidTank
public FluidTank readFromNBT(CompoundNBT nbt)
public CompoundNBT writeToNBT(CompoundNBT nbt)
public int getTanks()
IFluidHandler
getTanks
in interface IFluidHandler
@Nonnull public FluidStack getFluidInTank(int tank)
IFluidHandler
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
getFluidInTank
in interface IFluidHandler
tank
- Tank to query.public int getTankCapacity(int tank)
IFluidHandler
getTankCapacity
in interface IFluidHandler
tank
- Tank to query.public boolean isFluidValid(int tank, @Nonnull FluidStack stack)
IFluidHandler
isFluidValid
in interface IFluidHandler
tank
- Tank to query for validitystack
- Stack to test with for validitypublic int fill(FluidStack resource, IFluidHandler.FluidAction action)
IFluidHandler
fill
in interface IFluidHandler
fill
in interface IFluidTank
resource
- FluidStack representing the Fluid and maximum amount of fluid to be filled.action
- If SIMULATE, fill will only be simulated.@Nonnull public FluidStack drain(FluidStack resource, IFluidHandler.FluidAction action)
IFluidHandler
drain
in interface IFluidHandler
drain
in interface IFluidTank
resource
- 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)
IFluidHandler
drain
in interface IFluidHandler
drain
in interface IFluidTank
maxDrain
- Maximum amount of fluid to drain.action
- If SIMULATE, drain will only be simulated.protected void onContentsChanged()
public void setFluid(FluidStack stack)
public boolean isEmpty()
public int getSpace()