More changes, im going to bed

This commit is contained in:
2026-11-06 00:17:27 -03:00
parent 9bec0f3718
commit 7458a2d42a
13 changed files with 35 additions and 53 deletions
+2 -2
View File
@@ -7,7 +7,7 @@ import { Container, ContainerSlot, ItemStack } from "./inventory.ts";
import { BlockRules } from "./block_rules.ts";
import { Tags } from "./tags.ts";
import { CommandDispatcher } from "./commands.ts";
import { OverworldTerrain } from "./worldgen/terrain.ts";
import { NoiseTerrain } from "./worldgen/terrain.ts";
import { physics } from "./physics.ts";
// built when it's exposed, not when this module loads, so import cycles can't leave anything undefined
@@ -20,7 +20,7 @@ export function common_engine() {
BlockRules,
Tags,
CommandDispatcher,
OverworldTerrain,
NoiseTerrain,
physics,
};
}
+2 -2
View File
@@ -7,7 +7,7 @@ import { Alea } from "@paulaboks/rng";
import { AIR, CHUNK_AREA, CHUNK_HEIGHT, CHUNK_SIZE, ID_MASK } from "@/common/constants.ts";
import type { FeatureChunk, Position } from "@/common/mod_api/worldgen.ts";
import type { OreJson } from "@/common/mod_data.ts";
import { generate_overworld } from "./worldgen/overworld.ts";
import { generate_noise_chunk } from "./worldgen/noise_chunk.ts";
import type { Generator } from "./worldgen/generator.ts";
import { named_noise_2d, named_noise_3d } from "./worldgen/noise.ts";
@@ -81,7 +81,7 @@ export function generate_raw_chunk(
const nid = block_ids[name];
return nid === undefined ? AIR : default_values?.[nid] ?? nid;
};
generate_overworld(blocks, heights, biomes, chunk_x, chunk_z, worldgen.generator.for_seed(seed), id);
generate_noise_chunk(blocks, heights, biomes, chunk_x, chunk_z, worldgen.generator.for_seed(seed), id);
for (const ores of worldgen.ores) {
generate_ores(blocks, chunk_x, chunk_z, seed, block_ids, ores, default_values);
+5 -5
View File
@@ -2,11 +2,11 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// a generator: noise settings, and the density functions, noises and biome rules it uses. compiled once for each
// seed, see OverworldTerrain. the data comes from mods' worldgen folders, see docs/modding/worldgen/terrain.md
// seed, see NoiseTerrain. the data comes from mods' worldgen folders, see docs/modding/worldgen/terrain.md
import { EverythingRegistry } from "../everything_registry.ts";
import type { BiomeRuleJson, BiomeSourceJson, DensityFunctionJson, NoiseJson, NoiseSettingsJson } from "./data.ts";
import type { DensitySources } from "./density.ts";
import { OverworldTerrain } from "./terrain.ts";
import { NoiseTerrain } from "./terrain.ts";
// everything worldgen data mods registered, in load order
export interface WorldgenData {
@@ -21,7 +21,7 @@ export class Generator {
// the biome source's rules with every mod's added in, the first that holds picks a column's biome
readonly rules: BiomeRuleJson[];
readonly sources: DensitySources;
#seeds = new Map<string, OverworldTerrain>();
#seeds = new Map<string, NoiseTerrain>();
// throws when the data doesn't add up, like a density function that doesn't exist
constructor(id: string, data: WorldgenData) {
@@ -36,10 +36,10 @@ export class Generator {
this.for_seed("");
}
for_seed(seed: string): OverworldTerrain {
for_seed(seed: string): NoiseTerrain {
let terrain = this.#seeds.get(seed);
if (!terrain) {
terrain = new OverworldTerrain(seed, this);
terrain = new NoiseTerrain(seed, this);
this.#seeds.set(seed, terrain);
}
return terrain;
@@ -1,13 +1,13 @@
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
// SPDX-License-Identifier: AGPL-3.0-or-later
// fills a chunk with the overworld: the terrain's density sampled on a coarse grid and interpolated (minecraft's
// fills a chunk from a generator's noise settings: the terrain's density sampled on a coarse grid and interpolated (minecraft's
// noise cells), caves cut out of it, then each column's biome, its surface blocks and fluids. what all of it is comes
// from the generator's noise settings, see OverworldTerrain and docs/modding/worldgen/terrain.md. trees and the rest
// from the generator's noise settings, see NoiseTerrain and docs/modding/worldgen/terrain.md. trees and the rest
// are features, after it
import { CHUNK_AREA, CHUNK_HEIGHT, CHUNK_SIZE } from "@/common/constants.ts";
import { get_biome } from "./biomes.ts";
import type { OverworldTerrain, TerrainColumn } from "./terrain.ts";
import type { NoiseTerrain, TerrainColumn } from "./terrain.ts";
import {
compile_fluids,
compile_surface_rule,
@@ -18,13 +18,13 @@ import {
// fills blocks (indexed y * CHUNK_AREA + z * CHUNK_SIZE + x) and each column's surface height and biome. block is
// a block's numeric id with its default states
export function generate_overworld(
export function generate_noise_chunk(
blocks: Uint32Array,
heights: Int32Array,
biomes: string[],
chunk_x: number,
chunk_z: number,
terrain: OverworldTerrain,
terrain: NoiseTerrain,
block: (id: string) => number,
) {
const settings = terrain.settings;
+4 -4
View File
@@ -5,7 +5,7 @@
// for each chunk with its block ids. like minecraft's surface rules: a rule gives a block or nothing, and a sequence
// gives its first rule's block
import { type FluidJson, range_test, type SurfaceConditionJson, type SurfaceRuleJson } from "./data.ts";
import type { OverworldTerrain } from "./terrain.ts";
import type { NoiseTerrain } from "./terrain.ts";
// a biome's surface as numeric ids
export interface SurfaceBlocks {
@@ -38,7 +38,7 @@ type Condition = (context: SurfaceContext) => boolean;
export function compile_surface_rule(
json: SurfaceRuleJson,
terrain: OverworldTerrain,
terrain: NoiseTerrain,
block: (id: string) => number,
): Rule {
switch (json.type) {
@@ -68,7 +68,7 @@ export function compile_surface_rule(
}
}
function compile_condition(json: SurfaceConditionJson, terrain: OverworldTerrain): Condition {
function compile_condition(json: SurfaceConditionJson, terrain: NoiseTerrain): Condition {
switch (json.type) {
case "stone_depth": {
const offset = json.offset;
@@ -113,7 +113,7 @@ export function surface_rule_reach(json: SurfaceRuleJson): number {
// the fluid empty space at the context's y becomes, if any. open_sky is whether there's only air above it
export function compile_fluids(
json: FluidJson[],
terrain: OverworldTerrain,
terrain: NoiseTerrain,
block: (id: string) => number,
): (context: SurfaceContext, open_sky: boolean) => number | undefined {
const fluids = json.map((fluid) => {
+3 -4
View File
@@ -2,9 +2,8 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// the shape of the world and which biome each column gets, from a generator's data (see generator.ts): its density
// functions compiled for one seed. generate_overworld calls density and cave through here, so engine access mods can
// hook them. bworld's overworld is shaped after tectonic (https://github.com/Apollounknowndev/tectonic, MIT), its
// splines are in mods/bworld/worldgen/density_function/overworld
// functions compiled for one seed. generate_noise_chunk calls density and cave through here, so engine access mods can
// hook them
import { type Density, DensityCompiler } from "./density.ts";
import { type DensityJson, type NoiseSettingsJson, range_test, type RangeJson } from "./data.ts";
import type { Generator } from "./generator.ts";
@@ -25,7 +24,7 @@ interface CompiledRule {
holds(climate: number[], surface: number, steep: boolean): boolean;
}
export class OverworldTerrain {
export class NoiseTerrain {
readonly seed: string;
readonly settings: NoiseSettingsJson;
readonly compiler: DensityCompiler;