Water phyisics

This commit is contained in:
2026-10-07 19:38:27 -03:00
parent d101fa2ef3
commit 78117f65c9
13 changed files with 338 additions and 13 deletions
+27
View File
@@ -4,6 +4,7 @@ import { type BlockRegistry, EverythingRegistry } from "$/common/everything_regi
import { get_state_value } from "$/common/utils.ts";
import { LIQUID_DEFAULTS } from "$/common/everything_registry.ts";
import { LiquidFlow } from "$/server/game/liquids.ts";
import { ItemStack } from "$/common/inventory.ts";
import { test_game } from "./helpers.ts";
type Game = Awaited<ReturnType<typeof test_game>>["game"];
@@ -152,3 +153,29 @@ Deno.test("water stops at chunks that aren't loaded instead of making them", ()
assert(!blocks.has("1,1,0"));
assert(asked.includes(1));
});
Deno.test("flowing water pushes things in it downstream, still water doesn't", async () => {
// entities only move near a player
const { game, join } = await test_game("mods");
join(1, "alice");
floor(game, 10);
game.set_block(0, Y, 0, "bworld:water");
ticks(game, 60);
// in the water flowing towards +x
const item = game.spawn_item(3.5, Y, 0.5, new ItemStack("bworld:stone"));
item.vx = item.vy = item.vz = 0;
ticks(game, 20);
assert(item.x > 4, `drifted to ${item.x}`);
assert(Math.abs(item.z - 0.5) < 0.01, `and stayed in its row, at z ${item.z}`);
// a pool of sources is still
const { game: pool, join: join_pool } = await test_game("mods");
join_pool(1, "alice");
floor(pool, 10);
for (let x = -2; x <= 2; x++) for (let z = -2; z <= 2; z++) pool.set_block(x, Y, z, "bworld:water");
const floating = pool.spawn_item(0.5, Y, 0.5, new ItemStack("bworld:stone"));
floating.vx = floating.vy = floating.vz = 0;
ticks(pool, 20);
assertEquals([floating.x, floating.z], [0.5, 0.5]);
});