// SPDX-FileCopyrightText: 2026 Paula Wisnievski // SPDX-License-Identifier: AGPL-3.0-or-later // what worldgen scripts get, see docs/modding/worldgen/index.md. runs on the server and must be deterministic import type { Id, Position } from "./shared.ts"; export type { Id, Position } from "./shared.ts"; export interface WorldgenContext { register_terrain(id: Id, generate: (chunk: TerrainChunk) => void): void; // a feature that's code, run on every chunk. see FeatureOptions for when register_feature(id: Id, generate: (chunk: FeatureChunk) => void, options?: FeatureOptions): void; // a type of feature data features can use: places config at origin, returns whether it placed anything // deno-lint-ignore no-explicit-any register_feature_type(id: Id, place: (chunk: FeatureChunk, config: C, origin: Position) => boolean): void; // a placement modifier data features can use: the positions after it, from the ones before. config is its json register_placement_modifier>( id: Id, modify: (chunk: FeatureChunk, config: C, positions: Position[]) => Position[], ): void; // every biome mods added, for what features read from them, like which trees grow biomes(): FeatureBiome[]; } // the order features run in, minecraft's decoration steps. features without one run in the last export type FeatureStep = | "raw_generation" | "lakes" | "local_modifications" | "underground_structures" | "surface_structures" | "strongholds" | "underground_ores" | "underground_decoration" | "fluid_springs" | "vegetal_decoration" | "top_layer_modification"; export interface FeatureOptions { step?: FeatureStep; // only runs in chunks with one of these biomes biomes?: Id | Id[]; } // a biome, as features see it export interface FeatureBiome { id: Id; // its json's trees, see docs/modding/worldgen/biomes.md trees?: { chance: number; kinds: string[]; wood: Record }; } export interface FeatureChunk { // chunk coordinates readonly x: number; readonly z: number; readonly seed: string; // seeded from the seed, chunk and feature id readonly rng: { next(): number }; // seeded from the seed and name alone, the same in every chunk. for things decided across chunks, like trees // spread over a grid of cells random(name: string): { next(): number }; // create_noise_2d(new Alea(seed + "_" + name)), cached per seed and name noise_2d(name: string): (x: number, z: number) => number; noise_3d(name: string): (x: number, y: number, z: number) => number; // surface height and biome, inside this chunk only height_at(x: number, z: number): number; biome_at(x: number, z: number): Id; get_block(x: number, y: number, z: number): Id | undefined; // inside this chunk only set_block(x: number, y: number, z: number, id: Id): void; // up to one chunk away, like trees // a data feature's type and config at x, y, z, without its placement. whether it placed anything place_feature(id: Id, x: number, y: number, z: number): boolean; } export interface TerrainChunk extends FeatureChunk { set_height(x: number, z: number, height: number): void; set_biome(x: number, z: number, biome: Id): void; }