Class FluidType
Fluid
. This is used to link a flowing and source fluid together
without relying on tags. Most accessors do not correlate to in-game features;
they are provided for mods to take advantage of.
Accessors are typically implemented in a method call chain. As such, it can provide a general implementation while more specific implementations can be implemented by overriding methods further in the call chain (on fluids, entities, etc.).
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
The properties of the fluid. -
Field Summary
Modifier and TypeFieldDescriptionprivate final @Nullable PathType
static final int
The number of fluid units that a bucket represents.private final boolean
private final boolean
private final boolean
private final boolean
private final boolean
private final boolean
private final int
private String
private final float
private final int
private final double
private final @Nullable PathType
private final Rarity
private Object
A lazy value which computes the number of fluid types within the registry.protected final Map
<SoundAction, SoundEvent> A map of actions performed to sound that should be played.private final boolean
private final int
private final int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
canBePlacedInLevel
(BlockAndTintGetter getter, BlockPos pos, FluidState state) Returns whether the fluid can be placed in the level.final boolean
canBePlacedInLevel
(BlockAndTintGetter getter, BlockPos pos, FluidStack stack) Returns whether the fluid can be placed in the level.boolean
canConvertToSource
(FluidState state, LevelReader reader, BlockPos pos) Returns whether the fluid can create a source.boolean
canConvertToSource
(FluidStack stack) Returns whether the fluid can create a source.boolean
canDrownIn
(LivingEntity entity) Returns whether the entity can drown in the fluid.boolean
canExtinguish
(Entity entity) Returns whether the entity can be extinguished by this fluid.boolean
canExtinguish
(FluidState state, BlockGetter getter, BlockPos pos) Returns whether the block can be extinguished by this fluid.boolean
canHydrate
(Entity entity) Returns whether the entity can be hydrated by this fluid.boolean
canHydrate
(FluidState state, BlockGetter getter, BlockPos pos, BlockState source, BlockPos sourcePos) Returns whether the block can be hydrated by a fluid.boolean
canHydrate
(FluidStack stack) Returns whether the fluid can hydrate.boolean
canPushEntity
(Entity entity) Returns whether the fluid can push an entity.boolean
canRideVehicleUnder
(Entity vehicle, Entity rider) Returns whether the entity can ride in this vehicle under the fluid.boolean
Returns whether the entity can swim in the fluid.@Nullable PathType
getAdjacentBlockPathType
(FluidState state, BlockGetter level, BlockPos pos, @Nullable Mob mob, PathType originalType) Gets the path type of the adjacent fluid to a pathfinding entity.getBlockForFluidState
(BlockAndTintGetter getter, BlockPos pos, FluidState state) Returns the associatedBlockState
for aFluidState
.@Nullable PathType
getBlockPathType
(FluidState state, BlockGetter level, BlockPos pos, @Nullable Mob mob, boolean canFluidLog) Gets the path type of this fluid when an entity is pathfinding.getBucket
(FluidStack stack) Returns the bucket containing the fluid.int
Returns the density of the fluid.int
getDensity
(FluidState state, BlockAndTintGetter getter, BlockPos pos) Returns the density of the fluid.int
getDensity
(FluidStack stack) Returns the density of the fluid.Returns the component representing the name of the fluid type.getDescription
(FluidStack stack) Returns the component representing the name of the fluid type.Returns the identifier representing the name of the fluid type.getDescriptionId
(FluidStack stack) Returns the identifier representing the name of the fluid.float
getFallDistanceModifier
(Entity entity) Returns how much the fluid should scale the damage done to a falling entity when hitting the ground per tick.int
Returns the light level emitted by the fluid.int
getLightLevel
(FluidState state, BlockAndTintGetter getter, BlockPos pos) Returns the light level emitted by the fluid.int
getLightLevel
(FluidStack stack) Returns the light level emitted by the fluid.Returns the rarity of the fluid.getRarity
(FluidStack stack) Returns the rarity of the fluid.@Nullable SoundEvent
getSound
(Entity entity, SoundAction action) Returns a sound to play when a certain action is performed by the entity in the fluid.@Nullable SoundEvent
getSound
(@Nullable Player player, BlockGetter getter, BlockPos pos, SoundAction action) Returns a sound to play when a certain action is performed at a position.@Nullable SoundEvent
getSound
(SoundAction action) Returns a sound to play when a certain action is performed.@Nullable SoundEvent
getSound
(FluidStack stack, SoundAction action) Returns a sound to play when a certain action is performed.getStateForPlacement
(BlockAndTintGetter getter, BlockPos pos, FluidStack stack) Returns theFluidState
when aFluidStack
is trying to place it.int
Returns the temperature of the fluid.int
getTemperature
(FluidState state, BlockAndTintGetter getter, BlockPos pos) Returns the temperature of the fluid.int
getTemperature
(FluidStack stack) Returns the temperature of the fluid.int
Returns the viscosity, or thickness, of the fluid.int
getViscosity
(FluidState state, BlockAndTintGetter getter, BlockPos pos) Returns the viscosity, or thickness, of the fluid.int
getViscosity
(FluidStack stack) Returns the viscosity, or thickness, of the fluid.private void
void
initializeClient
(Consumer<IClientFluidTypeExtensions> consumer) final boolean
isAir()
Returns whether the fluid type represents air.final boolean
Returns whether a fluid is lighter than air.final boolean
Returns whether the fluid type is from vanilla.boolean
isVaporizedOnPlacement
(Level level, BlockPos pos, FluidStack stack) Determines if this fluid should be vaporized when placed into a level.double
motionScale
(Entity entity) Returns how much the velocity of the fluid should be scaled by when applied to an entity.boolean
move
(FluidState state, LivingEntity entity, Vec3 movementVector, double gravity) Performs how an entity moves when within the fluid.void
onVaporize
(@Nullable Player player, Level level, BlockPos pos, FluidStack stack) Performs an action when a fluid can be vaporized when placed into a level.void
setItemMovement
(ItemEntity entity) Performs what to do when an item is in a fluid.boolean
shouldUpdateWhileBoating
(FluidState state, Boat boat, Entity rider) Whenfalse
, the fluid will no longer update its height value while within a boat while it is not within a fluid (Boat.isUnderWater()
.boolean
supportsBoating
(Boat boat) Returns whether the boat can be used on the fluid.boolean
supportsBoating
(FluidState state, Boat boat) Returns whether the boat can be used on the fluid.toString()
-
Field Details
-
BUCKET_VOLUME
public static final int BUCKET_VOLUMEThe number of fluid units that a bucket represents.- See Also:
-
SIZE
A lazy value which computes the number of fluid types within the registry. -
descriptionId
-
motionScale
private final double motionScale -
canPushEntity
private final boolean canPushEntity -
canSwim
private final boolean canSwim -
canDrown
private final boolean canDrown -
fallDistanceModifier
private final float fallDistanceModifier -
canExtinguish
private final boolean canExtinguish -
canConvertToSource
private final boolean canConvertToSource -
supportsBoating
private final boolean supportsBoating -
pathType
-
adjacentPathType
-
canHydrate
private final boolean canHydrate -
lightLevel
private final int lightLevel -
density
private final int density -
temperature
private final int temperature -
viscosity
private final int viscosity -
rarity
-
sounds
A map of actions performed to sound that should be played. -
renderProperties
-
-
Constructor Details
-
FluidType
Default constructor.- Parameters:
properties
- the general properties of the fluid type
-
-
Method Details
-
getDescription
Returns the component representing the name of the fluid type.- Returns:
- the component representing the name of the fluid type
-
getDescriptionId
Returns the identifier representing the name of the fluid type. If no identifier was specified, then the identifier will be defaulted tofluid_type.<modid>.<registry_name>
.- Returns:
- the identifier representing the name of the fluid type
-
getLightLevel
public int getLightLevel()Returns the light level emitted by the fluid.Note: This should be a value between
[0,15]
. If not specified, the light level is0
as most fluids do not emit light.Implementation: This is used by the bucket model to determine whether the fluid should render full-bright when
applyFluidLuminosity
istrue
.- Returns:
- the light level emitted by the fluid
-
getDensity
public int getDensity()Returns the density of the fluid.Note: This is an arbitrary number. Negative or zero values indicate that the fluid is lighter than air. If not specified, the density is approximately equivalent to the real-life density of water in
kg/m^3
.- Returns:
- the density of the fluid
-
getTemperature
public int getTemperature()Returns the temperature of the fluid.Note: This is an arbitrary number. Higher temperature values indicate that the fluid is hotter. If not specified, the temperature is approximately equivalent to the real-life room temperature of water in
Kelvin
.- Returns:
- the temperature of the fluid
-
getViscosity
public int getViscosity()Returns the viscosity, or thickness, of the fluid.Note: This is an arbitrary number. The value should never be negative. Higher viscosity values indicate that the fluid flows more slowly. If not specified, the viscosity is approximately equivalent to the real-life viscosity of water in
m/s^2
.- Returns:
- the viscosity of the fluid
-
getRarity
Returns the rarity of the fluid.Note: If not specified, the rarity of the fluid is
Rarity.COMMON
.- Returns:
- the rarity of the fluid
-
getSound
Returns a sound to play when a certain action is performed. If no sound is present, then the sound will benull
.- Parameters:
action
- the action being performed- Returns:
- the sound to play when performing the action
-
motionScale
Returns how much the velocity of the fluid should be scaled by when applied to an entity.- Parameters:
entity
- the entity in the fluid- Returns:
- a scalar to multiply to the fluid velocity
-
canPushEntity
Returns whether the fluid can push an entity.- Parameters:
entity
- the entity in the fluid- Returns:
true
if the entity can be pushed by the fluid,false
otherwise
-
canSwim
Returns whether the entity can swim in the fluid.- Parameters:
entity
- the entity in the fluid- Returns:
true
if the entity can swim in the fluid,false
otherwise
-
getFallDistanceModifier
Returns how much the fluid should scale the damage done to a falling entity when hitting the ground per tick.Implementation: If the entity is in many fluids, the smallest modifier is applied.
- Parameters:
entity
- the entity in the fluid- Returns:
- a scalar to multiply to the fall damage
-
canExtinguish
Returns whether the entity can be extinguished by this fluid.- Parameters:
entity
- the entity in the fluid- Returns:
true
if the entity can be extinguished,false
otherwise
-
move
Performs how an entity moves when within the fluid. If using custom movement logic, the method should returntrue
. Otherwise, the movement logic will default to water.- Parameters:
state
- the state of the fluidentity
- the entity moving within the fluidmovementVector
- the velocity of how the entity wants to movegravity
- the gravity to apply to the entity- Returns:
true
if custom movement logic is performed,false
otherwise
-
canDrownIn
Returns whether the entity can drown in the fluid.- Parameters:
entity
- the entity in the fluid- Returns:
true
if the entity can drown in the fluid,false
otherwise
-
setItemMovement
Performs what to do when an item is in a fluid.- Parameters:
entity
- the item in the fluid
-
supportsBoating
Returns whether the boat can be used on the fluid.- Parameters:
boat
- the boat trying to be used on the fluid- Returns:
true
if the boat can be used,false
otherwise
-
supportsBoating
Returns whether the boat can be used on the fluid.- Parameters:
state
- the state of the fluidboat
- the boat trying to be used on the fluid- Returns:
true
if the boat can be used,false
otherwise
-
shouldUpdateWhileBoating
Whenfalse
, the fluid will no longer update its height value while within a boat while it is not within a fluid (Boat.isUnderWater()
.- Parameters:
state
- the state of the fluid the rider is withinboat
- the boat the rider is within that is not inside a fluidrider
- the rider of the boat- Returns:
true
if the fluid height should be updated,false
otherwise
-
canRideVehicleUnder
Returns whether the entity can ride in this vehicle under the fluid.- Parameters:
vehicle
- the vehicle being ridden inrider
- the entity riding the vehicle- Returns:
true
if the vehicle can be ridden in under this fluid,false
otherwise
-
canHydrate
Returns whether the entity can be hydrated by this fluid.Hydration is an arbitrary word which depends on the entity.
- Parameters:
entity
- the entity in the fluid- Returns:
true
if the entity can be hydrated,false
otherwise
-
getSound
Returns a sound to play when a certain action is performed by the entity in the fluid. If no sound is present, then the sound will benull
.- Parameters:
entity
- the entity in the fluidaction
- the action being performed- Returns:
- the sound to play when performing the action
-
canExtinguish
Returns whether the block can be extinguished by this fluid.- Parameters:
state
- the state of the fluidgetter
- the getter which can get the fluidpos
- the position of the fluid- Returns:
true
if the block can be extinguished,false
otherwise
-
canConvertToSource
Returns whether the fluid can create a source.- Parameters:
state
- the state of the fluidreader
- the reader that can get the fluidpos
- the location of the fluid- Returns:
true
if the fluid can create a source,false
otherwise
-
getBlockPathType
@Nullable public @Nullable PathType getBlockPathType(FluidState state, BlockGetter level, BlockPos pos, @Nullable @Nullable Mob mob, boolean canFluidLog) Gets the path type of this fluid when an entity is pathfinding. Whennull
, uses vanilla behavior.- Parameters:
state
- the state of the fluidlevel
- the level which contains this fluidpos
- the position of the fluidmob
- the mob currently pathfinding, may benull
canFluidLog
-true
if the path is being applied for fluids that can log blocks, should be checked against if the fluid can log a block- Returns:
- the path type of this fluid
-
getAdjacentBlockPathType
@Nullable public @Nullable PathType getAdjacentBlockPathType(FluidState state, BlockGetter level, BlockPos pos, @Nullable @Nullable Mob mob, PathType originalType) Gets the path type of the adjacent fluid to a pathfinding entity. Path types with a negative malus are not traversable for the entity. Pathfinding entities will favor paths consisting of a lower malus. Whennull
, uses vanilla behavior.- Parameters:
state
- the state of the fluidlevel
- the level which contains this fluidpos
- the position of the fluidmob
- the mob currently pathfinding, may benull
originalType
- the path type of the source the entity is on- Returns:
- the path type of this fluid
-
getSound
@Nullable public @Nullable SoundEvent getSound(@Nullable @Nullable Player player, BlockGetter getter, BlockPos pos, SoundAction action) Returns a sound to play when a certain action is performed at a position. If no sound is present, then the sound will benull
.- Parameters:
player
- the player listening to the soundgetter
- the getter which can get the fluidpos
- the position of the fluidaction
- the action being performed- Returns:
- the sound to play when performing the action
-
canHydrate
public boolean canHydrate(FluidState state, BlockGetter getter, BlockPos pos, BlockState source, BlockPos sourcePos) Returns whether the block can be hydrated by a fluid.Hydration is an arbitrary word which depends on the block.
- A farmland has moisture
- A sponge can soak up the liquid
- A coral can live
- Parameters:
state
- the state of the fluidgetter
- the getter which can get the fluidpos
- the position of the fluidsource
- the state of the block being hydratedsourcePos
- the position of the block being hydrated- Returns:
true
if the block can be hydrated,false
otherwise
-
getLightLevel
Returns the light level emitted by the fluid.Note: This should be a value between
[0,15]
. If not specified, the light level is0
as most fluids do not emit light.- Parameters:
state
- the state of the fluidgetter
- the getter which can get the fluidpos
- the position of the fluid- Returns:
- the light level emitted by the fluid
-
getDensity
Returns the density of the fluid.Note: This is an arbitrary number. Negative or zero values indicate that the fluid is lighter than air. If not specified, the density is approximately equivalent to the real-life density of water in
kg/m^3
.- Parameters:
state
- the state of the fluidgetter
- the getter which can get the fluidpos
- the position of the fluid- Returns:
- the density of the fluid
-
getTemperature
Returns the temperature of the fluid.Note: This is an arbitrary number. Higher temperature values indicate that the fluid is hotter. If not specified, the temperature is approximately equivalent to the real-life room temperature of water in
Kelvin
.- Parameters:
state
- the state of the fluidgetter
- the getter which can get the fluidpos
- the position of the fluid- Returns:
- the temperature of the fluid
-
getViscosity
Returns the viscosity, or thickness, of the fluid.Note: This is an arbitrary number. The value should never be negative. Higher viscosity values indicate that the fluid flows more slowly. If not specified, the viscosity is approximately equivalent to the real-life viscosity of water in
m/s^2
.- Parameters:
state
- the state of the fluidgetter
- the getter which can get the fluidpos
- the position of the fluid- Returns:
- the viscosity of the fluid
-
canConvertToSource
Returns whether the fluid can create a source.- Parameters:
stack
- the stack holding the fluid- Returns:
true
if the fluid can create a source,false
otherwise
-
getSound
Returns a sound to play when a certain action is performed. If no sound is present, then the sound will benull
.- Parameters:
stack
- the stack holding the fluidaction
- the action being performed- Returns:
- the sound to play when performing the action
-
getDescription
Returns the component representing the name of the fluid type.- Parameters:
stack
- the stack holding the fluid- Returns:
- the component representing the name of the fluid type
-
getDescriptionId
Returns the identifier representing the name of the fluid. If no identifier was specified, then the identifier will be defaulted tofluid_type.<modid>.<registry_name>
.- Parameters:
stack
- the stack holding the fluid- Returns:
- the identifier representing the name of the fluid
-
canHydrate
Returns whether the fluid can hydrate.Hydration is an arbitrary word which depends on the implementation.
- Parameters:
stack
- the stack holding the fluid- Returns:
true
if the fluid can hydrate,false
otherwise
-
getLightLevel
Returns the light level emitted by the fluid.Note: This should be a value between
[0,15]
. If not specified, the light level is0
as most fluids do not emit light.- Parameters:
stack
- the stack holding the fluid- Returns:
- the light level emitted by the fluid
-
getDensity
Returns the density of the fluid.Note: This is an arbitrary number. Negative or zero values indicate that the fluid is lighter than air. If not specified, the density is approximately equivalent to the real-life density of water in
kg/m^3
.- Parameters:
stack
- the stack holding the fluid- Returns:
- the density of the fluid
-
getTemperature
Returns the temperature of the fluid.Note: This is an arbitrary number. Higher temperature values indicate that the fluid is hotter. If not specified, the temperature is approximately equivalent to the real-life room temperature of water in
Kelvin
.- Parameters:
stack
- the stack holding the fluid- Returns:
- the temperature of the fluid
-
getViscosity
Returns the viscosity, or thickness, of the fluid.Note: This is an arbitrary number. The value should never be negative. Higher viscosity values indicate that the fluid flows more slowly. If not specified, the viscosity is approximately equivalent to the real-life viscosity of water in
m/s^2
.- Parameters:
stack
- the stack holding the fluid- Returns:
- the viscosity of the fluid
-
getRarity
Returns the rarity of the fluid.Note: If not specified, the rarity of the fluid is
Rarity.COMMON
.- Parameters:
stack
- the stack holding the fluid- Returns:
- the rarity of the fluid
-
isAir
public final boolean isAir()Returns whether the fluid type represents air.- Returns:
true
if the type represents air,false
otherwise
-
isVanilla
public final boolean isVanilla()Returns whether the fluid type is from vanilla.- Returns:
true
if the type is from vanilla,false
otherwise
-
getBucket
Returns the bucket containing the fluid.- Parameters:
stack
- the stack holding the fluid- Returns:
- the bucket containing the fluid
-
getBlockForFluidState
Returns the associatedBlockState
for aFluidState
.- Parameters:
getter
- the getter which can get the level datapos
- the position of where the fluid would bestate
- the state of the fluid- Returns:
- the
BlockState
of a fluid
-
getStateForPlacement
Returns theFluidState
when aFluidStack
is trying to place it.- Parameters:
getter
- the getter which can get the level datapos
- the position of where the fluid is being placedstack
- the stack holding the fluid- Returns:
- the
FluidState
being placed
-
canBePlacedInLevel
Returns whether the fluid can be placed in the level.- Parameters:
getter
- the getter which can get the level datapos
- the position of where the fluid is being placedstate
- the state of the fluid being placed- Returns:
true
if the fluid can be placed,false
otherwise
-
canBePlacedInLevel
Returns whether the fluid can be placed in the level.- Parameters:
getter
- the getter which can get the level datapos
- the position of where the fluid is being placedstack
- the stack holding the fluid- Returns:
true
if the fluid can be placed,false
otherwise
-
isLighterThanAir
public final boolean isLighterThanAir()Returns whether a fluid is lighter than air. If the fluid's density is lower than or equal0
, the fluid is considered lighter than air.Tip:
0
is the "canonical" density of air within Forge.Note: Fluids lighter than air will have their bucket model rotated upside-down; fluid block models will have their vertices inverted.
- Returns:
true
if the fluid is lighter than air,false
otherwise
-
isVaporizedOnPlacement
Determines if this fluid should be vaporized when placed into a level.Note: Fluids that can turn lava into obsidian should vaporize within the nether to preserve the intentions of vanilla.
- Parameters:
level
- the level the fluid is being placed inpos
- the position to place the fluid atstack
- the stack holding the fluid being placed- Returns:
true
if this fluid should be vaporized on placement,false
otherwise- See Also:
-
onVaporize
public void onVaporize(@Nullable @Nullable Player player, Level level, BlockPos pos, FluidStack stack) Performs an action when a fluid can be vaporized when placed into a level.Note: The fluid will already have been drained from the stack.
- Parameters:
player
- the player placing the fluid, may benull
for blocks like dispenserslevel
- the level the fluid is vaporized inpos
- the position the fluid is vaporized atstack
- the stack holding the fluid being vaporized- See Also:
-
toString
-
getRenderPropertiesInternal
-
initClient
private void initClient() -
initializeClient
-