Add natural mob spawning for rotwalker

This commit is contained in:
2026-09-30 22:15:42 -03:00
parent 0052faa24d
commit a6fd508529
22 changed files with 714 additions and 7 deletions
+18
View File
@@ -4,6 +4,7 @@ import {
entity_model_from_geo,
FORMAT_VERSION,
OreJson,
type SpawnJson,
type TagJson,
validate_block,
validate_entity,
@@ -12,6 +13,7 @@ import {
validate_model,
validate_ore,
validate_recipe,
validate_spawn,
validate_tag,
} from "$/common/mod_data.ts";
import { check_references, load_order, type LoadedMod, type ModReport } from "$/common/mod_check.ts";
@@ -70,6 +72,7 @@ function load_mod(mods_dir: string, id: string): LoadedMod {
items: [],
recipes: [],
ores: [],
spawns: [],
entities: [],
entity_models: [],
tags: [],
@@ -169,6 +172,21 @@ function load_mod(mods_dir: string, id: string): LoadedMod {
}
}
if (exists(`${dir}/worldgen/spawns.json`)) {
const spawns = read_json(`${dir}/worldgen/spawns.json`, (m) => error(`worldgen/spawns.json: ${m}`));
if (!is_object(spawns) || spawns.format_version !== FORMAT_VERSION || !Array.isArray(spawns.spawns)) {
error(`worldgen/spawns.json: must be { "format_version": ${FORMAT_VERSION}, "spawns": [ ... ] }`);
} else {
spawns.spawns.forEach((spawn, i) => {
const problems = validate_spawn(spawn);
for (const problem of problems) error(`worldgen/spawns.json: spawn ${i}: ${problem}`);
if (problems.length === 0) {
mod.spawns.push({ file: "worldgen/spawns.json", json: spawn as SpawnJson });
}
});
}
}
// a mod only registers ids in its own namespace
for (const { file, json } of [...mod.blocks, ...mod.models, ...mod.items, ...mod.entities]) {
if (json.id.split(":")[0] !== id) error(`${file}: ${json.id} isn't in this mod's namespace "${id}"`);
+1
View File
@@ -31,6 +31,7 @@ export async function pack_mod(mod: LoadedMod): Promise<Uint8Array<ArrayBuffer>>
items: mod.items.map((i) => i.json),
recipes: mod.recipes.map((r) => r.json),
ores: mod.ores.map((o) => o.json),
spawns: mod.spawns.map((s) => s.json),
entities: mod.entities.map((e) => e.json),
entity_models: mod.entity_models.map((m) => m.json),
tags: mod.tags.map((t) => t.json),