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
+21 -1
View File
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
// SPDX-License-Identifier: AGPL-3.0-or-later
// world generation as data: noises, density functions, noise settings (a generator) and biome sources, see
// world generation as data: noises, density functions, noise settings (a generator), biome sources and dimensions, see
// docs/modding/worldgen/terrain.md. checked here, compiled by density.ts and generator.ts. the names follow
// minecraft's (density functions, the noise router, surface rules) where the idea is the same
import * as z from "zod";
@@ -130,6 +130,16 @@ export interface BiomeRuleJson {
biome: string;
}
// dimensions: a world to play and the noise settings that generate it, like neoforge's level stems. the world plays the
// one with "default": true, and only one loaded mod can have one
export interface DimensionJson {
id: string;
// the noise settings that generate it
generator: string;
default?: boolean;
}
// what worldgen data refers to, for checking it all exists
export interface WorldgenRefs {
noises: Set<string>;
@@ -313,6 +323,12 @@ const biome_source_schema: z.ZodType<BiomeSourceJson> = z.object({
});
});
const dimension_schema: z.ZodType<DimensionJson> = z.strictObject({
id: worldgen_id,
generator: z.string("must be a noise settings' id").regex(WORLDGEN_ID_PATTERN),
default: z.boolean().optional(),
});
export function validate_noise(json: unknown): Problems {
return find_problems(noise_schema, json);
}
@@ -329,6 +345,10 @@ export function validate_biome_source(json: unknown): Problems {
return find_problems(biome_source_schema, json);
}
export function validate_dimension(json: unknown): Problems {
return find_problems(dimension_schema, json);
}
// what worldgen data that passed its checks refers to
export function noise_refs(json: NoiseJson, refs: WorldgenRefs) {