Move world generation outside the engine and into mods and data files
This commit is contained in:
+13
-2
@@ -48,7 +48,7 @@ export function position_key(x: number, y: number, z: number) {
|
||||
export class ServerWorld {
|
||||
readonly seed: string;
|
||||
readonly block_ids: Record<string, number> = {};
|
||||
readonly worldgen: WorldgenSetup | undefined;
|
||||
readonly worldgen: WorldgenSetup;
|
||||
// what a freshly placed or generated block stores, by numeric id: the id with its default states
|
||||
readonly default_values: number[] = [];
|
||||
// for light_at, by numeric id
|
||||
@@ -85,7 +85,7 @@ export class ServerWorld {
|
||||
on_block_change?: (x: number, y: number, z: number, id: string, state: number) => void;
|
||||
on_tile_item_change?: (x: number, y: number, z: number, item: ItemData | undefined) => void;
|
||||
|
||||
constructor(seed: string, worldgen?: WorldgenSetup) {
|
||||
constructor(seed: string, worldgen: WorldgenSetup) {
|
||||
this.seed = seed;
|
||||
this.worldgen = worldgen;
|
||||
const blocks = EverythingRegistry.get_registry<BlockRegistry>("blocks");
|
||||
@@ -173,6 +173,11 @@ export class ServerWorld {
|
||||
}
|
||||
|
||||
// like "bworld:plains", what generation decided
|
||||
// a column's biome without generating its chunk, a little off near coasts and cliffs, see OverworldTerrain
|
||||
estimate_biome(x: number, z: number): { biome: string; y: number } {
|
||||
return this.worldgen.generator.for_seed(this.seed).estimate_biome(x, z);
|
||||
}
|
||||
|
||||
biome_at(x: number, z: number): string {
|
||||
const chunk_x = Math.floor(x / CHUNK_SIZE);
|
||||
const chunk_z = Math.floor(z / CHUNK_SIZE);
|
||||
@@ -209,6 +214,12 @@ export class ServerWorld {
|
||||
return found;
|
||||
}
|
||||
|
||||
// what generation makes in a chunk, neighbors' spills included, without what players changed. built again every
|
||||
// call, for comparing generation (tests/worldgen_golden_test.ts)
|
||||
generated_blocks(chunk_x: number, chunk_z: number): Uint32Array {
|
||||
return this.#generate_chunk(chunk_x, chunk_z);
|
||||
}
|
||||
|
||||
// whether every chunk within radius blocks of x, z is, see has_chunk
|
||||
has_chunks_around(x: number, z: number, radius: number) {
|
||||
for (let cx = Math.floor((x - radius) / CHUNK_SIZE); cx <= Math.floor((x + radius) / CHUNK_SIZE); cx++) {
|
||||
|
||||
Reference in New Issue
Block a user