Class FluidType

java.lang.Object
net.minecraftforge.fluids.FluidType

public class FluidType extends Object
A definition of common attributes, properties, and methods that is applied to a 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.).

  • Field Details

    • BUCKET_VOLUME

      public static final int BUCKET_VOLUME
      The number of fluid units that a bucket represents.
      See Also:
    • SIZE

      public static final Lazy<Integer> SIZE
      A lazy value which computes the number of fluid types within the registry.
    • descriptionId

      private String 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

      @Nullable private final @Nullable BlockPathTypes pathType
    • adjacentPathType

      @Nullable private final @Nullable BlockPathTypes 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

      private final Rarity rarity
    • sounds

      protected final Map<SoundAction,SoundEvent> sounds
      A map of actions performed to sound that should be played.
    • renderProperties

      private Object renderProperties
  • Constructor Details

    • FluidType

      public FluidType(FluidType.Properties properties)
      Default constructor.
      Parameters:
      properties - the general properties of the fluid type
  • Method Details

    • getDescription

      public Component getDescription()
      Returns the component representing the name of the fluid type.
      Returns:
      the component representing the name of the fluid type
    • getDescriptionId

      public String getDescriptionId()
      Returns the identifier representing the name of the fluid type. If no identifier was specified, then the identifier will be defaulted to fluid_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 is 0 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 is true.

      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

      public Rarity 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

      @Nullable public @Nullable SoundEvent getSound(SoundAction action)
      Returns a sound to play when a certain action is performed. If no sound is present, then the sound will be null.
      Parameters:
      action - the action being performed
      Returns:
      the sound to play when performing the action
    • motionScale

      public double motionScale(Entity entity)
      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

      public boolean canPushEntity(Entity entity)
      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

      public boolean canSwim(Entity entity)
      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

      public float getFallDistanceModifier(Entity entity)
      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

      public boolean canExtinguish(Entity entity)
      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

      public boolean move(FluidState state, LivingEntity entity, Vec3 movementVector, double gravity)
      Performs how an entity moves when within the fluid. If using custom movement logic, the method should return true. Otherwise, the movement logic will default to water.
      Parameters:
      state - the state of the fluid
      entity - the entity moving within the fluid
      movementVector - the velocity of how the entity wants to move
      gravity - the gravity to apply to the entity
      Returns:
      true if custom movement logic is performed, false otherwise
    • canDrownIn

      public boolean canDrownIn(LivingEntity entity)
      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

      public void setItemMovement(ItemEntity entity)
      Performs what to do when an item is in a fluid.
      Parameters:
      entity - the item in the fluid
    • supportsBoating

      public boolean supportsBoating(Boat boat)
      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

      public boolean supportsBoating(FluidState state, Boat boat)
      Returns whether the boat can be used on the fluid.
      Parameters:
      state - the state of the fluid
      boat - the boat trying to be used on the fluid
      Returns:
      true if the boat can be used, false otherwise
    • canRideVehicleUnder

      public boolean canRideVehicleUnder(Entity vehicle, Entity rider)
      Returns whether the entity can ride in this vehicle under the fluid.
      Parameters:
      vehicle - the vehicle being ridden in
      rider - the entity riding the vehicle
      Returns:
      true if the vehicle can be ridden in under this fluid, false otherwise
    • canHydrate

      public boolean canHydrate(Entity entity)
      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

      @Nullable public @Nullable SoundEvent getSound(Entity entity, SoundAction action)
      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 be null.
      Parameters:
      entity - the entity in the fluid
      action - the action being performed
      Returns:
      the sound to play when performing the action
    • canExtinguish

      public boolean canExtinguish(FluidState state, BlockGetter getter, BlockPos pos)
      Returns whether the block can be extinguished by this fluid.
      Parameters:
      state - the state of the fluid
      getter - the getter which can get the fluid
      pos - the position of the fluid
      Returns:
      true if the block can be extinguished, false otherwise
    • canConvertToSource

      public boolean canConvertToSource(FluidState state, LevelReader reader, BlockPos pos)
      Returns whether the fluid can create a source.
      Parameters:
      state - the state of the fluid
      reader - the reader that can get the fluid
      pos - the location of the fluid
      Returns:
      true if the fluid can create a source, false otherwise
    • getBlockPathType

      @Nullable public @Nullable BlockPathTypes 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. When null, uses vanilla behavior.
      Parameters:
      state - the state of the fluid
      level - the level which contains this fluid
      pos - the position of the fluid
      mob - the mob currently pathfinding, may be null
      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 BlockPathTypes getAdjacentBlockPathType(FluidState state, BlockGetter level, BlockPos pos, @Nullable @Nullable Mob mob, BlockPathTypes 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. When null, uses vanilla behavior.
      Parameters:
      state - the state of the fluid
      level - the level which contains this fluid
      pos - the position of the fluid
      mob - the mob currently pathfinding, may be null
      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 be null.
      Parameters:
      player - the player listening to the sound
      getter - the getter which can get the fluid
      pos - the position of the fluid
      action - 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 fluid
      getter - the getter which can get the fluid
      pos - the position of the fluid
      source - the state of the block being hydrated
      sourcePos - the position of the block being hydrated
      Returns:
      true if the block can be hydrated, false otherwise
    • getLightLevel

      public int getLightLevel(FluidState state, BlockAndTintGetter getter, BlockPos pos)
      Returns the light level emitted by the fluid.

      Note: This should be a value between [0,15]. If not specified, the light level is 0 as most fluids do not emit light.

      Parameters:
      state - the state of the fluid
      getter - the getter which can get the fluid
      pos - the position of the fluid
      Returns:
      the light level emitted by the fluid
    • getDensity

      public int getDensity(FluidState state, BlockAndTintGetter getter, BlockPos pos)
      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 fluid
      getter - the getter which can get the fluid
      pos - the position of the fluid
      Returns:
      the density of the fluid
    • getTemperature

      public int getTemperature(FluidState state, BlockAndTintGetter getter, BlockPos pos)
      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 fluid
      getter - the getter which can get the fluid
      pos - the position of the fluid
      Returns:
      the temperature of the fluid
    • getViscosity

      public int getViscosity(FluidState state, BlockAndTintGetter getter, BlockPos pos)
      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 fluid
      getter - the getter which can get the fluid
      pos - the position of the fluid
      Returns:
      the viscosity of the fluid
    • canConvertToSource

      public boolean canConvertToSource(FluidStack stack)
      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

      @Nullable public @Nullable SoundEvent getSound(FluidStack stack, SoundAction action)
      Returns a sound to play when a certain action is performed. If no sound is present, then the sound will be null.
      Parameters:
      stack - the stack holding the fluid
      action - the action being performed
      Returns:
      the sound to play when performing the action
    • getDescription

      public Component getDescription(FluidStack stack)
      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

      public String getDescriptionId(FluidStack stack)
      Returns the identifier representing the name of the fluid. If no identifier was specified, then the identifier will be defaulted to fluid_type.<modid>.<registry_name>.
      Parameters:
      stack - the stack holding the fluid
      Returns:
      the identifier representing the name of the fluid
    • canHydrate

      public boolean canHydrate(FluidStack stack)
      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

      public int getLightLevel(FluidStack stack)
      Returns the light level emitted by the fluid.

      Note: This should be a value between [0,15]. If not specified, the light level is 0 as most fluids do not emit light.

      Parameters:
      stack - the stack holding the fluid
      Returns:
      the light level emitted by the fluid
    • getDensity

      public int getDensity(FluidStack stack)
      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

      public int getTemperature(FluidStack stack)
      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

      public int getViscosity(FluidStack stack)
      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

      public Rarity getRarity(FluidStack stack)
      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

      public ItemStack getBucket(FluidStack stack)
      Returns the bucket containing the fluid.
      Parameters:
      stack - the stack holding the fluid
      Returns:
      the bucket containing the fluid
    • getBlockForFluidState

      public BlockState getBlockForFluidState(BlockAndTintGetter getter, BlockPos pos, FluidState state)
      Returns the associated BlockState for a FluidState.
      Parameters:
      getter - the getter which can get the level data
      pos - the position of where the fluid would be
      state - the state of the fluid
      Returns:
      the BlockState of a fluid
    • getStateForPlacement

      public FluidState getStateForPlacement(BlockAndTintGetter getter, BlockPos pos, FluidStack stack)
      Returns the FluidState when a FluidStack is trying to place it.
      Parameters:
      getter - the getter which can get the level data
      pos - the position of where the fluid is being placed
      stack - the stack holding the fluid
      Returns:
      the FluidState being placed
    • canBePlacedInLevel

      public final boolean canBePlacedInLevel(BlockAndTintGetter getter, BlockPos pos, FluidState state)
      Returns whether the fluid can be placed in the level.
      Parameters:
      getter - the getter which can get the level data
      pos - the position of where the fluid is being placed
      state - the state of the fluid being placed
      Returns:
      true if the fluid can be placed, false otherwise
    • canBePlacedInLevel

      public final boolean canBePlacedInLevel(BlockAndTintGetter getter, BlockPos pos, FluidStack stack)
      Returns whether the fluid can be placed in the level.
      Parameters:
      getter - the getter which can get the level data
      pos - the position of where the fluid is being placed
      stack - 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 equal 0, 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

      public boolean isVaporizedOnPlacement(Level level, BlockPos pos, FluidStack stack)
      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 in
      pos - the position to place the fluid at
      stack - 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 be null for blocks like dispensers
      level - the level the fluid is vaporized in
      pos - the position the fluid is vaporized at
      stack - the stack holding the fluid being vaporized
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getRenderPropertiesInternal

      public Object getRenderPropertiesInternal()
    • initClient

      private void initClient()
    • initializeClient

      public void initializeClient(Consumer<IClientFluidTypeExtensions> consumer)