Waterlogging
This commit is contained in:
+46
-1
@@ -169,7 +169,8 @@ async function mesh(blocks: [number, number, number, string, number?][]) {
|
||||
const worker = new Worker(new URL("../client/workers/chunk_worker.ts", import.meta.url).href, { type: "module" });
|
||||
worker.postMessage({
|
||||
type: "init",
|
||||
blocks_registry: JSON.parse(JSON.stringify(registry)),
|
||||
// with the registry's gaps, like the client sends it
|
||||
blocks_registry: registry.map((block) => JSON.parse(JSON.stringify(block))),
|
||||
models: {},
|
||||
textures_info: { "engine:missing": { x: 0, y: 0, width: 16, height: 16 } },
|
||||
image: { width: 1024, height: 1024 },
|
||||
@@ -266,3 +267,47 @@ Deno.test("with a flowing texture of its own, a sloping top flows downhill and t
|
||||
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", () => {
|
||||
const json: BlockJson = {
|
||||
id: "a:post",
|
||||
textures: "a:post",
|
||||
states: [{ name: "lit", bits: 1, default: 0 }],
|
||||
waterloggable: "a:water",
|
||||
};
|
||||
const { block } = block_from_json(json);
|
||||
assertEquals(block.states!.map((s) => s.name), ["lit", "waterlogged"]);
|
||||
assertEquals(block_to_json(block, true), json);
|
||||
|
||||
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({ ...json, states: [{ name: "waterlogged", bits: 1, default: 0 }] })
|
||||
.some((p) => p.includes("of its own")),
|
||||
);
|
||||
// only ever placed waterlogged, which needs something to be waterlogged with
|
||||
const only: BlockJson = { ...json, waterlogged_only: true };
|
||||
assertEquals(block_to_json(block_from_json(only).block, true), only);
|
||||
assertEquals(validate_block(only), []);
|
||||
assert(validate_block({ id: "a:post", textures: "a:post", waterlogged_only: true }).length > 0);
|
||||
});
|
||||
|
||||
Deno.test("the chunk worker draws the water in a waterlogged fence, joined to the water beside it", async () => {
|
||||
await test_game("mods");
|
||||
const fence = EverythingRegistry.get<BlockRegistry>("blocks", "bworld:oak_fence")!;
|
||||
const waterlogged = set_state_value(0, fence, "waterlogged", 1)! >>> 16;
|
||||
// a fence in water at x 1 with water at x 2, and a dry fence at x 5
|
||||
const quads = await mesh([
|
||||
[1, 10, 8, "bworld:oak_fence", waterlogged],
|
||||
[2, 10, 8, "bworld:water", 0],
|
||||
[5, 10, 8, "bworld:oak_fence", 0],
|
||||
]);
|
||||
const water_in = (x: number) =>
|
||||
quads.filter((corners) => corners.every(([cx]) => cx >= x - 1e-6 && cx <= x + 1 + 1e-6));
|
||||
// a full top, facing up and down, and no side between it and the water next to it
|
||||
const tops = water_in(1).filter((corners) => corners.every(([, y]) => y === 11));
|
||||
assertEquals(tops.length, 2);
|
||||
assert(!water_in(1).some((corners) => corners.every(([cx]) => Math.abs(cx - 2) < 1e-6)));
|
||||
assertEquals(water_in(5).length, 0);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user