Rename all "liquid" mentions to "fluid"
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// liquids flowing on the server, like minecraft's water: out from a source, down past edges, and draining away
|
||||
// fluids flowing on the server, like minecraft's water: out from a source, down past edges, and draining away
|
||||
import { assert, assertEquals } from "@std/assert";
|
||||
import { type BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { get_state_value } from "$/common/utils.ts";
|
||||
import { LIQUID_DEFAULTS } from "$/common/everything_registry.ts";
|
||||
import { LiquidFlow } from "$/server/game/liquids.ts";
|
||||
import { FLUID_DEFAULTS } from "$/common/everything_registry.ts";
|
||||
import { FluidFlow } from "$/server/game/fluids.ts";
|
||||
import { ItemStack } from "$/common/inventory.ts";
|
||||
import { test_game } from "./helpers.ts";
|
||||
|
||||
@@ -50,7 +50,7 @@ Deno.test("water flows out from a source one block a step, lower each block, up
|
||||
// it spreads in a diamond, by how far it walked
|
||||
assertEquals(level(game, 3, Y, 3), 6);
|
||||
// and doesn't flow on its own after that
|
||||
assertEquals(game.liquids.pending, 0);
|
||||
assertEquals(game.fluids.pending, 0);
|
||||
});
|
||||
|
||||
// lava's level there, undefined for no lava
|
||||
@@ -112,7 +112,7 @@ Deno.test("taking the source away drains what flowed from it", async () => {
|
||||
for (let x = -8; x <= 8; x++) {
|
||||
for (let z = -8; z <= 8; z++) assertEquals(level(game, x, Y, z), undefined, `at ${x}, ${z}`);
|
||||
}
|
||||
assertEquals(game.liquids.pending, 0);
|
||||
assertEquals(game.fluids.pending, 0);
|
||||
});
|
||||
|
||||
Deno.test("two sources beside a spot on solid ground make it a source, like infinite water", async () => {
|
||||
@@ -158,12 +158,12 @@ Deno.test("water stops at chunks that aren't loaded instead of making them", ()
|
||||
id: "a:water",
|
||||
textures: "a:water",
|
||||
has_collision: false,
|
||||
liquid: LIQUID_DEFAULTS,
|
||||
fluid: FLUID_DEFAULTS,
|
||||
} as BlockRegistry;
|
||||
water.states = [{ name: "level", bits: 3, default: 0 }];
|
||||
const blocks = new Map<string, number>([["0,1,0", 1]]);
|
||||
const asked: number[] = [];
|
||||
const flow = new LiquidFlow({
|
||||
const flow = new FluidFlow({
|
||||
value_at(x, y, z) {
|
||||
asked.push(x);
|
||||
if (x > 0) return undefined;
|
||||
@@ -1,48 +1,48 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// which way liquid flows and how it pushes what's in it, like minecraft's FlowingFluid.getFlow
|
||||
// which way fluid flows and how it pushes what's in it, like minecraft's FlowingFluid.getFlow
|
||||
import { assert, assertAlmostEquals, assertEquals } from "@std/assert";
|
||||
import { type Body, liquid_flow, type LiquidInCell, push_by_liquid } from "$/common/physics.ts";
|
||||
import { type Body, fluid_flow, type FluidInCell, push_by_fluid } from "$/common/physics.ts";
|
||||
|
||||
const WATER = "a:water";
|
||||
|
||||
// cells by "x,y,z", and solid blocks
|
||||
function world(liquids: Record<string, number>, solid: string[] = []) {
|
||||
const liquid_at = (x: number, y: number, z: number): LiquidInCell | undefined => {
|
||||
const height = liquids[`${x},${y},${z}`];
|
||||
function world(fluids: Record<string, number>, solid: string[] = []) {
|
||||
const fluid_at = (x: number, y: number, z: number): FluidInCell | undefined => {
|
||||
const height = fluids[`${x},${y},${z}`];
|
||||
return height === undefined ? undefined : { id: WATER, height };
|
||||
};
|
||||
const is_solid = (x: number, y: number, z: number) => solid.includes(`${x},${y},${z}`);
|
||||
return { liquid_at, is_solid };
|
||||
return { fluid_at, is_solid };
|
||||
}
|
||||
|
||||
const rounded = (v: number[]) => v.map((n) => Math.round(n * 1000) / 1000 + 0);
|
||||
|
||||
Deno.test("liquid flows towards lower cells of it and over edges, not into walls or air beside it", () => {
|
||||
Deno.test("fluid flows towards lower cells of it and over edges, not into walls or air beside it", () => {
|
||||
// a source with lower water to +x
|
||||
const stream = world({ "0,0,0": 1, "1,0,0": 0.8 });
|
||||
assertEquals(rounded(liquid_flow(0, 0, 0, stream.liquid_at, stream.is_solid)), [1, 0, 0]);
|
||||
assertEquals(rounded(fluid_flow(0, 0, 0, stream.fluid_at, stream.is_solid)), [1, 0, 0]);
|
||||
// level, nothing
|
||||
const pool = world({ "0,0,0": 1, "1,0,0": 1, "-1,0,0": 1 });
|
||||
assertEquals(rounded(liquid_flow(0, 0, 0, pool.liquid_at, pool.is_solid)), [0, 0, 0]);
|
||||
assertEquals(rounded(fluid_flow(0, 0, 0, pool.fluid_at, pool.is_solid)), [0, 0, 0]);
|
||||
// air beside it with nothing below doesn't pull, air with more of it below does
|
||||
assertEquals(rounded(liquid_flow(0, 0, 0, world({ "0,0,0": 1 }).liquid_at, () => false)), [0, 0, 0]);
|
||||
assertEquals(rounded(fluid_flow(0, 0, 0, world({ "0,0,0": 1 }).fluid_at, () => false)), [0, 0, 0]);
|
||||
const edge = world({ "0,0,0": 0.5, "0,-1,1": 1 });
|
||||
assertEquals(rounded(liquid_flow(0, 0, 0, edge.liquid_at, edge.is_solid)), [0, 0, 1]);
|
||||
assertEquals(rounded(fluid_flow(0, 0, 0, edge.fluid_at, edge.is_solid)), [0, 0, 1]);
|
||||
// falling down beside a wall, down
|
||||
const fall = world({ "0,0,0": 0.9, "0,1,0": 1 }, ["1,0,0"]);
|
||||
assertEquals(rounded(liquid_flow(0, 0, 0, fall.liquid_at, fall.is_solid)), [0, -1, 0]);
|
||||
assertEquals(rounded(fluid_flow(0, 0, 0, fall.fluid_at, fall.is_solid)), [0, -1, 0]);
|
||||
// a source under more water beside a wall is still, like the bottom of a pool
|
||||
const deep = world({ "0,0,0": 1, "0,1,0": 1 }, ["1,0,0"]);
|
||||
assertEquals(rounded(liquid_flow(0, 0, 0, deep.liquid_at, deep.is_solid)), [0, 0, 0]);
|
||||
assertEquals(rounded(fluid_flow(0, 0, 0, deep.fluid_at, deep.is_solid)), [0, 0, 0]);
|
||||
});
|
||||
|
||||
Deno.test("a body in flowing liquid is pushed along it, a player only by the average", () => {
|
||||
Deno.test("a body in flowing fluid is pushed along it, a player only by the average", () => {
|
||||
const stream = world({ "0,0,0": 1, "1,0,0": 0.8 });
|
||||
const body = (): Body => ({ x: 0.5, y: 0, z: 0.5, vx: 0, vy: 0, vz: 0, width: 0.25, height: 0.25 });
|
||||
const item = body();
|
||||
push_by_liquid(item, stream.liquid_at, stream.is_solid, false);
|
||||
push_by_fluid(item, stream.fluid_at, stream.is_solid, false);
|
||||
assertAlmostEquals(item.vx, 0.28);
|
||||
assertEquals([item.vy, item.vz], [0, 0]);
|
||||
|
||||
@@ -50,13 +50,13 @@ Deno.test("a body in flowing liquid is pushed along it, a player only by the ave
|
||||
const wide: Body = { ...body(), x: 0, width: 0.5 };
|
||||
const half = world({ "-1,0,0": 1, "0,0,0": 1, "1,0,0": 0.8 });
|
||||
const player = { ...wide };
|
||||
push_by_liquid(player, half.liquid_at, half.is_solid, true);
|
||||
push_by_fluid(player, half.fluid_at, half.is_solid, true);
|
||||
const other = { ...wide };
|
||||
push_by_liquid(other, half.liquid_at, half.is_solid, false);
|
||||
push_by_fluid(other, half.fluid_at, half.is_solid, false);
|
||||
assert(player.vx > 0 && player.vx < other.vx, `${player.vx} < ${other.vx}`);
|
||||
|
||||
// out of the liquid, nothing
|
||||
// out of the fluid, nothing
|
||||
const dry = { ...body(), y: 3 };
|
||||
push_by_liquid(dry, stream.liquid_at, stream.is_solid, false);
|
||||
push_by_fluid(dry, stream.fluid_at, stream.is_solid, false);
|
||||
assertEquals([dry.vx, dry.vy, dry.vz], [0, 0, 0]);
|
||||
});
|
||||
@@ -1,20 +1,20 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// liquids: blocks with "liquid", drawn like luanti's with surfaces that slope down to where they flow
|
||||
// fluids: blocks with "fluid", drawn like luanti's with surfaces that slope down to where they flow
|
||||
import { assert, assertAlmostEquals, assertEquals } from "@std/assert";
|
||||
import {
|
||||
type BlockRegistry,
|
||||
EverythingRegistry,
|
||||
is_liquid_block,
|
||||
liquid_height,
|
||||
liquid_textures,
|
||||
fluid_height,
|
||||
fluid_textures,
|
||||
is_fluid_block,
|
||||
} from "$/common/everything_registry.ts";
|
||||
import { block_from_json, block_to_json, type BlockJson, validate_block } from "$/common/mod_data.ts";
|
||||
import { cube_face_texture } from "$/common/block_models.ts";
|
||||
import { CHUNK_AREA, CHUNK_HEIGHT, CHUNK_SIZE } from "$/common/constants.ts";
|
||||
import { get_state_value, set_state_value } from "$/common/utils.ts";
|
||||
import { cell_index, corner_height, liquid_quads, type LiquidCell } from "$/client/workers/liquid_mesh.ts";
|
||||
import { cell_index, corner_height, fluid_quads, type FluidCell } from "$/client/workers/fluid_mesh.ts";
|
||||
import { TERRAIN_VERTEX_BYTES } from "$/client/workers/chunk_messages.ts";
|
||||
import { test_game } from "./helpers.ts";
|
||||
|
||||
@@ -22,13 +22,13 @@ const OIL: BlockJson = {
|
||||
id: "oily:oil",
|
||||
textures: { still: "oily:oil_still", flowing: "oily:oil_flow" },
|
||||
render_layer: "translucent",
|
||||
liquid: { range: 4 },
|
||||
fluid: { range: 4 },
|
||||
};
|
||||
|
||||
Deno.test("a liquid gets a level state, no collision and can be placed into", () => {
|
||||
Deno.test("a fluid gets a level state, no collision and can be placed into", () => {
|
||||
const { block } = block_from_json(OIL);
|
||||
assert(is_liquid_block(block));
|
||||
assertEquals(block.liquid, { range: 4, ticks: 5, renewable: true });
|
||||
assert(is_fluid_block(block));
|
||||
assertEquals(block.fluid, { range: 4, ticks: 5, renewable: true });
|
||||
assertEquals(block.states, [{ name: "level", bits: 3, default: 0 }]);
|
||||
assertEquals(block.has_collision, false);
|
||||
assertEquals(block.replaceable, true);
|
||||
@@ -43,48 +43,48 @@ Deno.test("a liquid gets a level state, no collision and can be placed into", ()
|
||||
assertEquals(block_to_json(hot, true).states, [{ name: "hot", bits: 1, default: 0 }]);
|
||||
|
||||
// a range of 7 is the default
|
||||
const water = block_from_json({ id: "a:water", textures: "a:water", liquid: {} }).block;
|
||||
assertEquals(water.liquid, { range: 7, ticks: 5, renewable: true });
|
||||
assertEquals(block_to_json(water, true).liquid, {});
|
||||
const water = block_from_json({ id: "a:water", textures: "a:water", fluid: {} }).block;
|
||||
assertEquals(water.fluid, { range: 7, ticks: 5, renewable: true });
|
||||
assertEquals(block_to_json(water, true).fluid, {});
|
||||
});
|
||||
|
||||
Deno.test("a liquid's still texture is its top and bottom, the flowing one its sides", () => {
|
||||
Deno.test("a fluid's still texture is its top and bottom, the flowing one its sides", () => {
|
||||
const { block } = block_from_json(OIL);
|
||||
assertEquals(liquid_textures(block.textures), { still: "oily:oil_still", flowing: "oily:oil_flow" });
|
||||
assertEquals(fluid_textures(block.textures), { still: "oily:oil_still", flowing: "oily:oil_flow" });
|
||||
assertEquals(cube_face_texture(block, "top"), "oily:oil_still");
|
||||
assertEquals(cube_face_texture(block, "side"), "oily:oil_flow");
|
||||
// one texture is both
|
||||
assertEquals(liquid_textures("a:water"), { still: "a:water", flowing: "a:water" });
|
||||
assertEquals(liquid_textures({ still: "a:water" }), { still: "a:water", flowing: "a:water" });
|
||||
assertEquals(fluid_textures("a:water"), { still: "a:water", flowing: "a:water" });
|
||||
assertEquals(fluid_textures({ still: "a:water" }), { still: "a:water", flowing: "a:water" });
|
||||
});
|
||||
|
||||
Deno.test("check-mods catches liquids that can't work", () => {
|
||||
Deno.test("check-mods catches fluids that can't work", () => {
|
||||
assertEquals(validate_block(OIL), []);
|
||||
const problems = (json: Record<string, unknown>) => validate_block({ ...OIL, ...json });
|
||||
assertEquals(problems({ liquid: { range: 8 } }), ["liquid.range must be at most 7"]);
|
||||
assertEquals(problems({ liquid: true }), ["liquid must be { range, ticks, renewable }, or {}"]);
|
||||
assertEquals(problems({ liquid: { ticks: 0 } }), ["liquid.ticks must be 1 or more"]);
|
||||
assertEquals(problems({ liquid: { speed: 2 } }), ['liquid can\'t have "speed"']);
|
||||
assertEquals(problems({ fluid: { range: 8 } }), ["fluid.range must be at most 7"]);
|
||||
assertEquals(problems({ fluid: true }), ["fluid must be { range, ticks, renewable }, or {}"]);
|
||||
assertEquals(problems({ fluid: { ticks: 0 } }), ["fluid.ticks must be 1 or more"]);
|
||||
assertEquals(problems({ fluid: { speed: 2 } }), ['fluid can\'t have "speed"']);
|
||||
assertEquals(problems({ textures: { top: "a:b" } }), [
|
||||
"textures must be a texture id or { still, flowing } for a liquid",
|
||||
"textures must be a texture id or { still, flowing } for a fluid",
|
||||
]);
|
||||
assertEquals(problems({ model: "engine:cross" }), ["model isn't for liquids, the engine draws them"]);
|
||||
assertEquals(problems({ model: "engine:cross" }), ["model isn't for fluids, the engine draws them"]);
|
||||
assertEquals(problems({ states: [{ name: "level", bits: 2, default: 0 }] }), [
|
||||
`states can't have "level", a liquid gets that state of its own`,
|
||||
`states can't have "level", a fluid gets that state of its own`,
|
||||
]);
|
||||
});
|
||||
|
||||
Deno.test("a liquid's surface is full at a source and lower each block it flows", () => {
|
||||
assertEquals(liquid_height(0, 7), 1);
|
||||
assertAlmostEquals(liquid_height(1, 7), 6.5 / 7);
|
||||
assertAlmostEquals(liquid_height(7, 7), 0.5 / 7);
|
||||
Deno.test("a fluid's surface is full at a source and lower each block it flows", () => {
|
||||
assertEquals(fluid_height(0, 7), 1);
|
||||
assertAlmostEquals(fluid_height(1, 7), 6.5 / 7);
|
||||
assertAlmostEquals(fluid_height(7, 7), 0.5 / 7);
|
||||
// past its range it's as low as it goes
|
||||
assertEquals(liquid_height(5, 4), liquid_height(4, 4));
|
||||
assertEquals(fluid_height(5, 4), fluid_height(4, 4));
|
||||
});
|
||||
|
||||
// the 3x3 cells around a liquid, all air unless set
|
||||
function cells(set: Record<string, Partial<LiquidCell>> = {}) {
|
||||
const list: LiquidCell[] = Array.from({ length: 9 }, () => ({
|
||||
// the 3x3 cells around a fluid, all air unless set
|
||||
function cells(set: Record<string, Partial<FluidCell>> = {}) {
|
||||
const list: FluidCell[] = Array.from({ length: 9 }, () => ({
|
||||
same: false,
|
||||
height: 0,
|
||||
air: true,
|
||||
@@ -97,12 +97,12 @@ function cells(set: Record<string, Partial<LiquidCell>> = {}) {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
const liquid = (height: number): Partial<LiquidCell> => ({ same: true, height });
|
||||
const fluid = (height: number): Partial<FluidCell> => ({ same: true, height });
|
||||
const OPEN = { same: false, solid: false };
|
||||
const SOLID = { same: false, solid: true };
|
||||
|
||||
// the highest and lowest y of each quad, by face
|
||||
function extents(quads: ReturnType<typeof liquid_quads>) {
|
||||
function extents(quads: ReturnType<typeof fluid_quads>) {
|
||||
return quads.map((q) => {
|
||||
const ys = [q.positions[1], q.positions[4], q.positions[7], q.positions[10]];
|
||||
return { face: q.face, min: Math.min(...ys), max: Math.max(...ys) };
|
||||
@@ -110,7 +110,7 @@ function extents(quads: ReturnType<typeof liquid_quads>) {
|
||||
}
|
||||
|
||||
Deno.test("a lone source is a full block, on the ground it has no bottom", () => {
|
||||
const quads = liquid_quads(cells({ "0,0": liquid(1) }), OPEN, SOLID);
|
||||
const quads = fluid_quads(cells({ "0,0": fluid(1) }), OPEN, SOLID);
|
||||
assertEquals(quads.map((q) => q.face).sort(), [0, 2, 3, 4, 5]);
|
||||
for (const { min, max, face } of extents(quads)) {
|
||||
if (face === 0) assertEquals([min, max], [1, 1]);
|
||||
@@ -119,25 +119,25 @@ Deno.test("a lone source is a full block, on the ground it has no bottom", () =>
|
||||
});
|
||||
|
||||
Deno.test("the middle of a lake is only its surface", () => {
|
||||
const lake: Record<string, Partial<LiquidCell>> = {};
|
||||
for (let dx = -1; dx <= 1; dx++) for (let dz = -1; dz <= 1; dz++) lake[`${dx},${dz}`] = liquid(1);
|
||||
assertEquals(liquid_quads(cells(lake), OPEN, SOLID).map((q) => q.face), [0]);
|
||||
const lake: Record<string, Partial<FluidCell>> = {};
|
||||
for (let dx = -1; dx <= 1; dx++) for (let dz = -1; dz <= 1; dz++) lake[`${dx},${dz}`] = fluid(1);
|
||||
assertEquals(fluid_quads(cells(lake), OPEN, SOLID).map((q) => q.face), [0]);
|
||||
// deeper down, nothing at all
|
||||
assertEquals(liquid_quads(cells(lake), { same: true, solid: false }, { same: true, solid: false }), []);
|
||||
assertEquals(fluid_quads(cells(lake), { same: true, solid: false }, { same: true, solid: false }), []);
|
||||
// a full surface right under a solid block can't be seen
|
||||
assertEquals(liquid_quads(cells(lake), SOLID, SOLID), []);
|
||||
assertEquals(fluid_quads(cells(lake), SOLID, SOLID), []);
|
||||
});
|
||||
|
||||
Deno.test("flowing liquid slopes down from the source beside it, and thins out to a film at the shore", () => {
|
||||
const flowing = liquid_height(1, 7);
|
||||
Deno.test("flowing fluid slopes down from the source beside it, and thins out to a film at the shore", () => {
|
||||
const flowing = fluid_height(1, 7);
|
||||
// a source to the -x side
|
||||
const set = cells({ "0,0": liquid(flowing), "-1,0": liquid(1) });
|
||||
const set = cells({ "0,0": fluid(flowing), "-1,0": fluid(1) });
|
||||
assertEquals(corner_height(set, 0, 0), 1);
|
||||
assertEquals(corner_height(set, 0, 1), 1);
|
||||
// the +x corners have it and air around them
|
||||
assertAlmostEquals(corner_height(set, 1, 0), 0.02);
|
||||
|
||||
const quads = liquid_quads(set, OPEN, SOLID);
|
||||
const quads = fluid_quads(set, OPEN, SOLID);
|
||||
// no side facing the source
|
||||
assert(!quads.some((q) => q.face === 4));
|
||||
const top = extents(quads).find((q) => q.face === 0)!;
|
||||
@@ -145,18 +145,18 @@ Deno.test("flowing liquid slopes down from the source beside it, and thins out t
|
||||
assertAlmostEquals(top.min, 0.02);
|
||||
|
||||
// between two flowing cells, the average
|
||||
const two = cells({ "0,0": liquid(0.5), "1,0": liquid(0.3), "1,1": liquid(0.1), "0,1": { solid: true } });
|
||||
const two = cells({ "0,0": fluid(0.5), "1,0": fluid(0.3), "1,1": fluid(0.1), "0,1": { solid: true } });
|
||||
assertAlmostEquals(corner_height(two, 1, 1), 0.3);
|
||||
});
|
||||
|
||||
Deno.test("a lower neighbor's surface rises to meet a column of liquid, so there's no gap", () => {
|
||||
// liquid with more of itself above: every corner is full, so the side toward the lower one has no height
|
||||
const column = cells({ "0,0": { ...liquid(1), top_same: true }, "0,1": liquid(0.3) });
|
||||
const quads = liquid_quads(column, { same: true, solid: false }, SOLID);
|
||||
Deno.test("a lower neighbor's surface rises to meet a column of fluid, so there's no gap", () => {
|
||||
// fluid with more of itself above: every corner is full, so the side toward the lower one has no height
|
||||
const column = cells({ "0,0": { ...fluid(1), top_same: true }, "0,1": fluid(0.3) });
|
||||
const quads = fluid_quads(column, { same: true, solid: false }, SOLID);
|
||||
assert(!quads.some((q) => q.face === 2 || q.face === 0));
|
||||
// the lower one, beside the column at -z: its top goes up to the top of the cell there
|
||||
const low = cells({ "0,0": liquid(0.3), "0,-1": { ...liquid(1), top_same: true } });
|
||||
const top = liquid_quads(low, OPEN, SOLID).find((q) => q.face === 0)!;
|
||||
const low = cells({ "0,0": fluid(0.3), "0,-1": { ...fluid(1), top_same: true } });
|
||||
const top = fluid_quads(low, OPEN, SOLID).find((q) => q.face === 0)!;
|
||||
const ys_at_z = (z: number) =>
|
||||
[0, 1, 2, 3].filter((k) => top.positions[k * 3 + 2] === z).map((k) => top.positions[k * 3 + 1]);
|
||||
assertEquals(ys_at_z(0), [1, 1]);
|
||||
@@ -232,7 +232,7 @@ Deno.test("the chunk worker draws water sloping down from a source, across a chu
|
||||
// full where it meets the source, then down
|
||||
assertEquals(height_at(0), 1);
|
||||
// the average of the levels around it, between the rows
|
||||
assertAlmostEquals(height_at(1), (liquid_height(1, 7) + liquid_height(2, 7)) / 2, 1e-6);
|
||||
assertAlmostEquals(height_at(1), (fluid_height(1, 7) + fluid_height(2, 7)) / 2, 1e-6);
|
||||
assertAlmostEquals(height_at(2), 0.02, 1e-6);
|
||||
// no sides between cells of it, only on the outside
|
||||
assert(!quads.some((corners) => corners.every(([x]) => x === 1)));
|
||||
@@ -241,13 +241,13 @@ Deno.test("the chunk worker draws water sloping down from a source, across a chu
|
||||
|
||||
Deno.test("with a flowing texture of its own, a sloping top flows downhill and the sides show part of it", () => {
|
||||
// level water stays still, whatever the flowing texture
|
||||
const lake: Record<string, Partial<LiquidCell>> = {};
|
||||
for (let dx = -1; dx <= 1; dx++) for (let dz = -1; dz <= 1; dz++) lake[`${dx},${dz}`] = liquid(1);
|
||||
assert(liquid_quads(cells(lake), OPEN, SOLID, 0.5).every((q) => q.still));
|
||||
const lake: Record<string, Partial<FluidCell>> = {};
|
||||
for (let dx = -1; dx <= 1; dx++) for (let dz = -1; dz <= 1; dz++) lake[`${dx},${dz}`] = fluid(1);
|
||||
assert(fluid_quads(cells(lake), OPEN, SOLID, 0.5).every((q) => q.still));
|
||||
|
||||
// a source to the -x side, so it flows towards +x
|
||||
const set = cells({ "0,0": liquid(liquid_height(1, 7)), "-1,0": liquid(1) });
|
||||
const quads = liquid_quads(set, OPEN, SOLID, 0.5);
|
||||
const set = cells({ "0,0": fluid(fluid_height(1, 7)), "-1,0": fluid(1) });
|
||||
const quads = fluid_quads(set, OPEN, SOLID, 0.5);
|
||||
const top = quads.find((q) => q.face === 0)!;
|
||||
assertEquals(top.still, false);
|
||||
// the middle half of the texture, turned so v (down the texture) runs with x, downstream
|
||||
@@ -267,12 +267,12 @@ Deno.test("with a flowing texture of its own, a sloping top flows downhill and t
|
||||
}
|
||||
|
||||
// with only one texture, the top stays still and the sides show all of it
|
||||
const plain = liquid_quads(set, OPEN, SOLID);
|
||||
const plain = fluid_quads(set, OPEN, SOLID);
|
||||
assert(plain.find((q) => q.face === 0)!.still);
|
||||
assert(plain.some((q) => q.face !== 0 && q.uvs.some((n) => n > 8)));
|
||||
});
|
||||
|
||||
Deno.test("a waterloggable block gets a waterlogged state after its own, and can't be a liquid", () => {
|
||||
Deno.test("a waterloggable block gets a waterlogged state after its own, and can't be a fluid", () => {
|
||||
const json: BlockJson = {
|
||||
id: "a:post",
|
||||
textures: "a:post",
|
||||
@@ -285,7 +285,7 @@ Deno.test("a waterloggable block gets a waterlogged state after its own, and can
|
||||
|
||||
assertEquals(validate_block(json), []);
|
||||
assert(validate_block({ ...json, waterloggable: "water" }).some((p) => p.includes("waterloggable")));
|
||||
assert(validate_block({ id: "a:w", textures: "a:w", liquid: {}, waterloggable: "a:water" }).length > 0);
|
||||
assert(validate_block({ id: "a:w", textures: "a:w", fluid: {}, waterloggable: "a:water" }).length > 0);
|
||||
assert(
|
||||
validate_block({ ...json, states: [{ name: "waterlogged", bits: 1, default: 0 }] })
|
||||
.some((p) => p.includes("of its own")),
|
||||
@@ -16,9 +16,9 @@ function setup(ceiling = Infinity, world?: { solid: Blocks; water: Blocks }) {
|
||||
const client = {
|
||||
level: {
|
||||
collision_shape: world?.solid ?? ((_x: number, y: number) => y < 0 || y >= ceiling),
|
||||
is_liquid: world?.water ?? (() => false),
|
||||
is_fluid: world?.water ?? (() => false),
|
||||
// its water is all still sources
|
||||
liquid_at: (x: number, y: number, z: number) =>
|
||||
fluid_at: (x: number, y: number, z: number) =>
|
||||
world?.water(x, y, z) ? { id: "a:water", height: 1 } : undefined,
|
||||
},
|
||||
screen: undefined,
|
||||
|
||||
@@ -74,11 +74,11 @@ Deno.test("which way water flows, from where it's higher to where it's lower", a
|
||||
const { game, ctx } = await setup();
|
||||
game.set_block(0, 100, 0, "bworld:water");
|
||||
for (let i = 0; i < 40; i++) game.tick();
|
||||
assertEquals(ctx.world.liquid_flow(2, 100, 0), { x: 1, y: 0, z: 0 });
|
||||
assertEquals(ctx.world.liquid_flow(0, 100, -2), { x: 0, y: 0, z: -1 });
|
||||
assertEquals(ctx.world.fluid_flow(2, 100, 0), { x: 1, y: 0, z: 0 });
|
||||
assertEquals(ctx.world.fluid_flow(0, 100, -2), { x: 0, y: 0, z: -1 });
|
||||
// a source with water all around is still, and so is air
|
||||
assertEquals(ctx.world.liquid_flow(0, 100, 0), { x: 0, y: 0, z: 0 });
|
||||
assertEquals(ctx.world.liquid_flow(0, 102, 0), { x: 0, y: 0, z: 0 });
|
||||
assertEquals(ctx.world.fluid_flow(0, 100, 0), { x: 0, y: 0, z: 0 });
|
||||
assertEquals(ctx.world.fluid_flow(0, 102, 0), { x: 0, y: 0, z: 0 });
|
||||
});
|
||||
|
||||
Deno.test("items lying in a box are found, changed and taken away", async () => {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { assert, assertAlmostEquals, assertEquals } from "@std/assert";
|
||||
import { eyes_in_water, in_water, move_body } from "$/common/physics.ts";
|
||||
import { type BlockRegistry, is_liquid_block, LIQUID_DEFAULTS } from "$/common/everything_registry.ts";
|
||||
import { type BlockRegistry, FLUID_DEFAULTS, is_fluid_block } from "$/common/everything_registry.ts";
|
||||
|
||||
const body = (x: number, z: number, vx: number, vz: number) => ({ x, y: 0, z, vx, vy: 0, vz, width: 0.6, height: 1.8 });
|
||||
// a block at x 0 to 1, z 1 to 2, on a floor
|
||||
@@ -46,12 +46,12 @@ Deno.test("a body on the ground steps up onto something low, not onto a full blo
|
||||
assertAlmostEquals(wall.y, 0);
|
||||
});
|
||||
|
||||
Deno.test("liquids are the blocks that say they are one", () => {
|
||||
Deno.test("fluids are the blocks that say they are one", () => {
|
||||
const block = (fields: Partial<BlockRegistry>) => ({ has_collision: false, ...fields }) as BlockRegistry;
|
||||
assertEquals(is_liquid_block(block({ liquid: LIQUID_DEFAULTS })), true);
|
||||
assertEquals(is_fluid_block(block({ fluid: FLUID_DEFAULTS })), true);
|
||||
// no collision and replaceable isn't enough any more, like a plant you can place into
|
||||
assertEquals(is_liquid_block(block({ replaceable: true })), false);
|
||||
assertEquals(is_liquid_block(undefined), false);
|
||||
assertEquals(is_fluid_block(block({ replaceable: true })), false);
|
||||
assertEquals(is_fluid_block(undefined), false);
|
||||
});
|
||||
|
||||
Deno.test("a body is in water by its feet or the middle of its box, and its eyes by its eye height", () => {
|
||||
|
||||
@@ -68,7 +68,7 @@ Deno.test("water flows out of a waterlogged fence, which never drains, and break
|
||||
const value = set_state_value(t.game.world.get_block_value(2, 100, 0), fence, "waterlogged", 1)!;
|
||||
t.game.set_block_state(2, 100, 0, value >>> 16);
|
||||
assertEquals(waterlogged(t.game, 2, 100, 0), 1);
|
||||
assert(t.game.entities.is_liquid(2, 100, 0), "entities are in water in it");
|
||||
assert(t.game.entities.is_fluid(2, 100, 0), "entities are in water in it");
|
||||
|
||||
ticks(t.game, 30);
|
||||
assertEquals(t.game.world.get_block_id(3, 100, 0), "bworld:water");
|
||||
@@ -94,7 +94,7 @@ Deno.test("rice is only planted in a water source, holds it, and leaves it behin
|
||||
assertEquals(t.game.world.get_block_id(2, 100, 0), "farmersdelight:rice");
|
||||
const rice = EverythingRegistry.get<BlockRegistry>("blocks", "farmersdelight:rice")!;
|
||||
assertEquals(get_state_value(t.game.world.get_block_value(2, 100, 0), rice, "waterlogged"), 1);
|
||||
assert(t.game.entities.is_liquid(2, 100, 0));
|
||||
assert(t.game.entities.is_fluid(2, 100, 0));
|
||||
|
||||
t.game.destroy_block(2, 100, 0);
|
||||
ticks(t.game, 1);
|
||||
|
||||
Reference in New Issue
Block a user