// SPDX-FileCopyrightText: 2026 Paula Wisnievski // SPDX-License-Identifier: AGPL-3.0-or-later // dimensions: the world is generated by the default dimension's noise settings, exactly one mod has one, and players // spawn on ground that has collision import { assert, assertEquals, assertRejects } from "@std/assert"; import { copy_dir, test_game } from "./helpers.ts"; // flat's ground: glass up to y 69, only east of x 16. west of it is open sea up to y 59 const GROUND_TOP = 69; const SEA_TOP = 59; const GROUND_FROM_X = 16; // mods/bworld, and flat when flat is true: a generator of its own and a dimension using it. which mods say their // dimension is the default is up to the test function mods(options: { flat: boolean; bworld_default: boolean; flat_default?: boolean }) { const dir = Deno.makeTempDirSync({ prefix: "bworld_dimensions_" }); copy_dir("mods/bworld", `${dir}/bworld`); const bworld_dimension = `${dir}/bworld/worldgen/dimension/overworld.json`; const json = JSON.parse(Deno.readTextFileSync(bworld_dimension)); json.dimension.default = options.bworld_default; Deno.writeTextFileSync(bworld_dimension, JSON.stringify(json)); if (!options.flat) return dir; const write = (path: string, json: unknown) => { Deno.mkdirSync(`${dir}/flat/${path.split("/").slice(0, -1).join("/")}`, { recursive: true }); Deno.writeTextFileSync(`${dir}/flat/${path}`, JSON.stringify(json)); }; write("manifest.json", { format_version: 1, id: "flat", name: "Flat", version: "1.0.0", dependencies: [{ id: "bworld", version: "*" }], }); write("worldgen/biome_source/flat.json", { format_version: 1, biome_source: { id: "flat:flat", rules: [{ id: "flat:beach", biome: "bworld:beach" }] }, }); // solid where both the y and the x parts are above 0 const below = (top: number) => ({ type: "sub", argument1: top + 0.5, argument2: { type: "y" } }); write("worldgen/noise_settings/flat.json", { format_version: 1, noise_settings: { id: "flat:flat", sea_level: SEA_TOP + 1, default_block: "bworld:glass", cell_width: 1, terrain: { density: { type: "min", argument1: below(GROUND_TOP), argument2: { type: "sub", argument1: { type: "x" }, argument2: GROUND_FROM_X - 0.5 }, }, cell_height: 1, }, caves: { density: 1, cell_height: 1 }, preliminary_surface: GROUND_TOP + 1, climate: {}, steep: 100, biome_source: "flat:flat", fluids: [{ block: "bworld:water", below: SEA_TOP + 1, where: "open_sky" }], surface_rule: { type: "block", result_state: { Name: "bworld:glass" } }, }, }); write("worldgen/dimension/flat.json", { format_version: 1, dimension: { id: "flat:flat", generator: "flat:flat", default: options.flat_default ?? true }, }); return dir; } Deno.test("the world is generated by the default dimension's noise settings, from any mod", async () => { const dir = mods({ flat: true, bworld_default: false }); const { game } = await test_game(dir); Deno.removeSync(dir, { recursive: true }); const world = game.world; for (const z of [-20, 0, 37]) { assertEquals(world.get_block_id(40, GROUND_TOP, z), "bworld:glass"); assertEquals(world.get_block_id(40, GROUND_TOP + 1, z), "cubi:air"); assertEquals(world.get_block_id(-40, SEA_TOP, z), "bworld:water"); assertEquals(world.get_block_id(-40, SEA_TOP + 1, z), "cubi:air"); } }); Deno.test("players spawn on ground with collision, not on the water in the middle of the world", async () => { const dir = mods({ flat: true, bworld_default: false }); const { game, join } = await test_game(dir); Deno.removeSync(dir, { recursive: true }); const { x, y, z } = join(1, "alice").spawn; assert(x >= GROUND_FROM_X, `spawned at x ${x}, over the water`); assertEquals(y, GROUND_TOP + 1); assert(game.world.get_block_info(Math.floor(x), y - 1, Math.floor(z))?.has_collision); }); Deno.test("the server doesn't start without a default dimension, or with two", async () => { const none = mods({ flat: true, bworld_default: false, flat_default: false }); await assertRejects(() => test_game(none), Error, "no mod has a default dimension"); Deno.removeSync(none, { recursive: true }); const two = mods({ flat: true, bworld_default: true }); await assertRejects( () => test_game(two), Error, "only one dimension can be the default, and these all are: bworld:overworld (bworld), flat:flat (flat)", ); Deno.removeSync(two, { recursive: true }); });