Class SimpleFluidRenderHandler
java.lang.Object
net.fabricmc.fabric.api.client.render.fluid.v1.SimpleFluidRenderHandler
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionprotected final net.minecraft.client.resources.model.sprite.SpriteIdprotected final net.minecraft.client.resources.model.sprite.SpriteIdprotected final net.minecraft.client.renderer.texture.TextureAtlasSprite[]protected final net.minecraft.client.resources.model.sprite.SpriteIdprotected final int -
Constructor Summary
ConstructorsConstructorDescriptionSimpleFluidRenderHandler(net.minecraft.client.resources.model.sprite.SpriteId stillTexture, net.minecraft.client.resources.model.sprite.SpriteId flowingTexture) Creates a fluid render handler without an overlay texture and no tint.SimpleFluidRenderHandler(net.minecraft.client.resources.model.sprite.SpriteId stillTexture, net.minecraft.client.resources.model.sprite.SpriteId flowingTexture, int tint) Creates a fluid render handler without an overlay texture and a custom, fixed tint.SimpleFluidRenderHandler(net.minecraft.client.resources.model.sprite.SpriteId stillTexture, net.minecraft.client.resources.model.sprite.SpriteId flowingTexture, @Nullable net.minecraft.client.resources.model.sprite.SpriteId overlayTexture, int tint) Creates a fluid render handler with an overlay texture and a custom, fixed tint.SimpleFluidRenderHandler(net.minecraft.client.resources.model.sprite.SpriteId stillTexture, net.minecraft.client.resources.model.sprite.SpriteId flowingTexture, net.minecraft.client.resources.model.sprite.SpriteId overlayTexture) Creates a fluid render handler with an overlay texture and no tint. -
Method Summary
Modifier and TypeMethodDescriptionstatic SimpleFluidRenderHandlercoloredWater(int tint) Creates a fluid render handler that uses the vanilla water texture with a fixed, custom color.intgetFluidColor(@Nullable net.minecraft.client.renderer.block.BlockAndTintGetter level, @Nullable net.minecraft.core.BlockPos pos, net.minecraft.world.level.material.FluidState state) Get the tint color for a fluid being rendered at a given position.net.minecraft.client.renderer.texture.TextureAtlasSprite[]getFluidSprites(@Nullable net.minecraft.client.renderer.block.BlockAndTintGetter level, @Nullable net.minecraft.core.BlockPos pos, net.minecraft.world.level.material.FluidState state) Get the sprites for a fluid being rendered at a given position.net.minecraft.client.renderer.chunk.ChunkSectionLayerreloadTextures(net.minecraft.client.resources.model.sprite.SpriteGetter spriteGetter) Look up your Fluid's sprites from the texture atlas.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface FluidRenderHandler
renderFluid
-
Field Details
-
stillTexture
protected final net.minecraft.client.resources.model.sprite.SpriteId stillTexture -
flowingTexture
protected final net.minecraft.client.resources.model.sprite.SpriteId flowingTexture -
overlayTexture
protected final net.minecraft.client.resources.model.sprite.SpriteId overlayTexture -
sprites
protected final net.minecraft.client.renderer.texture.TextureAtlasSprite[] sprites -
tint
protected final int tint
-
-
Constructor Details
-
SimpleFluidRenderHandler
public SimpleFluidRenderHandler(net.minecraft.client.resources.model.sprite.SpriteId stillTexture, net.minecraft.client.resources.model.sprite.SpriteId flowingTexture, @Nullable net.minecraft.client.resources.model.sprite.SpriteId 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(net.minecraft.client.resources.model.sprite.SpriteId stillTexture, net.minecraft.client.resources.model.sprite.SpriteId flowingTexture, net.minecraft.client.resources.model.sprite.SpriteId 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(net.minecraft.client.resources.model.sprite.SpriteId stillTexture, net.minecraft.client.resources.model.sprite.SpriteId 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(net.minecraft.client.resources.model.sprite.SpriteId stillTexture, net.minecraft.client.resources.model.sprite.SpriteId 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
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 net.minecraft.client.renderer.texture.TextureAtlasSprite[] getFluidSprites(@Nullable net.minecraft.client.renderer.block.BlockAndTintGetter level, @Nullable net.minecraft.core.BlockPos pos, net.minecraft.world.level.material.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 overrideFluidRenderHandler.reloadTextures(SpriteGetter)to reload your fluid sprites.The "fabric-textures" module contains sprite rendering facilities, which may come in handy here.
- Specified by:
getFluidSpritesin interfaceFluidRenderHandler- Parameters:
level- The level view pertaining to the fluid. May be null!pos- The position of the fluid in the level. 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 net.minecraft.client.renderer.chunk.ChunkSectionLayer reloadTextures(net.minecraft.client.resources.model.sprite.SpriteGetter spriteGetter) 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:
reloadTexturesin interfaceFluidRenderHandler- Parameters:
spriteGetter- TheSpriteGetterto look up sprites.- Returns:
- A
ChunkSectionLayerto indicate the transparency of the fluid.
-
getFluidColor
public int getFluidColor(@Nullable net.minecraft.client.renderer.block.BlockAndTintGetter level, @Nullable net.minecraft.core.BlockPos pos, net.minecraft.world.level.material.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:
getFluidColorin interfaceFluidRenderHandler- Parameters:
level- The level view pertaining to the fluid. May be null!pos- The position of the fluid in the level. May be null!state- The current state of the fluid.- Returns:
- The tint color of the fluid.
-