Loading schematics

This commit is contained in:
2026-11-15 19:54:08 -03:00
parent 6bb2c87373
commit 0564275f58
15 changed files with 142 additions and 17 deletions
+13 -1
View File
@@ -3,7 +3,7 @@
// starts a game server with its mods: registers their data, then runs the worldgen, shared and server phases of their
// scripts. the worker loads built mods, tests can load mods straight from their source folders
import { register_mod_data } from "@/common/mod_loader.ts";
import { ModLoadError, register_mod_data } from "@/common/mod_loader.ts";
import type { ModData, ModListing } from "@/common/mod_loader.ts";
import { load_worldgen } from "@/common/worldgen_loader.ts";
import { dimension_shape, type DimensionJson } from "@/common/worldgen/data.ts";
@@ -12,6 +12,7 @@ import { worldgen_bundle } from "@/common/worldgen_bundle.ts";
import { GameHost, GameServer } from "./game_server.ts";
import type { WorldSource } from "./saves.ts";
import { ModRuntime } from "./mod_runtime.ts";
import { prepare_schematic } from "./schematics.ts";
import { register_entity_type } from "./entity/entity_types.ts";
import { mod_entity_factory } from "./entity/mod_entity.ts";
import { set_effect_types } from "./entity/effects.ts";
@@ -68,6 +69,17 @@ export async function start_game(
runtime,
});
// before scripts, so their server phases can place them
for (const mod of mods) {
for (const schematic of mod.data.schematics ?? []) {
try {
game.schematics.set(schematic.id!, prepare_schematic(game, schematic));
} catch (e) {
throw new ModLoadError(mod.listing.id, `schematic ${schematic.id}: ${(e as Error).message}`);
}
}
}
const scripts = mods.flatMap((mod) => mod.url ? [{ ...script_of(mod), url: mod.url }] : []);
// every mod's shared rules first, so server phases can count on any mod's being there
await runtime.load_shared_scripts(game, scripts);
+1
View File
@@ -233,6 +233,7 @@ function as_loaded_mod(file: string, mod: Mod): LoadedMod {
biome_sources: entries(mod.data.biome_sources ?? []),
dimensions: entries(mod.data.dimensions ?? []),
features: entries(mod.data.features ?? []),
schematics: entries(mod.data.schematics ?? []),
config: mod.data.config,
textures: [...mod.textures.keys()],
texture_files: new Map(),