Dimension api

This commit is contained in:
2026-11-05 23:34:43 -03:00
parent 34f001285d
commit 4766c9a808
14 changed files with 251 additions and 27 deletions
+22
View File
@@ -29,6 +29,7 @@ import {
type BiomeSourceJson,
density_function_refs,
type DensityFunctionJson,
type DimensionJson,
new_refs,
noise_refs,
noise_settings_refs,
@@ -68,6 +69,7 @@ export interface LoadedMod {
density_functions: { file: string; json: DensityFunctionJson }[];
noise_settings: { file: string; json: NoiseSettingsJson }[];
biome_sources: { file: string; json: BiomeSourceJson }[];
dimensions: { file: string; json: DimensionJson }[];
features: { file: string; json: FeatureJson }[];
// config.json's settings, see docs/modding/misc/config.md
config?: Record<string, unknown>;
@@ -98,6 +100,7 @@ export function mod_data(mod: LoadedMod): ModData {
density_functions: mod.density_functions.map((d) => d.json),
noise_settings: mod.noise_settings.map((n) => n.json),
biome_sources: mod.biome_sources.map((b) => b.json),
dimensions: mod.dimensions.map((d) => d.json),
features: mod.features.map((f) => f.json),
config: mod.config,
};
@@ -177,7 +180,10 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
"density function": new Map(),
"noise settings": new Map(),
"biome source": new Map(),
dimension: new Map(),
};
// the dimensions that say they're the default, only one can be
const defaults: string[] = [];
const biome_rule_owners = new Map<string, string[]>();
const all_noise_settings: NoiseSettingsJson[] = [];
const feature_owners = new Map<string, string[]>();
@@ -213,6 +219,10 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
add(worldgen_owners["noise settings"], json.id, mod.id);
all_noise_settings.push(json);
}
for (const { json } of mod.dimensions ?? []) {
add(worldgen_owners.dimension, json.id, mod.id);
if (json.default) defaults.push(`${json.id} (${mod.id})`);
}
for (const { json } of mod.biome_sources ?? []) {
add(worldgen_owners["biome source"], json.id, mod.id);
for (const rule of json.rules) add(biome_rule_owners, rule.id, mod.id);
@@ -406,6 +416,18 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
noise_settings_refs(json, refs);
check_worldgen("noise settings", file, json.id, refs);
}
for (const { file, json } of mod.dimensions ?? []) {
check_worldgen("dimension", file, json.id, new_refs());
check_namespace(file, json.generator);
if (!worldgen_owners["noise settings"].has(json.generator)) {
errors.push(`${file}: noise settings ${json.generator} doesn't exist`);
}
if (json.default && defaults.length > 1) {
errors.push(
`${file}: only one dimension can be the default, and these all are: ${defaults.join(", ")}`,
);
}
}
for (const { file, json } of mod.biome_sources ?? []) {
const refs = new_refs();
biome_source_refs(json, refs);