Single module modding

This commit is contained in:
2026-11-14 12:18:41 -03:00
parent 605008f584
commit 313098892e
134 changed files with 919 additions and 924 deletions
+9 -8
View File
@@ -2,9 +2,9 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// everything generating a chunk reads, as one plain object a worker can be sent: the seed, the generator, and each
// mod's data generation needs with its worldgen script's url. loading it registers the data in this realm and loads
// the scripts, which gives the same numeric block ids and the same generator as the game, so chunks come out the same
// block for block. tests/worldgen_bundle_test.ts checks it with the golden fixture
// mod's data generation needs with its script's url. loading it registers the data in this realm and runs the
// scripts' worldgen phases, which gives the same numeric block ids and the same generator as the game, so chunks come
// out the same block for block. tests/worldgen_bundle_test.ts checks it with the golden fixture
import type { ModData } from "./mod_loader.ts";
import { register_mod_data } from "./mod_loader.ts";
import { type BlockRegistry, EverythingRegistry } from "./everything_registry.ts";
@@ -35,20 +35,21 @@ export interface WorldgenBundle {
// the dimension's, see WorldShape
shape: WorldShapeJson;
// in load order
mods: { id: string; data: WorldgenModData; worldgen_url?: string; engine_access?: boolean }[];
// url is the mod's script, which worldgen workers run the worldgen phase of
mods: { id: string; data: WorldgenModData; url?: string; engine_access?: boolean }[];
}
export function worldgen_bundle(
seed: string,
generator: string,
shape: WorldShapeJson,
mods: { id: string; data: ModData; worldgen_url?: string; engine_access?: boolean }[],
mods: { id: string; data: ModData; url?: string; engine_access?: boolean }[],
): WorldgenBundle {
return {
seed,
generator,
shape: { min_y: shape.min_y, max_y: shape.max_y, sky_light: shape.sky_light },
mods: mods.map(({ id, data, worldgen_url, engine_access }) => ({
mods: mods.map(({ id, data, url, engine_access }) => ({
id,
data: {
blocks: data.blocks,
@@ -62,7 +63,7 @@ export function worldgen_bundle(
biome_sources: data.biome_sources ?? [],
features: data.features ?? [],
},
...(worldgen_url ? { worldgen_url } : {}),
...(url ? { url } : {}),
...(engine_access ? { engine_access } : {}),
})),
};
@@ -105,7 +106,7 @@ export async function load_bundle(bundle: WorldgenBundle): Promise<LoadedBundle>
const setup = await load_worldgen({
mods: bundle.mods.map((mod) => mod.id),
scripts: bundle.mods.flatMap((mod) =>
mod.worldgen_url ? [{ mod: mod.id, url: mod.worldgen_url, engine_access: mod.engine_access }] : []
mod.url ? [{ mod: mod.id, url: mod.url, engine_access: mod.engine_access }] : []
),
ores: recipes.ores,
generator: bundle.generator,