Rename all "liquid" mentions to "fluid"

This commit is contained in:
2026-10-25 13:54:53 -03:00
parent bcca8fa4a5
commit 0cfa4d9b4a
58 changed files with 547 additions and 548 deletions
+1 -1
View File
@@ -304,7 +304,7 @@ export class Client {
player.yaw,
player.pitch,
picked?.distance ?? player.block_interaction_range,
this.game_mode.held_item()?.targets_liquids,
this.game_mode.held_item()?.targets_fluids,
);
this.entity_hit = picked && !this.hit_result ? picked.entity : undefined;
}
+2 -2
View File
@@ -64,12 +64,12 @@ export abstract class Entity {
// in water, like the server's Entity.in_water
get in_water() {
return physics.in_water(this, (x, y, z) => this.level.is_liquid(x, y, z));
return physics.in_water(this, (x, y, z) => this.level.is_fluid(x, y, z));
}
// its eyes are in water
get eyes_in_water() {
return physics.eyes_in_water(this, this.eye_height, (x, y, z) => this.level.is_liquid(x, y, z));
return physics.eyes_in_water(this, this.eye_height, (x, y, z) => this.level.is_fluid(x, y, z));
}
// after moving each tick. full speed is 5 blocks per second, a bit faster than walking
+4 -4
View File
@@ -159,9 +159,9 @@ export class LocalPlayer extends Player {
this.drag = this.flying ? FLY_VERTICAL_DRAG : this.#in_water ? WATER_DRAG : LAND_DRAG;
if (this.swimming && this.#in_water) this.#steer(input);
if (!this.flying) {
physics.push_by_liquid(
physics.push_by_fluid(
this,
(x, y, z) => this.level.liquid_at(x, y, z),
(x, y, z) => this.level.fluid_at(x, y, z),
(x, y, z) => this.level.collision_shape(x, y, z),
true,
);
@@ -229,7 +229,7 @@ export class LocalPlayer extends Player {
// of leaping out of the water, unless it's holding jump
#steer(input: MoveInput) {
const look_y = Math.sin(this.pitch);
const head_in_water = this.level.is_liquid(
const head_in_water = this.level.is_fluid(
Math.floor(this.x),
Math.floor(this.y + this.height),
Math.floor(this.z),
@@ -259,7 +259,7 @@ export class LocalPlayer extends Player {
#hop_out_of_water(from_y: number) {
if (!this.colliding_x && !this.colliding_z) return;
const blocked = (x: number, y: number, z: number) =>
this.level.is_liquid(x, y, z) || this.level.collision_shape(x, y, z);
this.level.is_fluid(x, y, z) || this.level.collision_shape(x, y, z);
const dy = from_y - this.y + this.vy * TICK_DELTA + WATER_HOP_HEIGHT;
if (physics.box_is_free(this, this.vx * TICK_DELTA, dy, this.vz * TICK_DELTA, blocked)) this.vy = WATER_HOP;
}
+4 -4
View File
@@ -7,7 +7,7 @@ import type { Client } from "./client.ts";
import type { BlockHitResult } from "./level/client_level.ts";
import type { Container } from "$/common/inventory.ts";
import { AIR_ID } from "$/common/protocol.ts";
import { box_overlaps_block, can_place, liquid_block, placement_target, waterlog_placement } from "$/common/utils.ts";
import { box_overlaps_block, can_place, fluid_block, placement_target, waterlog_placement } from "$/common/utils.ts";
import { block_rules, predict_neighbors } from "./mods.ts";
import { collision_shape_at } from "$/common/block_shapes.ts";
import type { EntityJson } from "$/common/mod_data.ts";
@@ -83,11 +83,11 @@ export class MultiPlayerGameMode {
// the shared rules' on_interact, like a trapdoor opening, shows right away. the server runs them too and corrects
// this if it disagrees. when they do something nothing is placed, like on the server
// an item aimed at liquids, like a bucket, uses the liquid in a waterlogged block instead, like on the server
// an item aimed at fluids, like a bucket, uses the fluid in a waterlogged block instead, like on the server
const block_info = EverythingRegistry.get_by_id<BlockRegistry>("blocks", hit.block)!;
const held = this.held_item();
const value = level.get_block_value(hit.x, hit.y, hit.z);
const used = (held?.targets_liquids && liquid_block(value, block_info)) || block_info;
const used = (held?.targets_fluids && fluid_block(value, block_info)) || block_info;
// sneaking with an item skips the block, like on the server
const sneaking = this.client.player.holding_sneak;
const skips_block = sneaking && held !== undefined;
@@ -107,7 +107,7 @@ export class MultiPlayerGameMode {
const place_block = place_id !== undefined
? EverythingRegistry.get<BlockRegistry>("blocks", place_id)
: undefined;
// with the states the server will give it, see BlockRules.placement_value, and holding the liquid it goes into.
// with the states the server will give it, see BlockRules.placement_value, and holding the fluid it goes into.
// undefined when its rules say it can't go there
const ruled_value = place_block &&
block_rules.placement_value(place_block, this.client.player.yaw, this.client.player.pitch, {
+18 -18
View File
@@ -5,9 +5,9 @@ import {
block_value,
chunk_key,
default_block_value,
fluid_block,
fluid_in_cell,
is_waterlogged,
liquid_block,
liquid_in_cell,
} from "$/common/utils.ts";
import { AIR_ID } from "$/common/protocol.ts";
import { decode_level_chunk } from "$/common/chunk_streaming.ts";
@@ -17,7 +17,7 @@ import {
block_light_opacity,
BlockRegistry,
EverythingRegistry,
is_liquid_block,
is_fluid_block,
RENDER_LAYERS,
RenderLayer,
} from "$/common/everything_registry.ts";
@@ -376,18 +376,18 @@ export class ClientLevel {
.biome_colors[CHUNK_AREA * 2 + (z - chunk_z * CHUNK_SIZE) * CHUNK_SIZE + (x - chunk_x * CHUNK_SIZE)];
}
// the liquid there and how high it is, for liquids pushing things along. unloaded chunks have none
liquid_at(x: number, y: number, z: number) {
// the fluid there and how high it is, for fluids pushing things along. unloaded chunks have none
fluid_at(x: number, y: number, z: number) {
const value = this.get_block_value(x, y, z);
const nid = value & ID_MASK;
return nid === VOID || nid === AIR ? undefined : liquid_in_cell(value, this.#blocks[nid]);
return nid === VOID || nid === AIR ? undefined : fluid_in_cell(value, this.#blocks[nid]);
}
// water, or a block waterlogged with it, see liquid_block. unloaded chunks aren't
is_liquid(x: number, y: number, z: number) {
// water, or a block waterlogged with it, see fluid_block. unloaded chunks aren't
is_fluid(x: number, y: number, z: number) {
const value = this.get_block_value(x, y, z);
const block = value & ID_MASK;
return block !== VOID && block !== AIR && liquid_block(value, this.#blocks[block]) !== undefined;
return block !== VOID && block !== AIR && fluid_block(value, this.#blocks[block]) !== undefined;
}
// only changes what this client shows, drops and everything else happen on the server
@@ -409,13 +409,13 @@ export class ClientLevel {
const old_value = chunk.blocks[index];
const old_nid = old_value & ID_MASK;
const old_block = this.#blocks[old_nid];
// a waterlogged block leaves its liquid, like the server's destroy_block
const liquid = is_waterlogged(old_value, old_block)
// a waterlogged block leaves its fluid, like the server's destroy_block
const fluid = is_waterlogged(old_value, old_block)
? EverythingRegistry.get_id("blocks", old_block!.waterloggable!) ?? AIR
: AIR;
chunk.blocks[index] = liquid;
chunk.blocks[index] = fluid;
this.#mark_dirty(chunk);
this.#mark_neighbors_dirty(block_chunk_x, block_chunk_z, lx, lz, old_nid, liquid);
this.#mark_neighbors_dirty(block_chunk_x, block_chunk_z, lx, lz, old_nid, fluid);
}
// a block that lets through or gives off a different amount of light changes the light up to 15 blocks
@@ -774,7 +774,7 @@ export class ClientLevel {
// the first block along the view of something at x/y/z looking at yaw/pitch, like minecraft's pick. it has to go
// into one of the block's boxes (see common/block_shapes.ts), so it looks past the empty half of a slab. it looks
// through liquids unless liquids is set, see ItemRegistry.targets_liquids
// through fluids unless fluids is set, see ItemRegistry.targets_fluids
pick(
x: number,
y: number,
@@ -782,7 +782,7 @@ export class ClientLevel {
yaw: number,
pitch: number,
max_distance = 6,
liquids = false,
fluids = false,
step = 0.05,
): BlockHitResult | undefined {
const cos_pitch = Math.cos(pitch);
@@ -812,11 +812,11 @@ export class ClientLevel {
continue;
}
const info = this.#blocks[block];
if (!liquids && is_liquid_block(info)) {
if (!fluids && is_fluid_block(info)) {
continue;
}
// aimed at liquids, the source in a waterlogged block covers it, like the server's raycast_shape
const covered = liquids && is_waterlogged(value, info);
// aimed at fluids, the source in a waterlogged block covers it, like the server's raycast_shape
const covered = fluids && is_waterlogged(value, info);
const hit = clip_shape(
!info || covered ? FULL_SHAPE : shape_at(info, value),
bx,
+1 -1
View File
@@ -53,7 +53,7 @@ export class GameRenderer {
#render_underwater(client: Client) {
const { x, y, z } = client.camera;
const [bx, by, bz] = [Math.floor(x), Math.floor(y), Math.floor(z)];
if (!client.level.is_liquid(bx, by, bz)) return;
if (!client.level.is_fluid(bx, by, bz)) return;
const color = client.level.water_color(bx, bz);
draw_rect(0, 0, canvas.width, canvas.height, [
(color >> 16) / 255,
+59 -59
View File
@@ -55,8 +55,8 @@ import {
region_sky,
REGION_VOID,
} from "./lighting.ts";
import { cell_index, liquid_quads, type LiquidCell } from "./liquid_mesh.ts";
import { liquid_height, liquid_textures } from "$/common/everything_registry.ts";
import { cell_index, fluid_quads, type FluidCell } from "./fluid_mesh.ts";
import { fluid_height, fluid_textures } from "$/common/everything_registry.ts";
type TexturesInfo = Record<string, SpriteRegion>;
@@ -94,11 +94,11 @@ const block_occludes = new Uint8Array(TABLE_SIZE);
// light can come around a corner past it
const block_lets_light_by = new Uint8Array(TABLE_SIZE);
const light_tables: LightTables = { opacity: new Uint8Array(TABLE_SIZE), emission: new Uint8Array(TABLE_SIZE) };
// liquids: their range, 0 for blocks that aren't one, and where their level state is in the state bits
const liquid_range = new Uint8Array(TABLE_SIZE);
const liquid_level_shift = new Uint8Array(TABLE_SIZE);
// waterloggable blocks: the numeric id of the liquid they hold, 0 for other blocks, and where their waterlogged state is
const waterlog_liquid = new Uint16Array(TABLE_SIZE);
// fluids: their range, 0 for blocks that aren't one, and where their level state is in the state bits
const fluid_range = new Uint8Array(TABLE_SIZE);
const fluid_level_shift = new Uint8Array(TABLE_SIZE);
// waterloggable blocks: the numeric id of the fluid they hold, 0 for other blocks, and where their waterlogged state is
const waterlog_fluid = new Uint16Array(TABLE_SIZE);
const waterlogged_shift = new Uint8Array(TABLE_SIZE);
// blocks with visuals: HAS_VISUAL, or REPLACED_MODEL when the visual draws all of it, see ctx.render.register_visual
const block_visual = new Uint8Array(TABLE_SIZE);
@@ -275,7 +275,7 @@ function build_block_tables() {
// the registry has gaps, which forEach skips
const nids = new Map<string, number>();
blocks_registry.forEach((block, nid) => block && nids.set(block.id, nid));
waterlog_liquid.fill(0);
waterlog_fluid.fill(0);
blocks_registry.forEach((block, nid) => {
if (!block || nid === AIR) return;
const layer = LAYER_IDS[block.render_layer ?? "solid"];
@@ -286,13 +286,13 @@ function build_block_tables() {
block_lets_light_by[nid] = layer !== SOLID || opacity === 0 ? 1 : 0;
light_tables.opacity[nid] = opacity;
light_tables.emission[nid] = block_light_emission(block);
liquid_range[nid] = block.liquid?.range ?? 0;
if (block.liquid) {
fluid_range[nid] = block.fluid?.range ?? 0;
if (block.fluid) {
// the level state is the last one, see block_from_json
liquid_level_shift[nid] = (block.states ?? []).slice(0, -1).reduce((bits, state) => bits + state.bits, 0);
fluid_level_shift[nid] = (block.states ?? []).slice(0, -1).reduce((bits, state) => bits + state.bits, 0);
}
if (block.waterloggable) {
waterlog_liquid[nid] = nids.get(block.waterloggable) ?? 0;
waterlog_fluid[nid] = nids.get(block.waterloggable) ?? 0;
// the waterlogged state is the last one, see block_from_json
waterlogged_shift[nid] = (block.states ?? []).slice(0, -1).reduce((bits, state) => bits + state.bits, 0);
}
@@ -538,8 +538,8 @@ function light_quad(quad: MeshQuad, index: number, y: number, face_offsets: numb
corner_ao.fill(1);
}
// whether a block hides the face of a liquid against it, like show_face. air's layer isn't set, so it's checked first
function hides_liquid(nid: number) {
// whether a block hides the face of a fluid against it, like show_face. air's layer isn't set, so it's checked first
function hides_fluid(nid: number) {
return nid !== AIR && block_layers[nid] === SOLID;
}
@@ -553,62 +553,62 @@ function region_value(chunks: (Uint32Array | null)[], index: number, y: number)
return chunk ? chunk[y * CHUNK_AREA + (z % CHUNK_SIZE) * CHUNK_SIZE + (x % CHUNK_SIZE)] : AIR;
}
// the surface of the liquid with this numeric id in a cell, if the cell is that liquid
function liquid_cell_height(nid: number, value: number) {
const level = ((value >>> 16) >>> liquid_level_shift[nid]) & 7;
return liquid_height(level, liquid_range[nid]);
// the surface of the fluid with this numeric id in a cell, if the cell is that fluid
function fluid_cell_height(nid: number, value: number) {
const level = ((value >>> 16) >>> fluid_level_shift[nid]) & 7;
return fluid_height(level, fluid_range[nid]);
}
const liquid_cells: LiquidCell[] = Array.from(
const fluid_cells: FluidCell[] = Array.from(
{ length: 9 },
() => ({ same: false, height: 0, air: false, solid: false, top_same: false }),
);
// the numeric id of the liquid in a cell: the block, or what it's waterlogged with. 0 for none
function cell_liquid(chunks: (Uint32Array | null)[], index: number, y: number) {
// the numeric id of the fluid in a cell: the block, or what it's waterlogged with. 0 for none
function cell_fluid(chunks: (Uint32Array | null)[], index: number, y: number) {
const id = region_block(region, index, y);
if (liquid_range[id]) return id;
const liquid = waterlog_liquid[id];
if (!liquid) return 0;
return ((region_value(chunks, index, y) >>> 16) >>> waterlogged_shift[id]) & 1 ? liquid : 0;
if (fluid_range[id]) return id;
const fluid = waterlog_fluid[id];
if (!fluid) return 0;
return ((region_value(chunks, index, y) >>> 16) >>> waterlogged_shift[id]) & 1 ? fluid : 0;
}
// the 3x3 cells around the liquid at index and y, see LiquidCell. a waterlogged block is a source of its liquid
function fill_liquid_cells(chunks: (Uint32Array | null)[], nid: number, index: number, y: number) {
// the 3x3 cells around the fluid at index and y, see FluidCell. a waterlogged block is a source of its fluid
function fill_fluid_cells(chunks: (Uint32Array | null)[], nid: number, index: number, y: number) {
for (let dz = -1; dz <= 1; dz++) {
for (let dx = -1; dx <= 1; dx++) {
const cell = liquid_cells[cell_index(dx, dz)];
const cell = fluid_cells[cell_index(dx, dz)];
const at = index + dx + dz * REGION_SIZE;
const id = region_block(region, at, y);
cell.same = cell_liquid(chunks, at, y) === nid;
cell.height = !cell.same ? 0 : id === nid ? liquid_cell_height(nid, region_value(chunks, at, y)) : 1;
cell.same = cell_fluid(chunks, at, y) === nid;
cell.height = !cell.same ? 0 : id === nid ? fluid_cell_height(nid, region_value(chunks, at, y)) : 1;
cell.air = id === AIR;
cell.solid = hides_liquid(id);
cell.top_same = cell_liquid(chunks, at + REGION_LAYER, y + 1) === nid;
cell.solid = hides_fluid(id);
cell.top_same = cell_fluid(chunks, at + REGION_LAYER, y + 1) === nid;
}
}
return liquid_cells;
return fluid_cells;
}
// for a liquid with a flowing texture of its own, how much of it a block shows: as many pixels across as the still one,
// so minecraft's 32×32 flowing water next to its 16×16 still water shows half. see liquid_quads
// for a fluid with a flowing texture of its own, how much of it a block shows: as many pixels across as the still one,
// so minecraft's 32×32 flowing water next to its 16×16 still water shows half. see fluid_quads
function flowing_scale(block: BlockRegistry): number | undefined {
const textures = liquid_textures(block.textures);
const textures = fluid_textures(block.textures);
if (textures.flowing === textures.still) return undefined;
const still = textures_info[textures.still] ?? textures_info["engine:missing"];
const flowing = textures_info[textures.flowing] ?? textures_info["engine:missing"];
return Math.min(1, still.width / flowing.width);
}
// a liquid's quad for the mesher, see liquid_mesh.ts. it's lit like a full block's face on that side
function liquid_mesh_quad(
// a fluid's quad for the mesher, see fluid_mesh.ts. it's lit like a full block's face on that side
function fluid_mesh_quad(
block: BlockRegistry,
face: number,
positions: number[],
uvs: number[],
still: boolean,
): MeshQuad {
const textures = liquid_textures(block.textures);
const textures = fluid_textures(block.textures);
const flat = FACE_AXIS[face] !== 1 || (positions[1] === positions[4] && positions[4] === positions[7] &&
positions[7] === positions[10]);
return {
@@ -625,7 +625,7 @@ function liquid_mesh_quad(
};
}
// the liquid's surface seen from below, so it shows from under water: the top quad facing down, lit and shaded like
// the fluid's surface seen from below, so it shows from under water: the top quad facing down, lit and shaded like
// the top. its corners go the other way round, the lighting the mesher just worked out with them
const UNDERSIDE_CORNERS = [0, 3, 2, 1];
@@ -641,7 +641,7 @@ function underside(top: MeshQuad): MeshQuad {
// region has to be filled and lit first
// chunks are the 3x3 chunks' blocks with their states, the middle one's for models that change with them and the
// ones around it for liquids, whose surface follows their neighbors'
// ones around it for fluids, whose surface follows their neighbors'
function make_chunk_mesh(chunk_x: number, chunk_z: number, chunks: (Uint32Array | null)[], camera: number[]) {
const values = chunks[4]!;
// solid and cutout get a buffer per face group, translucent one for everything since it's sorted instead
@@ -707,36 +707,36 @@ function make_chunk_mesh(chunk_x: number, chunk_z: number, chunks: (Uint32Array
const layer_id = block_layers[block_nid];
const alpha = layer_id === TRANSLUCENT ? block_info.alpha ?? 1 : 1;
// the liquid here, the block's own or what it's waterlogged with, then the block in it
const liquid_nid = cell_liquid(chunks, index, y);
if (liquid_nid) {
const liquid_info = blocks_registry[liquid_nid];
const liquid_layer = block_layers[liquid_nid];
const liquid_alpha = liquid_layer === TRANSLUCENT ? liquid_info.alpha ?? 1 : 1;
const cells = fill_liquid_cells(chunks, liquid_nid, index, y);
// the fluid here, the block's own or what it's waterlogged with, then the block in it
const fluid_nid = cell_fluid(chunks, index, y);
if (fluid_nid) {
const fluid_info = blocks_registry[fluid_nid];
const fluid_layer = block_layers[fluid_nid];
const fluid_alpha = fluid_layer === TRANSLUCENT ? fluid_info.alpha ?? 1 : 1;
const cells = fill_fluid_cells(chunks, fluid_nid, index, y);
const above = region_block(region, index + REGION_LAYER, y + 1);
const below = region_block(region, index - REGION_LAYER, y - 1);
const quads = liquid_quads(
const quads = fluid_quads(
cells,
{
same: cell_liquid(chunks, index + REGION_LAYER, y + 1) === liquid_nid,
solid: hides_liquid(above),
same: cell_fluid(chunks, index + REGION_LAYER, y + 1) === fluid_nid,
solid: hides_fluid(above),
},
{
same: cell_liquid(chunks, index - REGION_LAYER, y - 1) === liquid_nid,
solid: hides_liquid(below),
same: cell_fluid(chunks, index - REGION_LAYER, y - 1) === fluid_nid,
solid: hides_fluid(below),
},
flowing_scale(liquid_info),
flowing_scale(fluid_info),
);
for (const { face, positions, uvs, still } of quads) {
const quad = liquid_mesh_quad(liquid_info, face, positions, uvs, still);
const quad = fluid_mesh_quad(fluid_info, face, positions, uvs, still);
light_quad(quad, index, y, face_offsets);
// like minecraft's liquids, no ambient occlusion
// like minecraft's fluids, no ambient occlusion
corner_ao.fill(1);
emit(quad, liquid_layer, x, y, z, liquid_alpha);
if (face === 0) emit(underside(quad), liquid_layer, x, y, z, liquid_alpha);
emit(quad, fluid_layer, x, y, z, fluid_alpha);
if (face === 0) emit(underside(quad), fluid_layer, x, y, z, fluid_alpha);
}
if (liquid_nid === block_nid) continue;
if (fluid_nid === block_nid) continue;
}
const value = values[y * CHUNK_AREA + z * CHUNK_SIZE + x];
@@ -1,25 +1,25 @@
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
// SPDX-License-Identifier: AGPL-3.0-or-later
// liquids drawn like luanti's flowing liquids (MapblockMeshGenerator::drawLiquidNode in its content_mapblock.cpp): each
// corner of the surface is as high as the liquid around it, so it slopes down where it flows away from a source. the
// fluids drawn like luanti's flowing fluids (MapblockMeshGenerator::drawLiquidNode in its content_mapblock.cpp): each
// corner of the surface is as high as the fluid around it, so it slopes down where it flows away from a source. the
// sides between two cells of it are left out, except where it pours down past the surface of the one beside it
import { FACE_CORNERS } from "$/common/block_models.ts";
// one of the 3x3 cells around a liquid and level with it, and the cell above that one
export interface LiquidCell {
// the same liquid, at any level
// one of the 3x3 cells around a fluid and level with it, and the cell above that one
export interface FluidCell {
// the same fluid, at any level
same: boolean;
// its surface, 0 to 1, when it's the same liquid. 1 is a source
// its surface, 0 to 1, when it's the same fluid. 1 is a source
height: number;
air: boolean;
// hides the side of the liquid facing it, like a full block of stone
// hides the side of the fluid facing it, like a full block of stone
solid: boolean;
// the cell above it is the same liquid, so the liquid here goes right up to the top
// the cell above it is the same fluid, so the fluid here goes right up to the top
top_same: boolean;
}
export interface LiquidQuad {
export interface FluidQuad {
// the mesher's face index, see FACE_CORNERS
face: number;
// 4 corners in FACE_CORNERS' order, x y z in block space
@@ -36,15 +36,15 @@ const SHORE = 0.02;
// the horizontal neighbor each side faces, as dx dz, for faces 2 to 5: south (+z), north (-z), west (-x), east (+x)
const SIDE_DIRECTIONS = [[0, 1], [0, -1], [-1, 0], [1, 0]];
// cells indexed by (dz + 1) * 3 + (dx + 1), so 4 is the liquid itself
// cells indexed by (dz + 1) * 3 + (dx + 1), so 4 is the fluid itself
export function cell_index(dx: number, dz: number) {
return (dz + 1) * 3 + dx + 1;
}
// like luanti's getCornerLevel: the height of the surface at a corner (cx and cz are 0 or 1, which end of the cell),
// from the 4 cells that share it. a source or liquid above any of them makes it full, two of air pull it down to the
// floor, otherwise it's the average of the liquid among them
export function corner_height(cells: LiquidCell[], cx: number, cz: number) {
// from the 4 cells that share it. a source or fluid above any of them makes it full, two of air pull it down to the
// floor, otherwise it's the average of the fluid among them
export function corner_height(cells: FluidCell[], cx: number, cz: number) {
let sum = 0;
let count = 0;
let air = 0;
@@ -92,7 +92,7 @@ function quad(
still: boolean,
y_at: (x: number, top: number, z: number) => number,
uv_scale = 1,
): LiquidQuad {
): FluidQuad {
const positions: number[] = [];
const uvs: number[] = [];
for (const [x, top, z] of FACE_CORNERS[face]) {
@@ -104,9 +104,9 @@ function quad(
return { face, positions, uvs, still };
}
// the top of liquid flowing towards (flow_x, flow_z), like minecraft's LiquidBlockRenderer: the flowing texture turned
// the top of fluid flowing towards (flow_x, flow_z), like minecraft's LiquidBlockRenderer: the flowing texture turned
// so it runs downstream, a scale-sized square from its middle
function flowing_top(heights: number[], flow_x: number, flow_z: number, scale: number): LiquidQuad {
function flowing_top(heights: number[], flow_x: number, flow_z: number, scale: number): FluidQuad {
const angle = Math.atan2(flow_z, flow_x) - Math.PI / 2;
const cos = Math.cos(angle) * 16 * scale;
const sin = Math.sin(angle) * 16 * scale;
@@ -121,18 +121,18 @@ function flowing_top(heights: number[], flow_x: number, flow_z: number, scale: n
return { face: 0, positions, uvs, still: false };
}
// the quads of the liquid in the middle cell. above and below are the cells over and under it: whether they're the
// same liquid, and whether they're solid. flowing_scale is for a liquid with a flowing texture of its own, how much of
// the quads of the fluid in the middle cell. above and below are the cells over and under it: whether they're the
// same fluid, and whether they're solid. flowing_scale is for a fluid with a flowing texture of its own, how much of
// it a block shows, so it's as sharp as the still one (a 32×32 one next to a 16×16 still one shows half, like
// minecraft's water). with it, the sides show that much and a sloping top flows. without, the sides show all of the
// texture and the top is always still
export function liquid_quads(
cells: LiquidCell[],
export function fluid_quads(
cells: FluidCell[],
above: { same: boolean; solid: boolean },
below: { same: boolean; solid: boolean },
flowing_scale?: number,
): LiquidQuad[] {
const quads: LiquidQuad[] = [];
): FluidQuad[] {
const quads: FluidQuad[] = [];
// by corner, x then z
const heights = [
corner_height(cells, 0, 0),
@@ -152,7 +152,7 @@ export function liquid_quads(
if (top) return above.same ? 1 : height(x, z);
return neighbor.same ? height(x, z) : 0;
}, flowing_scale);
// a side with no height, where the liquid next to it is level with it
// a side with no height, where the fluid next to it is level with it
const p = side.positions;
if (p[1] === p[4] && p[4] === p[7] && p[7] === p[10]) return;
quads.push(side);