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
+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;