World shape for dimension

This commit is contained in:
2026-11-06 22:49:43 -03:00
parent 7458a2d42a
commit 818ce22dd6
60 changed files with 749 additions and 349 deletions
+22 -1
View File
@@ -6,6 +6,7 @@
// minecraft's (density functions, the noise router, surface rules) where the idea is the same
import * as z from "zod";
import { find_problems, ID_PATTERN, is_object, type Problems, TAG_ID_PATTERN } from "../schema.ts";
import { DEFAULT_SHAPE, HIGHEST_Y, LOWEST_Y, shape_problem, WorldShape } from "../world_shape.ts";
// ids of worldgen data can have folders, like "bworld:overworld/erosion"
export const WORLDGEN_ID_PATTERN = TAG_ID_PATTERN;
@@ -138,6 +139,20 @@ export interface DimensionJson {
// the noise settings that generate it
generator: string;
default?: boolean;
// its blocks go from min_y up to max_y - 1, see WorldShape. 0 and 256 when not set
min_y?: number;
max_y?: number;
// whether light comes from the sky, true when not set
sky_light?: boolean;
}
// the shape a dimension's json gives it
export function dimension_shape(json: DimensionJson): WorldShape {
return new WorldShape({
min_y: json.min_y ?? DEFAULT_SHAPE.min_y,
max_y: json.max_y ?? DEFAULT_SHAPE.max_y,
sky_light: json.sky_light ?? DEFAULT_SHAPE.sky_light,
});
}
// what worldgen data refers to, for checking it all exists
@@ -271,7 +286,7 @@ const cell_height = z.literal([1, 2, 4, 8, 16, 32]);
const noise_settings_schema: z.ZodType<NoiseSettingsJson> = z.object({
id: worldgen_id,
sea_level: z.int().min(0).max(256),
sea_level: z.int().min(LOWEST_Y).max(HIGHEST_Y),
default_block: block_id,
cell_width: z.literal([1, 2, 4, 8, 16]),
terrain: z.object({ density, cell_height }),
@@ -327,6 +342,12 @@ 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(),
min_y: z.int().optional(),
max_y: z.int().optional(),
sky_light: z.boolean().optional(),
}).superRefine((json, ctx) => {
const problem = shape_problem(json.min_y ?? DEFAULT_SHAPE.min_y, json.max_y ?? DEFAULT_SHAPE.max_y);
if (problem) ctx.addIssue({ code: "custom", message: problem });
});
export function validate_noise(json: unknown): Problems {