Fluids API
Each block can define a fluid it holds and a fill level.
Constants: fluid gravity
Defines the direction in which the fluid level decreases.
| Name | Description |
|---|---|
fluids.GRAVITY_DOWN | The fluid sticks to the bottom face of a block |
fluids.GRAVITY_UP | The fluid sticks to the top face of a block |
The figure shows the two cases. The fluid rests on the bottom face or on the top face of its cell.
Constant: null fluid
fluids.NULL_FLUID is an empty or non-existent fluid ID.
Functions
Function: fluids.add(name, def) -> integer
Registers a new fluid in the registry.
Arguments
nameis a namespaced fluid ID, egmymod:mywaterdefis a fluid definition table (see below)
Return value
Returns the numeric fluid ID.
Notes
Rename rule: on conflict, the engine adds a ~N suffix to the encroaching name. N is the smallest integer, starting at 1, that gives a free id (e.g. mymod:mywater~1). Loading stays deterministic for the same mod list and order.
Function: fluids.get(name) -> integer
Looks up a registered fluid by name.
Arguments
nameis a namespaced fluid ID, egmymod:mywater
Return value
- The numeric fluid ID
fluids.NULL_FLUIDif the fluid does not exist, or the registries have not committed yet
Fluid definition
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
gravity | integer | yes | N/D | One of fluids.GRAVITY_XXXX constants |
albedo | table | yes | N/D | Fluid albedo textures. still and flowing are both required, and masks is optional |
masks | table | no | {} | Fluid mask textures |
full_level | integer | yes | N/D | Level that counts as a full cell, from 1 to 15. The surface height is that many 1/16ths of a block |
physics | table | yes | N/D | Movement values inside the fluid (see below) |
opaque | boolean | no | false | If true, fluid quads use the blocks.RENDER_SOLID step instead of the fluid step |
tint | string | no | nil | Namespaced tint id |
fog_density | number | no | 1.0 | When the client camera is inside this fluid, the engine divides fog distance by this value. The engine clamps it to at least 1.0 |
fog_color | number[3] | no | {1,1,1} | When the client camera is inside this fluid, the engine replaces fog color with this value |
Fluid physics
The physics table holds the movement values that the engine uses while an entity is inside the fluid. Every field is required.
| Field | Type | Description |
|---|---|---|
drag | number | Multiplier on the velocity of the entity each fixed tick |
gravity_scale | number | Share of gravity that acts on the entity |
input_scale | number | Scale of the horizontal input |
swim_speed | number | Upward movement that the jump input adds each fixed tick |
climb_speed | number | Upward movement when the entity jumps against a wall |
flow_scale | number | Scale of the fluid flow that pushes the entity. The engine multiplies it by the submersion |
The built-in water uses these values:
physics = {
drag = 0.8,
gravity_scale = 0.0625,
input_scale = 0.02,
swim_speed = 0.04,
climb_speed = 0.3,
flow_scale = 0.014,
}
Fluid textures
- The engine assumes that every fluid animates. It does not randomize texture frames by world position.
- Fluids define only two hard-coded texture slots:
stillandflowing. - Texture syntax otherwise matches block definitions, both for albedo and for mask textures.