Move world generation outside the engine and into mods and data files
This commit is contained in:
@@ -1,11 +1,49 @@
|
||||
// what worldgen scripts get, see docs/modding/worldgen/index.md. runs on the server and must be deterministic
|
||||
import type { Id } from "./shared.ts";
|
||||
import type { Id, Position } from "./shared.ts";
|
||||
|
||||
export type { Id } from "./shared.ts";
|
||||
export type { Id, Position } from "./shared.ts";
|
||||
|
||||
export interface WorldgenContext {
|
||||
register_terrain(id: Id, generate: (chunk: TerrainChunk) => void): void;
|
||||
register_feature(id: Id, generate: (chunk: FeatureChunk) => 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<C = any>(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<C = Record<string, unknown>>(
|
||||
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<string, string> };
|
||||
}
|
||||
|
||||
export interface FeatureChunk {
|
||||
@@ -15,6 +53,9 @@ export interface FeatureChunk {
|
||||
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;
|
||||
@@ -23,6 +64,8 @@ export interface FeatureChunk {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user