More changes, im going to bed
This commit is contained in:
+2
-3
@@ -20,9 +20,8 @@ What world generation has today (see [World Generation](docs/modding/worldgen/in
|
||||
- **Determinism matters at chunk borders.** Every chunk generated is saved whole, like Minecraft, so a change to
|
||||
generation only shows in chunks never generated before. A chunk generated next to a saved one still takes the saved
|
||||
one's spills from generation, so features cross the border the same way only when generation hasn't changed.
|
||||
- **Heights and biomes for any column**, without generating its chunk: `OverworldTerrain.column` and `estimate_biome`.
|
||||
The biome is exact away from coasts and cliffs. The height is the height before 3D noise, so it isn't the real
|
||||
surface.
|
||||
- **Heights and biomes for any column**, without generating its chunk: `NoiseTerrain.column` and `estimate_biome`. The
|
||||
biome is exact away from coasts and cliffs. The height is the height before 3D noise, so it isn't the real surface.
|
||||
- **Blocks:** numeric states (up to 16 bits), `variants`, `parts`, shapes, tile data, containers, components and shared
|
||||
rules. Tags exist for blocks, items and entities. Biomes are a registry of data (`worldgen/biomes/` in a mod), but
|
||||
which one a column gets is data too, a biome source's rules (see [biomes.md](docs/modding/worldgen/biomes.md)).
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -53,11 +53,11 @@ made changes too. It returns a function that unhooks it.
|
||||
|
||||
## What's in `engine`
|
||||
|
||||
| Side | Where | Like |
|
||||
| -------- | -------------- | ------------------------------------------------------------------------------------------- |
|
||||
| `common` | every script | `EverythingRegistry`, `ItemStack`, `Container`, `BlockRules`, `OverworldTerrain`, `physics` |
|
||||
| `server` | server scripts | `GameServer`, `ServerWorld`, `ServerPlayer`, `Entity`, `Mob`, `ModRuntime`, the mob goals |
|
||||
| `client` | client scripts | `Client`, `LocalPlayer`, `ClientLevel`, `GameRenderer`, `Camera`, `GuiScreen` |
|
||||
| Side | Where | Like |
|
||||
| -------- | -------------- | ----------------------------------------------------------------------------------------- |
|
||||
| `common` | every script | `EverythingRegistry`, `ItemStack`, `Container`, `BlockRules`, `NoiseTerrain`, `physics` |
|
||||
| `server` | server scripts | `GameServer`, `ServerWorld`, `ServerPlayer`, `Entity`, `Mob`, `ModRuntime`, the mob goals |
|
||||
| `client` | client scripts | `Client`, `LocalPlayer`, `ClientLevel`, `GameRenderer`, `Camera`, `GuiScreen` |
|
||||
|
||||
The full lists are in `common/engine_modules.ts`, `server/game/engine_modules.ts` and `client/engine_modules.ts`. The
|
||||
types are the engine's own source, so `check-mods` typechecks against exactly the engine the mod runs on. `cubi/engine`
|
||||
@@ -68,7 +68,7 @@ also exports `game_version`, the version of the game that's running.
|
||||
- `#private` members can't be hooked. They're kept for things with rules that must hold, like a container's slots.
|
||||
- Hooks reach one JavaScript realm. Chunk workers run their own copy of the engine, so a client hook doesn't change
|
||||
meshing. The server generates chunks in worldgen workers, and each loads the worldgen scripts into its own copy, so
|
||||
hooks on the terrain (`engine.common.OverworldTerrain`) go in the worldgen script. A server script's hooks there only
|
||||
hooks on the terrain (`engine.common.NoiseTerrain`) go in the worldgen script. A server script's hooks there only
|
||||
reach the few chunks the game generates itself, so the world would come out different in places.
|
||||
|
||||
## Performance
|
||||
|
||||
@@ -282,8 +282,8 @@ A mod can add biomes to it, but can't replace its files yet: an id defined by tw
|
||||
changes the terrain changes land not generated yet in existing worlds, the same as adding a
|
||||
[feature](index.md#features). Every chunk generated is saved, so what's been generated stays as it was.
|
||||
|
||||
[Engine access](../misc/engine.md) mods can hook `engine.common.OverworldTerrain`, whose `density` and `cave` are called
|
||||
for every cell corner.
|
||||
[Engine access](../misc/engine.md) mods can hook `engine.common.NoiseTerrain`, whose `density` and `cave` are called for
|
||||
every cell corner.
|
||||
|
||||
`deno run -A tools/worldgen_preview.ts [seed] [out dir] [x z]` renders the base game's generator to PNG files, around
|
||||
chunk `x z`.
|
||||
|
||||
@@ -276,6 +276,7 @@ export class GameServer {
|
||||
});
|
||||
},
|
||||
});
|
||||
this.mods.storage = saved?.mod_storage ?? {};
|
||||
if (save) this.world.use_saved_chunks(save.chunks);
|
||||
this.world.time = saved?.time ?? 0;
|
||||
this.#day = this.world.day;
|
||||
|
||||
@@ -241,7 +241,7 @@ 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
|
||||
// a column's biome without generating its chunk, a little off near coasts and cliffs, see NoiseTerrain
|
||||
estimate_biome(x: number, z: number): { biome: string; y: number } {
|
||||
return this.worldgen.generator.for_seed(this.seed).estimate_biome(x, z);
|
||||
}
|
||||
|
||||
@@ -102,23 +102,6 @@ Deno.test("items only go in the slots they fit, and fall out when the player die
|
||||
assert(curios_items(t.take(1)).every((item: Msg) => item === null));
|
||||
});
|
||||
|
||||
Deno.test("curios worn when curios was a mod of its own are still worn", async () => {
|
||||
const t = await setup();
|
||||
t.send(1, { type: "click", menu: 0, slot: 0, button: 0, shift: true });
|
||||
t.game.on_disconnect(1);
|
||||
|
||||
// how a save from then kept which container is each player's curios
|
||||
const save = t.game.save();
|
||||
const level = JSON.parse(save.level);
|
||||
level.mod_storage.curios = { containers: level.mod_storage.bworld.curios };
|
||||
delete level.mod_storage.bworld.curios;
|
||||
|
||||
const loaded = await setup({ ...save, level: JSON.stringify(level) });
|
||||
const ring = loaded.game.players()[0].inventory_menu.extra[curio_slot(loaded, "ring")];
|
||||
assertEquals(ring.container.get_item(ring.index)?.to_data(), { id: "jewelry:ring", count: 1 });
|
||||
assertEquals(loaded.game.mods.storage.curios, undefined);
|
||||
});
|
||||
|
||||
Deno.test("the giant chestplate goes in the body slot and gives 20 more health while worn", async () => {
|
||||
const t = await setup();
|
||||
t.send(1, { type: "chat", text: "/give bworld:giant_chestplate" });
|
||||
|
||||
@@ -111,7 +111,7 @@ Deno.test("a worldgen mod hooks the terrain in engine.common", async () => {
|
||||
`import { engine, hook } from "cubi/engine";
|
||||
// no ground anywhere, so it's all sea
|
||||
export function setup() {
|
||||
hook(engine.common.OverworldTerrain.prototype, "density", { replace: () => -1 });
|
||||
hook(engine.common.NoiseTerrain.prototype, "density", { replace: () => -1 });
|
||||
}`,
|
||||
],
|
||||
})
|
||||
@@ -136,7 +136,7 @@ Deno.test({
|
||||
"worldgen.ts",
|
||||
`import { engine, hook } from "cubi/engine";
|
||||
export function setup() {
|
||||
hook(engine.common.OverworldTerrain.prototype, "density", { replace: () => -1 });
|
||||
hook(engine.common.NoiseTerrain.prototype, "density", { replace: () => -1 });
|
||||
}`,
|
||||
],
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user