Class SimpleFluidRenderHandler

java.lang.Object
net.fabricmc.fabric.api.client.render.fluid.v1.SimpleFluidRenderHandler
All Implemented Interfaces:
FluidRenderHandler

public class SimpleFluidRenderHandler extends Object implements FluidRenderHandler
A simple fluid render handler that uses and loads sprites given by their identifiers. Most fluids don't need more than this. In fact, if a fluid just needs the vanilla water texture with a custom color, coloredWater(int) can be used to easily create a fluid render handler for that.

Note that it's assumed that the fluid textures are assumed to be registered to the blocks sprite atlas. If they are not, you have to manually register the fluid textures. The "fabric-textures" API may come in handy for that.

  • Field Details

    • WATER_STILL

      public static final Identifier WATER_STILL
      The vanilla still water texture identifier.
    • WATER_FLOWING

      public static final Identifier WATER_FLOWING
      The vanilla flowing water texture identifier.
    • WATER_OVERLAY

      public static final Identifier WATER_OVERLAY
      The vanilla water overlay texture identifier.
    • LAVA_STILL

      public static final Identifier LAVA_STILL
      The vanilla still lava texture identifier.
    • LAVA_FLOWING

      public static final Identifier LAVA_FLOWING
      The vanilla flowing lava texture identifier.
    • stillTexture

      protected final Identifier stillTexture
    • flowingTexture

      protected final Identifier flowingTexture
    • overlayTexture

      protected final Identifier overlayTexture
    • sprites

      protected final Sprite[] sprites
    • tint

      protected final int tint
  • Constructor Details

    • SimpleFluidRenderHandler

      public SimpleFluidRenderHandler(Identifier stillTexture, Identifier flowingTexture, @Nullable @Nullable Identifier overlayTexture, int tint)
      Creates a fluid render handler with an overlay texture and a custom, fixed tint.
      Parameters:
      stillTexture - The texture for still fluid.
      flowingTexture - The texture for flowing/falling fluid.
      overlayTexture - The texture behind glass, leaves and other registered transparent blocks.
      tint - The fluid color RGB. Alpha is ignored.
    • SimpleFluidRenderHandler

      public SimpleFluidRenderHandler(Identifier stillTexture, Identifier flowingTexture, Identifier overlayTexture)
      Creates a fluid render handler with an overlay texture and no tint.
      Parameters:
      stillTexture - The texture for still fluid.
      flowingTexture - The texture for flowing/falling fluid.
      overlayTexture - The texture behind glass, leaves and other registered transparent blocks.
    • SimpleFluidRenderHandler

      public SimpleFluidRenderHandler(Identifier stillTexture, Identifier flowingTexture, int tint)
      Creates a fluid render handler without an overlay texture and a custom, fixed tint.
      Parameters:
      stillTexture - The texture for still fluid.
      flowingTexture - The texture for flowing/falling fluid.
      tint - The fluid color RGB. Alpha is ignored.
    • SimpleFluidRenderHandler

      public SimpleFluidRenderHandler(Identifier stillTexture, Identifier flowingTexture)
      Creates a fluid render handler without an overlay texture and no tint.
      Parameters:
      stillTexture - The texture for still fluid.
      flowingTexture - The texture for flowing/falling fluid.
  • Method Details

    • coloredWater

      public static SimpleFluidRenderHandler coloredWater(int tint)
      Creates a fluid render handler that uses the vanilla water texture with a fixed, custom color.
      Parameters:
      tint - The fluid color RGB. Alpha is ignored.
      See Also:
    • getFluidSprites

      public Sprite[] getFluidSprites(@Nullable @Nullable BlockRenderView view, @Nullable @Nullable BlockPos pos, FluidState state)
      Get the sprites for a fluid being rendered at a given position. For optimal performance, the sprites should be loaded as part of a resource reload and *not* looked up every time the method is called! You likely want to override FluidRenderHandler.reloadTextures(net.minecraft.client.texture.SpriteAtlasTexture) to reload your fluid sprites.

      The "fabric-textures" module contains sprite rendering facilities, which may come in handy here.

      Specified by:
      getFluidSprites in interface FluidRenderHandler
      Parameters:
      view - The world view pertaining to the fluid. May be null!
      pos - The position of the fluid in the world. May be null!
      state - The current state of the fluid.
      Returns:
      An array of size two or more: the first entry contains the "still" sprite, while the second entry contains the "flowing" sprite. If it contains a third sprite, that sprite is used as overlay behind glass and leaves.
    • reloadTextures

      public void reloadTextures(SpriteAtlasTexture textureAtlas)
      Look up your Fluid's sprites from the texture atlas. Called when the fluid renderer reloads its textures. This is a convenient way of reloading and does not require an advanced resource manager reload listener.

      The "fabric-textures" module contains sprite rendering facilities, which may come in handy here.

      Specified by:
      reloadTextures in interface FluidRenderHandler
      Parameters:
      textureAtlas - The blocks texture atlas, provided for convenience.
    • getFluidColor

      public int getFluidColor(@Nullable @Nullable BlockRenderView view, @Nullable @Nullable BlockPos pos, FluidState state)
      Get the tint color for a fluid being rendered at a given position.

      Note: As of right now, our hook cannot handle setting a custom alpha tint here - as such, it must be contained in the texture itself!

      Specified by:
      getFluidColor in interface FluidRenderHandler
      Parameters:
      view - The world view pertaining to the fluid. May be null!
      pos - The position of the fluid in the world. May be null!
      state - The current state of the fluid.
      Returns:
      The tint color of the fluid.