Class FluidTank
java.lang.Object
net.neoforged.neoforge.fluids.capability.templates.FluidTank
- All Implemented Interfaces:
IFluidHandler,IFluidTank
Flexible implementation of a Fluid Storage object. NOT REQUIRED.
- Author:
- King Lemming
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.neoforged.neoforge.fluids.capability.IFluidHandler
IFluidHandler.FluidAction -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected FluidStackprotected Predicate<FluidStack> -
Constructor Summary
ConstructorsConstructorDescriptionFluidTank(int capacity) FluidTank(int capacity, Predicate<FluidStack> validator) -
Method Summary
Modifier and TypeMethodDescriptiondrain(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 action) Fills fluid into internal tanks, distribution is left entirely to the IFluidHandler.intgetFluid()intgetFluidInTank(int tank) Returns the FluidStack in a given tank.intgetSpace()intgetTankCapacity(int tank) Retrieves the maximum fluid amount for a given tank.intgetTanks()Returns the number of fluid storage units ("tanks") availablebooleanisEmpty()booleanisFluidValid(int tank, FluidStack stack) This function is a way to determine which fluids can exist inside a given handler.booleanisFluidValid(FluidStack stack) protected voidreadFromNBT(HolderLookup.Provider lookupProvider, CompoundTag nbt) setCapacity(int capacity) voidsetFluid(FluidStack stack) setValidator(Predicate<FluidStack> validator) writeToNBT(HolderLookup.Provider lookupProvider, CompoundTag nbt)
-
Field Details
-
validator
-
fluid
-
capacity
protected int capacity
-
-
Constructor Details
-
FluidTank
public FluidTank(int capacity) -
FluidTank
-
-
Method Details
-
setCapacity
-
setValidator
-
isFluidValid
- Specified by:
isFluidValidin 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:
getCapacityin interfaceIFluidTank- Returns:
- Capacity of this fluid tank.
-
getFluid
- Specified by:
getFluidin interfaceIFluidTank- Returns:
- FluidStack representing the fluid in the tank, null if the tank is empty.
-
getFluidAmount
public int getFluidAmount()- Specified by:
getFluidAmountin interfaceIFluidTank- Returns:
- Current amount of fluid in the tank.
-
readFromNBT
-
writeToNBT
-
getTanks
public int getTanks()Description copied from interface:IFluidHandlerReturns the number of fluid storage units ("tanks") available- Specified by:
getTanksin interfaceIFluidHandler- Returns:
- The number of tanks available
-
getFluidInTank
Description 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 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:IFluidHandlerRetrieves the maximum fluid amount for a given tank.- Specified by:
getTankCapacityin interfaceIFluidHandler- Parameters:
tank- Tank to query.- Returns:
- The maximum fluid amount held by the tank.
-
isFluidValid
Description 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 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
Description copied from interface:IFluidHandlerFills fluid into internal tanks, distribution is left entirely to the IFluidHandler.- Specified by:
fillin interfaceIFluidHandler- Specified by:
fillin 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
Description copied from interface:IFluidHandlerDrains fluid out of internal tanks, distribution is left entirely to the IFluidHandler.- Specified by:
drainin interfaceIFluidHandler- Specified by:
drainin 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
Description 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 interfaceIFluidHandler- Specified by:
drainin 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
-
isEmpty
public boolean isEmpty() -
getSpace
public int getSpace()
-