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
+5 -5
View File
@@ -4,7 +4,7 @@
// block models, in the shape of minecraft's block model json: boxes ("elements") with a texture per face.
// a block picks one with "model" and fills in its texture variables with "textures". baking turns a model
// into quads in block space (0 to 1) that the chunk mesher and the item renderers draw
import { type BlockRegistry, type BlockTextures, liquid_textures } from "./everything_registry.ts";
import { type BlockRegistry, type BlockTextures, fluid_textures } from "./everything_registry.ts";
import { tint_without_biome } from "./worldgen/biome_colors.ts";
import { get_state_value } from "./utils.ts";
import { type DisplayContext, MODEL_FACES, type ModelFace } from "./mod_data.ts";
@@ -365,12 +365,12 @@ export function cube_face_texture(block: BlockRegistry, face: "top" | "bottom" |
return resolve_texture(`#${face}`, cube_textures(block), BUILTIN_MODELS[DEFAULT_MODEL]);
}
// the block's textures as engine:cube's. a liquid's { still, flowing } are its top and bottom, and its sides, for its
// item and its particles. the chunk mesher draws liquids itself
// the block's textures as engine:cube's. a fluid's { still, flowing } are its top and bottom, and its sides, for its
// item and its particles. the chunk mesher draws fluids itself
export function cube_textures(block: BlockRegistry): BlockTextures {
if (!block.liquid) return block.textures;
if (!block.fluid) return block.textures;
// through the variables, so a "tint" on still or flowing still finds them
return { ...liquid_textures(block.textures), top: "#still", bottom: "#still", side: "#flowing" };
return { ...fluid_textures(block.textures), top: "#still", bottom: "#still", side: "#flowing" };
}
// the color to draw a face of a block's item in, as r g b from 0 to 1. items aren't in a biome, so a biome "tint"
+20 -20
View File
@@ -160,20 +160,20 @@ export interface BlockRegistry {
// draws the item a server script gives it (ServerWorld.set_block_item) on top of it, like farmer's delight's
// cutting board. surface is the height in pixels it lies on. turned with the variant's y
item_display?: { surface: number };
// a liquid like water, drawn like luanti's: its top slopes down towards where it flows. see LiquidProperties
liquid?: LiquidProperties;
// the liquid it can hold, like minecraft's waterlogged fences. it gets a "waterlogged" state, see WATERLOGGED
// a fluid like water, drawn like luanti's: its top slopes down towards where it flows. see FluidProperties
fluid?: FluidProperties;
// the fluid it can hold, like minecraft's waterlogged fences. it gets a "waterlogged" state, see WATERLOGGED
waterloggable?: string;
// it can only be placed into a source of that liquid, so it's always placed holding it, like farmer's delight's rice
// it can only be placed into a source of that fluid, so it's always placed holding it, like farmer's delight's rice
waterlogged_only?: boolean;
compiled_states?: CompiledStateDefinition[];
}
// a liquid's "level" state is 0 for a source, the full block, and 1 to range as it flows away from one, each lower,
// like minecraft's. liquids get that state without listing it. their textures are one texture, or { still, flowing }:
// a fluid's "level" state is 0 for a source, the full block, and 1 to range as it flows away from one, each lower,
// like minecraft's. fluids get that state without listing it. their textures are one texture, or { still, flowing }:
// still on the top and bottom, flowing on the sides, like luanti's special tiles
export interface LiquidProperties {
export interface FluidProperties {
// how many blocks it flows from a source, 1 to 7, like luanti's liquid_range
range: number;
// ticks between each step it flows, like minecraft's 5 for water and 30 for lava
@@ -183,28 +183,28 @@ export interface LiquidProperties {
renewable: boolean;
}
export const LIQUID_LEVEL: BlockStateDefinition = { name: "level", bits: 3, default: 0 };
// a waterloggable block's state, 1 while it holds a source of its liquid. blocks get it without listing it, after
export const FLUID_LEVEL: BlockStateDefinition = { name: "level", bits: 3, default: 0 };
// a waterloggable block's state, 1 while it holds a source of its fluid. blocks get it without listing it, after
// their own states
export const WATERLOGGED: BlockStateDefinition = { name: "waterlogged", bits: 1, default: 0 };
export const MAX_LIQUID_RANGE = 7;
// what a liquid that doesn't say has
export const LIQUID_DEFAULTS: LiquidProperties = { range: MAX_LIQUID_RANGE, ticks: 5, renewable: true };
export const MAX_FLUID_RANGE = 7;
// what a fluid that doesn't say has
export const FLUID_DEFAULTS: FluidProperties = { range: MAX_FLUID_RANGE, ticks: 5, renewable: true };
// what entities swim in, and where falling doesn't hurt
export function is_liquid_block(block: BlockRegistry | undefined): boolean {
return block?.liquid !== undefined;
export function is_fluid_block(block: BlockRegistry | undefined): boolean {
return block?.fluid !== undefined;
}
// a liquid's textures as the top, bottom and sides of a cube, for its item and its particles
export function liquid_textures(textures: BlockTextures): { still: string; flowing: string } {
// a fluid's textures as the top, bottom and sides of a cube, for its item and its particles
export function fluid_textures(textures: BlockTextures): { still: string; flowing: string } {
if (typeof textures === "string") return { still: textures, flowing: textures };
const still = textures.still ?? "engine:missing";
return { still, flowing: textures.flowing ?? still };
}
// how high a liquid's surface is in a block of it at this level, 0 to 1, like luanti's flowing levels
export function liquid_height(level: number, range: number) {
// how high a fluid's surface is in a block of it at this level, 0 to 1, like luanti's flowing levels
export function fluid_height(level: number, range: number) {
if (level === 0) return 1;
return (range - Math.min(level, range) + 0.5) / range;
}
@@ -264,9 +264,9 @@ export interface ItemRegistry<T = unknown | undefined> {
lore?: string;
food?: FoodProperties;
worn?: WornProperties;
// whether players holding it aim at liquids, like buckets and fishing rods. others look through them, so they can
// whether players holding it aim at fluids, like buckets and fishing rods. others look through them, so they can
// break and place blocks under water
targets_liquids?: boolean;
targets_fluids?: boolean;
components?: Record<string, unknown>;
on_create?(item: ItemStack<T>): void;
+5 -5
View File
@@ -301,9 +301,9 @@ export interface ServerWorld {
// the first block on the line from one point to another, like minecraft's Level.clip. it hits what entities bump
// into, so it goes through plants and other blocks without collision. undefined when nothing is in the way
raycast(from: Position, to: Position, options?: RaycastOptions): RaycastHit | undefined;
// which way the liquid at x y z flows, a vector 1 long, or 0 0 0 where it's still or there's none, like minecraft's
// which way the fluid at x y z flows, a vector 1 long, or 0 0 0 where it's still or there's none, like minecraft's
// FluidState.getFlow: toward lower cells of it beside it, and down where it falls. for what it pushes, like a wheel
liquid_flow(x: number, y: number, z: number): Position;
fluid_flow(x: number, y: number, z: number): Position;
// whether the chunk the column is in was ever generated, so reading its blocks generates nothing. for code that
// reaches far, like a walk along something long, which can stop at the rest: nobody has built anything there
is_loaded(x: number, z: number): boolean;
@@ -350,9 +350,9 @@ export interface BreakOptions {
}
export interface RaycastOptions {
// like minecraft's ClipContext.Fluid: "none" (the default) goes through liquids, "source_only" hits their sources
// and goes through where they flow, "any" hits all of them. a liquid is hit at its surface
liquids?: "none" | "source_only" | "any";
// like minecraft's ClipContext.Fluid: "none" (the default) goes through fluids, "source_only" hits their sources
// and goes through where they flow, "any" hits all of them. a fluid is hit at its surface
fluids?: "none" | "source_only" | "any";
}
export interface RaycastHit {
+4 -4
View File
@@ -160,7 +160,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
const entity_model_jsons = new Map<string, EntityModelJson>();
const effect_owners = new Map<string, string[]>();
const tag_owners = new Map<TagRegistry, Set<string>>();
const liquids = new Set<string>();
const fluids = new Set<string>();
const loot_tables = new Set<string>();
const biome_owners = new Map<string, string[]>();
const add = (map: Map<string, string[]>, id: string, mod: string) => map.set(id, [...(map.get(id) ?? []), mod]);
@@ -181,7 +181,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
for (const { json } of mod.blocks) {
add(block_owners, json.id, mod.id);
if (json.item !== false) add(item_owners, json.id, mod.id);
if (json.liquid) liquids.add(json.id);
if (json.fluid) fluids.add(json.id);
}
// one without a texture is the item of the mod's block, which is already counted
for (const { json } of mod.items) if (json.texture !== undefined) add(item_owners, json.id, mod.id);
@@ -279,8 +279,8 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
if (json.loot_table) uses(file, json.loot_table, "loot table");
if (json.waterloggable) {
uses(file, json.waterloggable, "block");
if (block_owners.has(json.waterloggable) && !liquids.has(json.waterloggable)) {
errors.push(`${file}: waterloggable ${json.waterloggable} isn't a liquid`);
if (block_owners.has(json.waterloggable) && !fluids.has(json.waterloggable)) {
errors.push(`${file}: waterloggable ${json.waterloggable} isn't a fluid`);
}
}
for (const id of [...(json.place_on ?? []), ...(json.place_in ?? [])]) {
+41 -41
View File
@@ -8,12 +8,12 @@ import { is_tint_color, type TintColor } from "./worldgen/biome_colors.ts";
import {
type BlockRegistry,
type BlockStateDefinition,
FLUID_DEFAULTS,
FLUID_LEVEL,
type FluidProperties,
type FoodProperties,
type ItemRegistry,
LIQUID_DEFAULTS,
LIQUID_LEVEL,
type LiquidProperties,
MAX_LIQUID_RANGE,
MAX_FLUID_RANGE,
RENDER_LAYERS,
type RenderLayer,
type ToolProperties,
@@ -119,11 +119,11 @@ export interface BlockJson {
states?: BlockStateDefinition[];
components?: Record<string, unknown>;
item_display?: { surface: number };
// makes it a liquid, see LiquidProperties. range is 7 when not set
liquid?: Partial<LiquidProperties>;
// makes it a fluid, see FluidProperties. range is 7 when not set
fluid?: Partial<FluidProperties>;
// what it drops when broken, see common/loot.ts. drops is the shorthand for one of an item
loot_table?: string;
// the liquid it can hold, see BlockRegistry.waterloggable
// the fluid it can hold, see BlockRegistry.waterloggable
waterloggable?: string;
// only placed into a source of it, see BlockRegistry.waterlogged_only
waterlogged_only?: boolean;
@@ -198,8 +198,8 @@ const block_fields = z.object({
components: json_object.optional(),
// the height in pixels items lie on
item_display: z.object({ surface: z.number().min(0).max(16) }).optional(),
liquid: z.strictObject({
range: z.int().min(1).max(MAX_LIQUID_RANGE).optional(),
fluid: z.strictObject({
range: z.int().min(1).max(MAX_FLUID_RANGE).optional(),
ticks: z.int().min(1).optional(),
renewable: z.boolean().optional(),
}, "must be { range, ticks, renewable }, or {}").optional(),
@@ -210,8 +210,8 @@ const block_fields = z.object({
const block_schema: z.ZodType<BlockJson> = block_fields.superRefine(check_block);
// what a liquid's and a plain cube's textures can be, past being ids
const liquid_textures = z.union([z.string(), z.strictObject({ still: z.string(), flowing: z.string().optional() })]);
// what a fluid's and a plain cube's textures can be, past being ids
const fluid_textures = z.union([z.string(), z.strictObject({ still: z.string(), flowing: z.string().optional() })]);
const cube_textures = z.union([
z.string(),
z.object({ top: z.string(), bottom: z.string(), side: z.string() }),
@@ -237,18 +237,18 @@ function check_block(block: z.infer<typeof block_fields>, ctx: z.RefinementCtx)
if (part.when !== undefined) check_condition(["parts", i, "when"], part.when);
});
if (block.liquid) {
// a liquid is drawn by the engine, so it has no model of its own, and its level is a state it gets
if (!liquid_textures.safeParse(block.textures).success) {
problem(["textures"], "must be a texture id or { still, flowing } for a liquid");
if (block.fluid) {
// a fluid is drawn by the engine, so it has no model of its own, and its level is a state it gets
if (!fluid_textures.safeParse(block.textures).success) {
problem(["textures"], "must be a texture id or { still, flowing } for a fluid");
}
for (const key of ["model", "variants", "parts", "shape", "collision_shape", "item_model"] as const) {
if (block[key] !== undefined) problem([key], "isn't for liquids, the engine draws them");
if (block[key] !== undefined) problem([key], "isn't for fluids, the engine draws them");
}
if (names.has(LIQUID_LEVEL.name)) {
problem(["states"], `can't have "${LIQUID_LEVEL.name}", a liquid gets that state of its own`);
if (names.has(FLUID_LEVEL.name)) {
problem(["states"], `can't have "${FLUID_LEVEL.name}", a fluid gets that state of its own`);
}
if (block.waterloggable !== undefined) problem(["waterloggable"], "isn't for liquids");
if (block.waterloggable !== undefined) problem(["waterloggable"], "isn't for fluids");
} else if (block.parts === undefined && (block.model ?? "engine:cube") === "engine:cube") {
if (!cube_textures.safeParse(block.textures).success) {
problem(["textures"], "must be a texture id, { top, bottom, side } or { front, side }");
@@ -259,10 +259,10 @@ function check_block(block: z.infer<typeof block_fields>, ctx: z.RefinementCtx)
problem(["states"], `can't have "${WATERLOGGED.name}", a waterloggable block gets that state of its own`);
}
if (block.waterlogged_only && block.waterloggable === undefined) {
problem(["waterlogged_only"], "needs waterloggable, the liquid it's placed into");
problem(["waterlogged_only"], "needs waterloggable, the fluid it's placed into");
}
// a block's states fit in 16 bits, with the one it gets for being a liquid or waterloggable
const added = block.liquid ? LIQUID_LEVEL : block.waterloggable !== undefined ? WATERLOGGED : undefined;
// a block's states fit in 16 bits, with the one it gets for being a fluid or waterloggable
const added = block.fluid ? FLUID_LEVEL : block.waterloggable !== undefined ? WATERLOGGED : undefined;
const bits = states.reduce((sum, state) => sum + state.bits, added?.bits ?? 0);
if (bits > 16) problem(["states"], `use ${bits} bits${added ? ` with ${added.name}` : ""}, the most is 16`);
if (block.drops !== undefined && block.loot_table !== undefined) {
@@ -365,8 +365,8 @@ export interface ItemJson {
food?: FoodProperties;
// how it looks worn on a player
worn?: WornProperties;
// see ItemRegistry.targets_liquids
targets_liquids?: boolean;
// see ItemRegistry.targets_fluids
targets_fluids?: boolean;
name?: string;
lore?: string;
components?: Record<string, unknown>;
@@ -399,7 +399,7 @@ const item_schema: z.ZodType<ItemJson> = z.object({
slim_model: id.optional(),
slim_texture: id.optional(),
}, "must be { model, texture }, an entity model and a texture").optional(),
targets_liquids: z.boolean().optional(),
targets_fluids: z.boolean().optional(),
name: text.optional(),
lore: text.optional(),
components: json_object.optional(),
@@ -629,8 +629,8 @@ export function block_to_json(block: BlockRegistry, has_item: boolean): BlockJso
if (block.light_emission !== undefined) json.light_emission = block.light_emission;
if (block.light_opacity !== undefined) json.light_opacity = block.light_opacity;
if (block.alpha !== undefined) json.alpha = block.alpha;
// liquids are without collision and replaceable unless they say otherwise
if (block.has_collision === !!block.liquid) json.collision = block.has_collision;
// fluids are without collision and replaceable unless they say otherwise
if (block.has_collision === !!block.fluid) json.collision = block.has_collision;
if (block.shape !== undefined) json.shape = block.shape;
if (block.collision_shape !== undefined) json.collision_shape = block.collision_shape;
if (block.parts !== undefined) json.parts = block.parts;
@@ -646,22 +646,22 @@ export function block_to_json(block: BlockRegistry, has_item: boolean): BlockJso
if (!has_item) json.item = false;
if (block.interactive) json.interactive = true;
if (block.scrollable) json.scrollable = true;
if (!!block.replaceable !== !!block.liquid) json.replaceable = !!block.replaceable;
if (!!block.replaceable !== !!block.fluid) json.replaceable = !!block.replaceable;
if (block.place_on) json.place_on = block.place_on;
if (block.place_in) json.place_in = block.place_in;
// a liquid's level state and a waterloggable block's waterlogged state are its own, added when it loads
const added = block.liquid || block.waterloggable;
// a fluid's level state and a waterloggable block's waterlogged state are its own, added when it loads
const added = block.fluid || block.waterloggable;
const states = added ? block.states?.slice(0, -1) : block.states;
if (states && (states.length > 0 || !added)) json.states = states;
if (block.waterloggable) json.waterloggable = block.waterloggable;
if (block.waterlogged_only) json.waterlogged_only = true;
if (block.components) json.components = block.components;
if (block.item_display) json.item_display = block.item_display;
if (block.liquid) {
if (block.fluid) {
// only what isn't the default
const liquid = block.liquid;
json.liquid = Object.fromEntries(
Object.entries(liquid).filter(([key, value]) => LIQUID_DEFAULTS[key as keyof LiquidProperties] !== value),
const fluid = block.fluid;
json.fluid = Object.fromEntries(
Object.entries(fluid).filter(([key, value]) => FLUID_DEFAULTS[key as keyof FluidProperties] !== value),
);
}
return json;
@@ -671,7 +671,7 @@ export function block_from_json(json: BlockJson): { block: BlockRegistry; has_it
const block: BlockRegistry = {
id: json.id,
textures: json.textures,
has_collision: json.collision ?? !json.liquid,
has_collision: json.collision ?? !json.fluid,
};
if (json.name !== undefined) block.name = json.name;
if (json.model !== undefined) block.model = json.model;
@@ -697,16 +697,16 @@ export function block_from_json(json: BlockJson): { block: BlockRegistry; has_it
if (json.loot_table !== undefined) block.loot_table = json.loot_table;
if (json.interactive) block.interactive = true;
if (json.scrollable) block.scrollable = true;
if (json.replaceable ?? json.liquid) block.replaceable = true;
if (json.replaceable ?? json.fluid) block.replaceable = true;
if (json.place_on) block.place_on = json.place_on;
if (json.place_in) block.place_in = json.place_in;
if (json.states) block.states = json.states;
if (json.components) block.components = json.components;
if (json.item_display) block.item_display = json.item_display;
if (json.liquid) {
block.liquid = { ...LIQUID_DEFAULTS, ...json.liquid };
if (json.fluid) {
block.fluid = { ...FLUID_DEFAULTS, ...json.fluid };
// last, so the block's own states keep their bits
block.states = [...block.states ?? [], { ...LIQUID_LEVEL }];
block.states = [...block.states ?? [], { ...FLUID_LEVEL }];
}
if (json.waterlogged_only) block.waterlogged_only = true;
if (json.waterloggable) {
@@ -732,7 +732,7 @@ export function item_to_json(id: string, item: ItemRegistry): ItemJson {
if (item.base_sell_value !== undefined) json.base_sell_value = item.base_sell_value;
if (item.food !== undefined) json.food = item.food;
if (item.worn !== undefined) json.worn = item.worn;
if (item.targets_liquids !== undefined) json.targets_liquids = item.targets_liquids;
if (item.targets_fluids !== undefined) json.targets_fluids = item.targets_fluids;
if (item.name !== undefined) json.name = item.name;
if (item.lore !== undefined) json.lore = item.lore;
if (item.components) json.components = item.components;
@@ -760,7 +760,7 @@ function item_fields(json: ItemJson): Partial<ItemRegistry> {
if (json.base_sell_value !== undefined) item.base_sell_value = json.base_sell_value;
if (json.food !== undefined) item.food = json.food;
if (json.worn !== undefined) item.worn = json.worn;
if (json.targets_liquids !== undefined) item.targets_liquids = json.targets_liquids;
if (json.targets_fluids !== undefined) item.targets_fluids = json.targets_fluids;
if (json.name !== undefined) item.name = json.name;
if (json.lore !== undefined) item.lore = json.lore;
if (json.components) item.components = json.components;
+44 -44
View File
@@ -231,39 +231,39 @@ function overlaps_solid(min: number[], max: number[], is_solid: BlockCollision)
return false;
}
// in water like minecraft's wasTouchingWater, close enough: its feet or the middle of its box are in liquid
export function in_water(body: Body, is_liquid: (x: number, y: number, z: number) => boolean): boolean {
// in water like minecraft's wasTouchingWater, close enough: its feet or the middle of its box are in fluid
export function in_water(body: Body, is_fluid: (x: number, y: number, z: number) => boolean): boolean {
const x = Math.floor(body.x);
const z = Math.floor(body.z);
return is_liquid(x, Math.floor(body.y), z) || is_liquid(x, Math.floor(body.y + body.height / 2), z);
return is_fluid(x, Math.floor(body.y), z) || is_fluid(x, Math.floor(body.y + body.height / 2), z);
}
// its eyes are in liquid, so it can't breathe
// its eyes are in fluid, so it can't breathe
export function eyes_in_water(
body: Body,
eye_height: number,
is_liquid: (x: number, y: number, z: number) => boolean,
is_fluid: (x: number, y: number, z: number) => boolean,
): boolean {
return is_liquid(Math.floor(body.x), Math.floor(body.y + eye_height), Math.floor(body.z));
return is_fluid(Math.floor(body.x), Math.floor(body.y + eye_height), Math.floor(body.z));
}
// a liquid in a cell, for liquids pushing things along
export interface LiquidInCell {
// which liquid, its block's id. a liquid's flow only goes by cells of the same one
// a fluid in a cell, for fluids pushing things along
export interface FluidInCell {
// which fluid, its block's id. a fluid's flow only goes by cells of the same one
id: string;
// its surface, 0 to 1 (see liquid_height), not counting more of it above
// its surface, 0 to 1 (see fluid_height), not counting more of it above
height: number;
}
// the liquid in a cell, undefined for none
export type LiquidAt = (x: number, y: number, z: number) => LiquidInCell | undefined;
// the fluid in a cell, undefined for none
export type FluidAt = (x: number, y: number, z: number) => FluidInCell | undefined;
const HORIZONTAL = [[1, 0], [-1, 0], [0, 1], [0, -1]];
// blocks per second added each tick, minecraft's water 0.014 blocks per tick per tick
const LIQUID_PUSH = 0.014 * 20;
// moving slower than this sideways, a push is at least LIQUID_MIN_PUSH, so things still drift off flat-ish water
const LIQUID_STILL_SPEED = 0.003 * 20;
const LIQUID_MIN_PUSH = 0.0045 * 20;
const FLUID_PUSH = 0.014 * 20;
// moving slower than this sideways, a push is at least FLUID_MIN_PUSH, so things still drift off flat-ish water
const FLUID_STILL_SPEED = 0.003 * 20;
const FLUID_MIN_PUSH = 0.0045 * 20;
function blocks_motion(collision: boolean | Shape) {
return shape_of(collision).length > 0;
@@ -274,29 +274,29 @@ function normalized(x: number, y: number, z: number): [number, number, number] {
return length < 1e-5 ? [0, 0, 0] : [x / length, y / length, z / length];
}
// which way the liquid at x y z flows, a length 1 vector or nothing, like minecraft's FlowingFluid.getFlow: towards
// which way the fluid at x y z flows, a length 1 vector or nothing, like minecraft's FlowingFluid.getFlow: towards
// lower cells of it beside it, and towards drops where it pours over an edge. falling down a wall it goes down too
export function liquid_flow(
export function fluid_flow(
x: number,
y: number,
z: number,
liquid_at: LiquidAt,
fluid_at: FluidAt,
is_solid: BlockCollision,
): [number, number, number] {
const here = liquid_at(x, y, z);
const here = fluid_at(x, y, z);
if (!here) return [0, 0, 0];
let fx = 0;
let fz = 0;
for (const [dx, dz] of HORIZONTAL) {
const neighbor = liquid_at(x + dx, y, z + dz);
// another liquid doesn't change this one's flow
const neighbor = fluid_at(x + dx, y, z + dz);
// another fluid doesn't change this one's flow
if (neighbor && neighbor.id !== here.id) continue;
let drop = 0;
if (neighbor) {
drop = here.height - neighbor.height;
} else if (!blocks_motion(is_solid(x + dx, y, z + dz))) {
// an edge it pours over, onto more of itself
const below = liquid_at(x + dx, y - 1, z + dz);
const below = fluid_at(x + dx, y - 1, z + dz);
if (below?.id === here.id) drop = here.height - (below.height - 1);
}
fx += dx * drop;
@@ -306,7 +306,7 @@ export function liquid_flow(
// falling: flowing, not a source, with more of it above. a deep pool of sources isn't
let fy = 0;
if (here.height < 1 && liquid_at(x, y + 1, z)?.id === here.id) {
if (here.height < 1 && fluid_at(x, y + 1, z)?.id === here.id) {
const against_wall = HORIZONTAL.some(([dx, dz]) =>
blocks_motion(is_solid(x + dx, y, z + dz)) || blocks_motion(is_solid(x + dx, y + 1, z + dz))
);
@@ -315,10 +315,10 @@ export function liquid_flow(
return normalized(fx, fy, fz);
}
// liquid the body is in pushes it the way it flows, like minecraft's Entity.updateFluidHeightAndDoFluidPushing: the
// fluid the body is in pushes it the way it flows, like minecraft's Entity.updateFluidHeightAndDoFluidPushing: the
// flow of every cell of it the box reaches, averaged, weaker where it's shallow. players get that average as it is,
// other things are pushed at full strength whichever way it points. changes the body's velocity
export function push_by_liquid(body: Body, liquid_at: LiquidAt, is_solid: BlockCollision, is_player: boolean) {
export function push_by_fluid(body: Body, fluid_at: FluidAt, is_solid: BlockCollision, is_player: boolean) {
const half = body.width / 2 - 0.001;
const min_y = body.y + 0.001;
const max_y = body.y + body.height - 0.001;
@@ -330,12 +330,12 @@ export function push_by_liquid(body: Body, liquid_at: LiquidAt, is_solid: BlockC
for (let x = Math.floor(body.x - half); x <= Math.floor(body.x + half); x++) {
for (let y = Math.floor(min_y); y <= Math.floor(max_y); y++) {
for (let z = Math.floor(body.z - half); z <= Math.floor(body.z + half); z++) {
const liquid = liquid_at(x, y, z);
if (!liquid) continue;
const surface = y + (liquid_at(x, y + 1, z)?.id === liquid.id ? 1 : liquid.height);
const fluid = fluid_at(x, y, z);
if (!fluid) continue;
const surface = y + (fluid_at(x, y + 1, z)?.id === fluid.id ? 1 : fluid.height);
if (surface < min_y) continue;
depth = Math.max(depth, surface - min_y);
let [fx, fy, fz] = liquid_flow(x, y, z, liquid_at, is_solid);
let [fx, fy, fz] = fluid_flow(x, y, z, fluid_at, is_solid);
// minecraft's, which goes by the deepest cell so far
if (depth < 0.4) {
fx *= depth;
@@ -352,31 +352,31 @@ export function push_by_liquid(body: Body, liquid_at: LiquidAt, is_solid: BlockC
if (Math.hypot(px, py, pz) === 0) return;
[px, py, pz] = is_player ? [px / count, py / count, pz / count] : normalized(px, py, pz);
px *= LIQUID_PUSH;
py *= LIQUID_PUSH;
pz *= LIQUID_PUSH;
px *= FLUID_PUSH;
py *= FLUID_PUSH;
pz *= FLUID_PUSH;
if (
Math.abs(body.vx) < LIQUID_STILL_SPEED && Math.abs(body.vz) < LIQUID_STILL_SPEED &&
Math.hypot(px, py, pz) < LIQUID_MIN_PUSH
Math.abs(body.vx) < FLUID_STILL_SPEED && Math.abs(body.vz) < FLUID_STILL_SPEED &&
Math.hypot(px, py, pz) < FLUID_MIN_PUSH
) {
[px, py, pz] = normalized(px, py, pz).map((n) => n * LIQUID_MIN_PUSH);
[px, py, pz] = normalized(px, py, pz).map((n) => n * FLUID_MIN_PUSH);
}
body.vx += px;
body.vy += py;
body.vz += pz;
}
// how far the body's feet are under the surface of liquid it's in, 0 for none, like minecraft's getFluidHeight
export function liquid_depth(body: Body, liquid_at: LiquidAt): number {
// how far the body's feet are under the surface of fluid it's in, 0 for none, like minecraft's getFluidHeight
export function fluid_depth(body: Body, fluid_at: FluidAt): number {
const half = body.width / 2 - 0.001;
const min_y = body.y + 0.001;
let depth = 0;
for (let x = Math.floor(body.x - half); x <= Math.floor(body.x + half); x++) {
for (let y = Math.floor(min_y); y <= Math.floor(body.y + body.height - 0.001); y++) {
for (let z = Math.floor(body.z - half); z <= Math.floor(body.z + half); z++) {
const liquid = liquid_at(x, y, z);
if (!liquid) continue;
const surface = y + (liquid_at(x, y + 1, z)?.id === liquid.id ? 1 : liquid.height);
const fluid = fluid_at(x, y, z);
if (!fluid) continue;
const surface = y + (fluid_at(x, y + 1, z)?.id === fluid.id ? 1 : fluid.height);
depth = Math.max(depth, surface - min_y);
}
}
@@ -392,7 +392,7 @@ export const physics = {
box_is_free,
in_water,
eyes_in_water,
liquid_flow,
push_by_liquid,
liquid_depth,
fluid_flow,
push_by_fluid,
fluid_depth,
};
+14 -14
View File
@@ -2,11 +2,11 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import { ID_MASK, STATE_SHIFT } from "./constants.ts";
import { BlockRegistry, EverythingRegistry, ItemRegistry, liquid_height } from "./everything_registry.ts";
import { BlockRegistry, EverythingRegistry, fluid_height, ItemRegistry } from "./everything_registry.ts";
import { block_item_texture, cube_face_texture } from "./block_models.ts";
import { FULL_SHAPE, type Shape } from "./block_shapes.ts";
import type { ItemStack } from "./inventory.ts";
import type { LiquidInCell } from "./physics.ts";
import type { FluidInCell } from "./physics.ts";
import { list_matches } from "./tags.ts";
export function point_inside_rec(
@@ -191,7 +191,7 @@ export function can_place(
const into = current?.id ?? "bworld:air";
const replaceable = !current || current.replaceable === true;
const in_ok = block.place_in ? list_matches("blocks", block.place_in, into) : replaceable;
// one that's only ever waterlogged goes into a source of its liquid and nothing else
// one that's only ever waterlogged goes into a source of its fluid and nothing else
const source_ok = !block.waterlogged_only ||
(current !== undefined && current.id === block.waterloggable &&
(get_state_value(current_value, current, "level") ?? 0) === 0);
@@ -220,31 +220,31 @@ export function chunk_key(x: number, z: number) {
return (x + 32768) * 65536 + (z + 32768);
}
// whether a block value is a waterloggable block holding its liquid
// whether a block value is a waterloggable block holding its fluid
export function is_waterlogged(value: number, block: BlockRegistry | undefined): boolean {
return block?.waterloggable !== undefined && get_state_value(value, block, "waterlogged") === 1;
}
// the liquid in a cell with this block value: the block itself, or the liquid it's waterlogged with. undefined for
// the fluid in a cell with this block value: the block itself, or the fluid it's waterlogged with. undefined for
// none. what entities swim in, see in_water in physics.ts
export function liquid_block(value: number, block: BlockRegistry | undefined): BlockRegistry | undefined {
if (block?.liquid) return block;
export function fluid_block(value: number, block: BlockRegistry | undefined): BlockRegistry | undefined {
if (block?.fluid) return block;
if (!is_waterlogged(value, block)) return undefined;
return EverythingRegistry.get<BlockRegistry>("blocks", block!.waterloggable!);
}
// the liquid in a cell and how high it is, for liquids pushing things (see push_by_liquid in physics.ts). a waterlogged
// the fluid in a cell and how high it is, for fluids pushing things (see push_by_fluid in physics.ts). a waterlogged
// block holds a source
export function liquid_in_cell(value: number, block: BlockRegistry | undefined): LiquidInCell | undefined {
if (block?.liquid) {
export function fluid_in_cell(value: number, block: BlockRegistry | undefined): FluidInCell | undefined {
if (block?.fluid) {
const level = get_state_value(value, block, "level") ?? 0;
return { id: block.id, height: liquid_height(level, block.liquid.range) };
return { id: block.id, height: fluid_height(level, block.fluid.range) };
}
const liquid = liquid_block(value, block);
return liquid && { id: liquid.id, height: 1 };
const fluid = fluid_block(value, block);
return fluid && { id: fluid.id, height: 1 };
}
// a waterloggable block placed where a source of its liquid is holds it, like minecraft's getStateForPlacement.
// a waterloggable block placed where a source of its fluid is holds it, like minecraft's getStateForPlacement.
// value is what it's placed as, current_value and current what's there now
export function waterlog_placement(
value: number,
+2 -2
View File
@@ -362,7 +362,7 @@ const MODIFIERS: Record<string, Builtin<Modifier>> = {
return (chunk, positions) => positions.map((p) => ({ x: p.x, y: height(chunk), z: p.z }));
},
},
// on top of the column: WORLD_SURFACE on its highest block, OCEAN_FLOOR on its highest that isn't a liquid.
// on top of the column: WORLD_SURFACE on its highest block, OCEAN_FLOOR on its highest that isn't a fluid.
// positions outside the chunk are dropped
heightmap: {
schema: z.object({ heightmap: z.enum(HEIGHTMAPS) }),
@@ -392,7 +392,7 @@ const MODIFIERS: Record<string, Builtin<Modifier>> = {
function counts_for_heightmap(id: string | undefined, floor: boolean) {
if (id === undefined || id === AIR_ID) return false;
return !floor || !EverythingRegistry.get<BlockRegistry>("blocks", id)?.liquid;
return !floor || !EverythingRegistry.get<BlockRegistry>("blocks", id)?.fluid;
}
// block predicates, like minecraft's