diff --git a/common/worldgen/biome_colors.ts b/common/worldgen/biome_colors.ts index 63a2978..5d4c944 100644 --- a/common/worldgen/biome_colors.ts +++ b/common/worldgen/biome_colors.ts @@ -1,5 +1,5 @@ -// what color each biome tints grass and leaves, as 0xRRGGBB. minecraft's grass and foliage colors, with the terralith -// style biomes given the ones of the vanilla biome closest to them. blocks pick them with "tint" +// what color each biome tints grass and leaves, as 0xRRGGBB, minecraft's grass and foliage colors. blocks pick them +// with "tint" export const BIOME_GRASS_COLORS: Record = { "bworld:deep_ocean": 0x8eb971, "bworld:deep_frozen_ocean": 0x80b497, @@ -23,17 +23,10 @@ export const BIOME_GRASS_COLORS: Record = { "bworld:savanna": 0xbfb755, "bworld:jungle": 0x59c93c, "bworld:desert": 0xbfb755, - "bworld:alpine_highlands": 0x8ab689, "bworld:snowy_slopes": 0x80b497, "bworld:stony_peaks": 0x9abe4b, "bworld:jagged_peaks": 0x80b497, "bworld:frozen_peaks": 0x80b497, - "bworld:yosemite_cliffs": 0x86b783, - "bworld:snowy_cliffs": 0x80b497, - "bworld:painted_mountains": 0x90814d, - "bworld:stony_spires": 0x8ab689, - "bworld:shattered_savanna": 0xbfb755, - "bworld:skylands": 0x79c05a, }; export const BIOME_FOLIAGE_COLORS: Record = { @@ -59,17 +52,10 @@ export const BIOME_FOLIAGE_COLORS: Record = { "bworld:savanna": 0xaea42a, "bworld:jungle": 0x30bb0b, "bworld:desert": 0xaea42a, - "bworld:alpine_highlands": 0x6da36b, "bworld:snowy_slopes": 0x60a17b, "bworld:stony_peaks": 0x82ac1e, "bworld:jagged_peaks": 0x60a17b, "bworld:frozen_peaks": 0x60a17b, - "bworld:yosemite_cliffs": 0x68a464, - "bworld:snowy_cliffs": 0x60a17b, - "bworld:painted_mountains": 0x9e814d, - "bworld:stony_spires": 0x6da36b, - "bworld:shattered_savanna": 0xaea42a, - "bworld:skylands": 0x59ae30, }; // biomes mods add without a color, and items, which aren't in any biome diff --git a/common/worldgen/noise.ts b/common/worldgen/noise.ts index 415e99d..156e485 100644 --- a/common/worldgen/noise.ts +++ b/common/worldgen/noise.ts @@ -26,12 +26,19 @@ export function named_noise_3d(seed: string, name: string): NoiseFunction3D { return noise; } +// where an octave starts, like the random origin of each of minecraft's ImprovedNoise. simplex noise is 0 at 0 for +// every seed, so without it every world would have the same thing at 0, 0 +function octave_offset(seed: string, name: string): number[] { + const random = new Alea(`${seed}_${name}_offset`); + return [random.next() * 256, random.next() * 256, random.next() * 256]; +} + // several octaves of simplex noise, like minecraft's NormalNoise: each octave has twice the frequency and half the // strength of the last, times its amplitude. wavelength is the size in blocks of the first octave's features, an // amplitude of 0 skips that octave. the result is roughly -1 to 1 but bunched in the middle, see Quantiles for an // even spread export class OctaveNoise2D { - #octaves: { noise: NoiseFunction2D; frequency: number; amplitude: number }[] = []; + #octaves: { noise: NoiseFunction2D; frequency: number; amplitude: number; offset: number[] }[] = []; #total: number; constructor(seed: string, name: string, wavelength: number, amplitudes: number[]) { @@ -41,6 +48,7 @@ export class OctaveNoise2D { noise: named_noise_2d(seed, `${name}_${i}`), frequency: 2 ** i / wavelength, amplitude: amplitude / 2 ** i, + offset: octave_offset(seed, `${name}_${i}`), }); } }); @@ -49,15 +57,15 @@ export class OctaveNoise2D { sample(x: number, z: number) { let value = 0; - for (const { noise, frequency, amplitude } of this.#octaves) { - value += noise(x * frequency, z * frequency) * amplitude; + for (const { noise, frequency, amplitude, offset } of this.#octaves) { + value += noise(x * frequency + offset[0], z * frequency + offset[2]) * amplitude; } return value / this.#total; } } export class OctaveNoise3D { - #octaves: { noise: NoiseFunction3D; frequency: number; amplitude: number }[] = []; + #octaves: { noise: NoiseFunction3D; frequency: number; amplitude: number; offset: number[] }[] = []; #total: number; // how much slower it changes vertically than horizontally #vertical_stretch: number; @@ -69,6 +77,7 @@ export class OctaveNoise3D { noise: named_noise_3d(seed, `${name}_${i}`), frequency: 2 ** i / wavelength, amplitude: amplitude / 2 ** i, + offset: octave_offset(seed, `${name}_${i}`), }); } }); @@ -79,8 +88,9 @@ export class OctaveNoise3D { sample(x: number, y: number, z: number) { let value = 0; const sy = y / this.#vertical_stretch; - for (const { noise, frequency, amplitude } of this.#octaves) { - value += noise(x * frequency, sy * frequency, z * frequency) * amplitude; + for (const { noise, frequency, amplitude, offset } of this.#octaves) { + value += noise(x * frequency + offset[0], sy * frequency + offset[1], z * frequency + offset[2]) * + amplitude; } return value / this.#total; } diff --git a/common/worldgen/overworld.ts b/common/worldgen/overworld.ts index 1f33153..797aafc 100644 --- a/common/worldgen/overworld.ts +++ b/common/worldgen/overworld.ts @@ -45,8 +45,6 @@ interface Surface { underwater_filler: Palette; // cliffs show bare stone instead of top bare_cliffs: boolean; - // stripes of sand, stone and dirt down the cliffs, like badlands - strata?: boolean; } const GRASSY: Surface = { @@ -75,7 +73,7 @@ const STONY: Surface = { }; const SEA_FLOOR: Surface = { ...SANDY, filler_depth: 3 }; -// every biome the overworld has, and its surface. names follow minecraft's and terralith's +// every biome the overworld has, and its surface. names follow minecraft's export const BIOMES: Record = { "bworld:deep_ocean": SEA_FLOOR, "bworld:deep_frozen_ocean": SEA_FLOOR, @@ -99,42 +97,33 @@ export const BIOMES: Record = { "bworld:savanna": GRASSY, "bworld:jungle": GRASSY, "bworld:desert": SANDY, - "bworld:alpine_highlands": GRASSY, "bworld:snowy_slopes": SNOWY, "bworld:stony_peaks": STONY, "bworld:jagged_peaks": { ...STONY, top: "snow" }, "bworld:frozen_peaks": { ...SNOWY, filler: "stone" }, - "bworld:yosemite_cliffs": GRASSY, - "bworld:snowy_cliffs": SNOWY, - "bworld:painted_mountains": { ...SANDY, filler_depth: 2, bare_cliffs: true, strata: true }, - "bworld:stony_spires": GRASSY, - "bworld:shattered_savanna": GRASSY, - "bworld:skylands": GRASSY, }; // picks a column's biome from its climate and shape, like minecraft's multi noise biome source export function pick_biome(column: TerrainColumn, surface_y: number, steep: boolean): string { - const { continentalness: c, erosion: e, pv, temperature: t, humidity: h } = column.climate; + const { continentalness: c, erosion, ridges, temperature: t, humidity: h } = column.climate; + const flat = Math.abs(erosion); + const valley = Math.abs(ridges); const frozen = t < -0.65; const cold = t < -0.3; const warm = t > 0.2; const hot = t > 0.55; - if (column.island && surface_y >= column.island.bottom) { - return "bworld:skylands"; - } - if (surface_y < SEA_LEVEL - 1) { - if (pv < -0.7 && c > -0.12) return frozen ? "bworld:frozen_river" : "bworld:river"; + if (valley < 0.06 && c > -0.2) return frozen ? "bworld:frozen_river" : "bworld:river"; if (c < -0.45) { return frozen ? "bworld:deep_frozen_ocean" : hot ? "bworld:deep_lukewarm_ocean" : "bworld:deep_ocean"; } return frozen ? "bworld:frozen_ocean" : hot ? "bworld:warm_ocean" : "bworld:ocean"; } - if (c < -0.04 && surface_y <= SEA_LEVEL + 4) { + if (c < -0.12 && surface_y <= SEA_LEVEL + 4) { return steep ? "bworld:stony_shore" : cold ? "bworld:snowy_beach" : "bworld:beach"; } - if (pv < -0.8 && c > -0.12 && surface_y <= SEA_LEVEL + 1) { + if (valley < 0.04 && c > -0.2 && surface_y <= SEA_LEVEL + 1) { return frozen ? "bworld:frozen_river" : "bworld:river"; } @@ -143,17 +132,10 @@ export function pick_biome(column: TerrainColumn, surface_y: number, steep: bool if (cold) return "bworld:frozen_peaks"; return column.jaggedness > 0.35 ? "bworld:jagged_peaks" : "bworld:stony_peaks"; } - if (column.plateau > 0.5) { - if (hot && h < 0.1) return "bworld:painted_mountains"; - return cold ? "bworld:snowy_cliffs" : "bworld:yosemite_cliffs"; + if (above > 60 && cold) { + return "bworld:snowy_slopes"; } - if (column.shattered > 0.5) { - return warm ? "bworld:shattered_savanna" : "bworld:stony_spires"; - } - if (above > 60) { - return cold ? "bworld:snowy_slopes" : "bworld:alpine_highlands"; - } - if (above > 30 && e > -0.2 && !cold && h > -0.3) { + if (above > 30 && !cold && h > -0.3) { return "bworld:meadow"; } @@ -161,14 +143,13 @@ export function pick_biome(column: TerrainColumn, surface_y: number, steep: bool if (cold) return h > 0 ? "bworld:taiga" : "bworld:plains"; if (hot) return h < -0.2 ? "bworld:desert" : h < 0.4 ? "bworld:savanna" : "bworld:jungle"; if (warm) return h < -0.3 ? "bworld:savanna" : h > 0.6 ? "bworld:jungle" : "bworld:forest"; - if (h > 0.5 && e > 0.4) return "bworld:swamp"; + if (h > 0.5 && flat > 0.6) return "bworld:swamp"; return h < -0.35 ? "bworld:plains" : h < 0.45 ? "bworld:forest" : "bworld:dark_forest"; } interface SeedGenerators { terrain: OverworldTerrain; snow_line: OctaveNoise2D; - strata: OctaveNoise2D; } const generators = new Map(); @@ -179,7 +160,6 @@ function generators_for(seed: string): SeedGenerators { found = { terrain: new OverworldTerrain(seed), snow_line: new OctaveNoise2D(seed, "snow_line", 96, [1, 1]), - strata: new OctaveNoise2D(seed, "strata", 128, [1]), }; generators.set(seed, found); } @@ -193,7 +173,7 @@ function generators_for(seed: string): SeedGenerators { export function estimate_biome(seed: string, x: number, z: number): { biome: string; y: number } { const { terrain } = generators_for(seed); const column = terrain.column(x, z); - const y = Math.round(column.island ? column.island.top : column.height); + const y = Math.round(column.height); const flat = pick_biome(column, y, false); // most columns are the same either way, the neighbors are only worth sampling when they aren't if (flat === pick_biome(column, y, true)) return { biome: flat, y }; @@ -212,7 +192,7 @@ export function generate_overworld( ids: OverworldBlocks, spill: (x: number, y: number, z: number, block: number) => void, ) { - const { terrain, snow_line, strata } = generators_for(seed); + const { terrain, snow_line } = generators_for(seed); const x0 = chunk_x * CHUNK_SIZE; const z0 = chunk_z * CHUNK_SIZE; @@ -337,8 +317,6 @@ export function generate_overworld( const biome = pick_biome(column, surface_y, steep); const surface = BIOMES[biome]; const snow_y = SNOW_LINE + snow_line.sample(x0 + x, z0 + z) * 10; - const strata_offset = strata.sample(x0 + x, z0 + z) * 4; - const island_bottom = column.island ? column.island.bottom - 2 : Infinity; heights[z * CHUNK_SIZE + x] = surface_y; biomes[z * CHUNK_SIZE + x] = biome; @@ -346,46 +324,37 @@ export function generate_overworld( const index = (y: number) => y * CHUNK_AREA + z * CHUNK_SIZE + x; // solid blocks since the last air going down, 0 is a block with air on top let depth = -1; - // nothing but air (and sky islands) above so far: water fills it up to sea level + // nothing but air above so far: water fills it up to sea level let open_sky = true; // whether the ground's surface is under water, for its cover let underwater = false; for (let y = CHUNK_HEIGHT - 1; y >= 0; y--) { if (!is_solid[y]) { depth = -1; - if (open_sky && y < SEA_LEVEL) { + // and a river's tunnel under a mountain, and the caves it runs into + if ((open_sky || column.underground_river > 0) && y < SEA_LEVEL) { blocks[index(y)] = ids.water; } continue; } depth += 1; - const in_island = y >= island_bottom; - if (open_sky && !in_island) { + if (open_sky) { open_sky = false; underwater = y < SEA_LEVEL - 1; } // surface rules reach the ground and anything above it, not cave floors let block: Palette = "stone"; - if (y >= ground - SURFACE_REACH || in_island) { - const wet = underwater && !in_island; - if (surface.strata && depth > 0 && y > SEA_LEVEL) { - block = strata_block(y + strata_offset); - } else if (depth === 0) { - if (wet) block = surface.underwater_top; - else if (y >= snow_y && !in_island) block = steep ? "stone" : "snow"; + if (y >= ground - SURFACE_REACH) { + if (depth === 0) { + if (underwater) block = surface.underwater_top; + else if (y >= snow_y) block = steep ? "stone" : "snow"; else block = steep && surface.bare_cliffs ? "stone" : surface.top; } else if (depth <= surface.filler_depth) { - block = wet ? surface.underwater_filler : surface.filler; + block = underwater ? surface.underwater_filler : surface.filler; } } blocks[index(y)] = ids[block]; } } } - -// the bands down a painted mountain's cliffs -function strata_block(y: number): Palette { - const band = ((Math.floor(y / 3) % 6) + 6) % 6; - return band === 1 || band === 4 ? "stone" : band === 3 ? "dirt" : "sand"; -} diff --git a/common/worldgen/spline.ts b/common/worldgen/spline.ts index ee8f036..c22b44b 100644 --- a/common/worldgen/spline.ts +++ b/common/worldgen/spline.ts @@ -1,30 +1,24 @@ // minecraft's CubicSpline: a smooth curve through points, where a point's value can itself be a spline of another -// input. that nesting is how its terrain (and terralith's) turns continentalness, erosion and peaks and valleys into -// heights: a spline over continentalness whose points are splines over erosion, whose points are splines over pv +// input. that nesting is how its terrain (and tectonic's) turns continentalness, erosion and ridges into heights: +// a spline over continentalness whose points are splines over erosion, whose points are splines over ridges. +// K names the inputs, see TerrainInputs -export interface SplineInputs { - continentalness: number; - erosion: number; - pv: number; - weirdness: number; -} +export type SplineValue = number | Spline; -export type SplineValue = number | Spline; - -export interface SplinePoint { +export interface SplinePoint { at: number; - value: SplineValue; + value: SplineValue; // the slope there, worked out from the neighbors when not given slope?: number; } -export class Spline { - readonly input: keyof SplineInputs; +export class Spline { + readonly input: K; #locations: number[]; - #values: SplineValue[]; + #values: SplineValue[]; #slopes: number[]; - constructor(input: keyof SplineInputs, points: SplinePoint[]) { + constructor(input: K, points: SplinePoint[]) { this.input = input; this.#locations = points.map((point) => point.at); this.#values = points.map((point) => point.value); @@ -40,7 +34,7 @@ export class Spline { }); } - get(inputs: SplineInputs): number { + get(inputs: Readonly>): number { const x = inputs[this.input]; const locations = this.#locations; const last = locations.length - 1; @@ -67,11 +61,12 @@ export class Spline { } } -function value_of(value: SplineValue, inputs: SplineInputs) { +function value_of(value: SplineValue, inputs: Readonly>) { return typeof value === "number" ? value : value.get(inputs); } -// a spline through evenly spaced values of one input -export function spline(input: keyof SplineInputs, at: number[], values: SplineValue[]) { - return new Spline(input, at.map((location, i) => ({ at: location, value: values[i] }))); +// a spline through points given as [at, value, slope], like minecraft's json with its derivatives. slope is 0 when +// left out, like minecraft's +export function spline(input: K, points: [number, SplineValue, number?][]) { + return new Spline(input, points.map(([at, value, slope]) => ({ at, value, slope: slope ?? 0 }))); } diff --git a/common/worldgen/terrain.ts b/common/worldgen/terrain.ts index 5353ef1..adc6317 100644 --- a/common/worldgen/terrain.ts +++ b/common/worldgen/terrain.ts @@ -1,11 +1,14 @@ -// the shape of the overworld, built the way minecraft 1.18+ (and terralith on top of it) does it: -// large noises for continentalness, erosion and weirdness feed nested splines that give each column a target height, -// how jagged its peaks are and how rough its ground is. a 3d density around that height decides what's solid, -// and caves are cut out of it. terralith's flavor comes from the extra shapes: terraced plateaus with cliffs, -// shattered hills full of overhangs, deep river valleys and gorges, jagged peaks and rare sky islands +// the shape of the overworld, built the way minecraft 1.18+ does it and shaped after tectonic +// (https://github.com/Apollounknowndev/tectonic, MIT): large noises for continents, erosion and ridges feed nested +// splines that give each column a target height, how jagged its peaks are and how rough its ground is. a 3d density +// around that height decides what's solid, and caves are cut out of it. tectonic's look comes from its splines, +// ported here in its units (1 is 128 blocks): oceans that wind between big continents with islands out at sea, +// mountain ranges where erosion is low, rivers along the valleys between ridges that go underground through +// mountains, and on the flatter land four kinds of region picked by a slow noise and the climate: valleys and +// plateaus (and badlands ridges where it's hot), tiered mesas, rolling hills and jungle pillars, and wetlands and dunes import { CHUNK_HEIGHT, SEA_LEVEL } from "$/common/constants.ts"; -import { clamp, lerp, OctaveNoise2D, OctaveNoise3D, Quantiles, smoothstep } from "./noise.ts"; -import { Spline, spline, SplineInputs } from "./spline.ts"; +import { clamp, OctaveNoise2D, OctaveNoise3D, Quantiles, smoothstep } from "./noise.ts"; +import { Spline, spline } from "./spline.ts"; // measured with tools/noise_quantiles.ts const QUANTILES_6 = new Quantiles([ @@ -131,16 +134,16 @@ const TOP_SLIDE_START = CHUNK_HEIGHT - 24; const TOP_SLIDE_END = CHUNK_HEIGHT - 4; const MIN_CAVE_Y = 5; -// the climate at a column, every value spread evenly from -1 to 1 +// the climate at a column. continentalness, erosion and ridges are scaled to about tectonic's ranges, temperature and +// humidity are spread evenly from -1 to 1 export interface Climate { - // ocean far below 0, coast around -0.2, further inland higher + // tectonic's raw continents: deep ocean below -0.45, ocean to -0.2, the coast to 0, then further and further + // inland. islands raise it out at sea continentalness: number; - // low is mountains, high is flat land + // low is mountains, high is flat land. both ends are flat, see erosion_folded erosion: number; - // picks between variants, and its folded form pv - weirdness: number; - // peaks and valleys: -1 in a valley (rivers), 1 on a peak - pv: number; + // 0 along valleys, where rivers run, and further from 0 towards the ridges between them + ridges: number; temperature: number; humidity: number; } @@ -150,101 +153,369 @@ export interface TerrainColumn { climate: Climate; // where the ground's surface is before 3d noise, in blocks height: number; - // how much 3d noise moves the ground, in units of density + // how much 3d noise moves the ground, in units of density. high where tectonic's terrain is rugged roughness: number; - // 0 to 1, how much of it are terraced plateaus and shattered hills - plateau: number; - shattered: number; - // 0 to 1, how pointy its peaks are + // 0 to 1, how much its peaks are sharp ridges jaggedness: number; - // a sky island above it, when there is one - island?: { top: number; bottom: number }; + // 0 to 1, how close it is to the middle of a river that goes under a mountain here, see cave + underground_river: number; } -// minecraft's peaks and valleys: weirdness folded so both its ends are peaks and its middle a valley -export function peaks_and_valleys(weirdness: number) { - return 1 - Math.abs(3 * Math.abs(weirdness) - 2); -} +// what tectonic's splines read: the climate, folded, and the small noises its regions are made of +type Input = + | "continents" + | "erosion" + | "erosion_folded" + | "ridges" + | "ridges_folded" + | "region" + | "regions" + | "temperature" + | "vegetation" + | "lower_tier" + | "upper_tier" + | "badlands" + | "hills" + | "wetland" + | "pillar"; +type TerrainInputs = Record; +type S = Spline; +const s = (input: Input, points: [number, number | S, number?][]): S => spline(input, points); -// the valley value holds until -0.85, so rivers have a flat bottom and some width -const PV_POINTS = [-1, -0.85, -0.65, -0.35, 0, 0.45, 0.8, 1]; -const EROSION_POINTS = [-1, -0.6, -0.3, 0, 0.3, 0.6, 1]; +// tectonic's raw continents from how far the continents noise is from 0: 0 is the middle of an ocean +const CONTINENT_SHAPE = s("continents", [[0, 0], [0.4, 0.575, 1], [0.48, 0.68, 1]]); -// the heights over land at one level of continentalness, relative to sea level. base lifts everything, mountains -// scales how tall they get. each erosion gets a spline over peaks and valleys: a valley value, then how far above -// base the ground rises towards the peaks -function land(base: number, mountains: number): Spline { - const row = (valley: number, rises: number[]) => - spline("pv", PV_POINTS, [valley, valley, ...rises.map((rise) => base + rise * mountains)]); - return spline("erosion", EROSION_POINTS, [ - // barely eroded: huge mountains, their valleys are gorges high above the sea - row(base + 14 * mountains, [22, 44, 66, 88, 104, 110]), - row(base + 8 * mountains, [14, 28, 42, 54, 62, 66]), - // hills and highlands, their valleys carry rivers - row(-4, [8, 20, 28, 36, 42, 44]), - row(-5, [4, 10, 15, 20, 23, 24]), - row(-5, [2, 6, 9, 12, 13, 14]), - // worn flat: plains and wetlands - row(-4, [1, 3, 5, 7, 8, 8]), - row(-3, [0, 1, 2, 3, 3, 3]), - ]); -} - -// target height above sea level -const OFFSET = spline( - "continentalness", - [-1, -0.55, -0.3, -0.18, -0.12, -0.04, 0.2, 0.5, 1], - [-46, -32, -18, -8, -2, land(1, 0.3), land(3, 0.65), land(8, 1), land(14, 1.15)], -); - -// how pointy peaks get, 0 to 1. only tall, barely eroded mountains have them -const JAGGEDNESS = spline("erosion", [-1, -0.6, -0.3, 0], [ - spline("pv", [-0.2, 0.3, 1], [0, 0.6, 1]), - spline("pv", [0, 0.5, 1], [0, 0.4, 0.7]), - spline("pv", [0.3, 0.8, 1], [0, 0.2, 0.3]), - 0, +// tectonic's temperature and vegetation indexes, 1 to 5, from its climate parameters +const TEMPERATURE_INDEX = s("temperature", [ + [-0.48, 1], + [-0.42, 2], + [-0.18, 2], + [-0.12, 3], + [0.17, 3], + [0.23, 4], + [0.52, 4], + [0.58, 5], +]); +const VEGETATION_INDEX = s("vegetation", [ + [-0.38, 1], + [-0.32, 2], + [-0.13, 2], + [-0.07, 3], + [0.07, 3], + [0.13, 4], + [0.27, 4], + [0.33, 5], ]); -// 3d noise strength: mountains are rougher than plains -const ROUGHNESS = spline("erosion", [-1, -0.5, 0, 0.5, 1], [0.32, 0.22, 0.14, 0.1, 0.06]); +// from here on, tectonic's splines: heights in its units, relative to sea level + +// a river: down to below sea level where the ridges noise is 0, back up to the land around it +const RIVER = s("ridges_folded", [[0.03, -0.06, 0.5], [0.1, 0.01]]); +const GENTLE_RIVER = s("ridges_folded", [[0.03, -0.06, 0.5], [0.1, 0.01, 0.1]]); +const lower_tier = (low: number, high: number) => s("lower_tier", [[0, low], [0.15, high]]); +const badlands = (low: number, high: number) => s("badlands", [[0.45, 0.05], [0.6, low, 1.5], [0.63, high, 0.2]]); + +// club: valleys between plateaus, with badlands ridges where it's hot +const PLATEAUS = s("ridges", [ + [-0.5, 0.25, -0.1], + [-0.4, lower_tier(0.1, 0.22)], + [-0.3, 0.05, -0.8], + [-0.1, 0.01], + [-0.03, -0.06, -0.5], + [0.03, -0.06, 0.5], + [0.1, 0.01], + [0.3, 0.05, 0.8], + [0.4, lower_tier(0.135, 0.28)], + [0.5, 0.35, 0.1], +]); +const SINGLE_VALLEY = s("ridges", [ + [-0.5, 0.25, -0.1], + [-0.4, lower_tier(0.1, 0.22)], + [-0.3, 0.05, -0.8], + [-0.1, 0.01], + [-0.03, -0.06, -0.5], + [0.03, -0.06, 0.5], + [0.075, 0.01], + [0.14, 0.05, 0.8], + [0.2, lower_tier(0.135, 0.28)], + [0.3, 0.35], + [0.45, 0.03], +]); +const DOUBLE_VALLEY = s("ridges", [ + [-0.45, 0.03], + [-0.3, 0.25], + [-0.2, lower_tier(0.1, 0.22)], + [-0.125, 0.05, -0.8], + [-0.075, 0.01], + [-0.03, -0.06, -0.5], + [0.03, -0.06, 0.5], + [0.075, 0.01], + [0.125, 0.05, 0.8], + [0.2, lower_tier(0.135, 0.28)], + [0.3, 0.35], + [0.45, 0.03], +]); +const CLUB = s("temperature", [ + [1, PLATEAUS], + [2, s("vegetation", [[1, SINGLE_VALLEY], [2, PLATEAUS]])], + [3, s("vegetation", [[2, SINGLE_VALLEY], [3, PLATEAUS], [4, PLATEAUS], [5, DOUBLE_VALLEY]])], + [4, PLATEAUS], + [5, s("ridges_folded", [[0, -0.15, 2.5], [0.1, 0.04], [0.2, badlands(0.15, 0.185)], [0.3, badlands(0.185, 0.5)]])], +]); + +// heart: rolling hills where it's mild, and in jungles ridges cut by narrow valleys +const HEART = s("temperature", [ + [ + 3, + s("vegetation", [ + [2, s("ridges_folded", [[0.03, -0.06, 0.5], [0.1, 0.01, 0.1], [0.2, s("hills", [[0, 0.01, 0.225]])]])], + [3, GENTLE_RIVER], + ]), + ], + [ + 4, + s("vegetation", [ + [3, GENTLE_RIVER], + [ + 4, + s("ridges", [ + [-0.75, 0.05], + [-0.175, 0.015], + [-0.125, 0.01], + [-0.04, -0.06, -0.7], + [0.04, -0.06, 0.7], + [0.125, 0.01], + ]), + ], + [5, s("ridges_folded", [[0.04, -0.06, 0.7], [0.125, 0.01], [0.175, 0.015], [0.75, 0.05], [0.8, 0.6]])], + ]), + ], + [5, s("ridges_folded", [[0.03, -0.06, 0.5], [0.1, 0.01, 0.15]])], +]); + +// spade: land in tiers, and tall mesas where it's hot +const SPADE = s("temperature", [ + [ + 4, + s("ridges_folded", [ + [0.03, -0.06, 0.5], + [0.1, 0.01], + [0.3, 0.05, 0.8], + [0.4, lower_tier(0.1, 0.22)], + [0.55, 0.25, 1], + [0.6, s("upper_tier", [[0, 0.25], [0.15, 0.45]])], + [0.64, 0.5], + ]), + ], + [ + 5, + s("ridges_folded", [ + [0.025, -0.075, 0.03], + [0.1, 0.05], + [0.175, 0.1, 1.5], + [0.2, 0.225, 0.2], + [0.4, 0.6, 7], + [0.4, 0.6, 0.1], + [0.8, 0.7], + [0.85, 0.4], + [1, 0.4], + [1.05, 0.04], + ]), + ], +]); + +// diamond: flat land with wetlands, and deserts (their dunes are added on top, see DUNES) +const DIAMOND = s("temperature", [ + [ + 4, + s("vegetation", [ + [2, GENTLE_RIVER], + [ + 3, + s("ridges_folded", [ + [0.03, -0.06, 0.5], + [0.1, 0.01], + [0.15, s("wetland", [[-0.45, -0.03, 0.03], [-0.3, 0.005], [0.3, 0.005], [0.45, -0.03, -0.03]])], + ]), + ], + ]), + ], + [5, s("ridges_folded", [[0.03, -0.06, 0.5], [0.1, 0.01, 0.15]])], +]); + +// which region: by erosion's sign, then the slow region noise +const REGIONS = s("erosion", [ + [-0.02, s("region", [[-0.1, CLUB], [0.1, HEART]])], + [0.04, s("region", [[-0.1, SPADE], [0.1, DIAMOND]])], +]); + +// the regions, after REGIONS and its height multiplier +const REGION = s("regions", [[0, 0, 1]]); +const WEAK_REGION = s("regions", [[0, 0, 0.5]]); +const HILLS = s("ridges_folded", [[0, -0.1, 1], [0.175, 0.075, 0.3], [0.3, 0.25]]); +const LOW_RIDGES = s("ridges_folded", [[0.38, -0.03], [0.45, 0.03]]); +const inland = (top: number, high: number, low: number, ridge: number, regions_end: number, hills: number) => + s("erosion_folded", [ + [0, top], + [0.175, high], + [0.3, low], + [0.375, s("ridges_folded", [[0, -0.1], [0.1, 0.125, 5], [0.1667, 0.225], [0.3, ridge]])], + [0.425, WEAK_REGION], + [0.5, REGION], + [regions_end, REGION], + [hills, HILLS], + [0.95, HILLS], + [1.075, LOW_RIDGES], + ]); + +// shallower than tectonic's, the world goes 64 blocks below sea level instead of 128 +const DEEP_OCEAN = -0.33; +const OCEAN = -0.17; + +// target height above sea level: the ocean floor, then coasts, then further inland mountains where erosion is low +// and the regions where it's high +const OFFSET = s("continents", [ + [-0.45, DEEP_OCEAN], + [-0.35, OCEAN], + [-0.195, -0.14], + [ + -0.155, + s("erosion_folded", [ + [0.2, s("ridges_folded", [[0, -0.1], [0.15, 0.15, 3], [0.25, 0.22]]), -0.17], + [0.3, s("ridges_folded", [[0.03, -0.06, 0.5], [0.1, 0]])], + ]), + ], + [ + 0, + s("erosion_folded", [ + [0, 0.65], + [0.15, 0.425, -1.5], + [0.3, 0.33], + [0.375, s("ridges_folded", [[0, -0.1], [0.15, 0.15], [0.3, 0.25]])], + [0.4, RIVER], + [0.95, RIVER], + [1.075, LOW_RIDGES], + ]), + ], + [0.1, inland(0.95, 0.55, 0.36, 0.3, 0.825, 0.875)], + [0.8, inland(1.1, 0.65, 0.38, 0.33, 0.8, 0.9)], +]); + +// how jagged the peaks are, 0 to 0.2: only the tallest mountains, deep inland +const JAGGEDNESS = s("continents", [[0, 0], [0.175, s("erosion_folded", [[0, 0.2], [0.125, 0]])]]); + +// tectonic's factor: how steeply density rises below the surface. low is rugged ground full of overhangs, on the +// ridges of hilly land +const rugged = (ridges: S) => s("erosion_folded", [[0.825, 5.6], [0.875, ridges], [0.975, ridges], [1.025, 5.6]]); +const FACTOR = s("continents", [ + [-0.19, 5.6], + [-0.15, rugged(s("ridges", [[0, 5.6], [0.1, 0.6]]))], + [0.03, rugged(s("ridges", [[0, 5.6], [0.1, 0.6]]))], + [0.06, rugged(s("ridges_folded", [[0.25, 5.6], [0.4, 1.3]]))], +]); + +// how tall dunes get, up to 6, in hot flat land of the diamond region +const DUNE_HEIGHT = s("temperature", [ + [4, 0], + [5, s("region", [[0, 0], [0.1, s("ridges_folded", [[0, 0], [0.25, 6]])]])], +]); +const DUNES = s("continents", [ + [0, 0], + [0.05, s("erosion_folded", [[0.4, 0], [0.45, DUNE_HEIGHT], [0.8, DUNE_HEIGHT], [0.85, 0]])], +]); + +// jungle pillars: tall narrow columns in heart's jungles, on the ridges between its valleys +const pillar = (mid: number, high: number) => s("pillar", [[0.05, 0], [0.2, mid, -0.2], [0.5, high, 0.05]]); +const JUNGLE_PILLARS = s("region", [ + [0, 0], + [ + 0.1, + s("temperature", [ + [3, 0], + [ + 4, + s("vegetation", [ + [3, 0], + [4, s("ridges", [[-0.75, pillar(0.4, 0.7)], [-0.175, pillar(0.25, 0.5)], [-0.125, 0]])], + [ + 5, + s("ridges_folded", [[0.125, 0], [0.175, pillar(0.25, 0.5)], [0.75, pillar(0.45, 0.75)], [ + 0.8, + 0, + ]]), + ], + ]), + ], + [5, 0], + ]), + ], +]); +const PILLARS = s("continents", [ + [0, 0], + [0.1, s("erosion", [[-0.875, 0], [-0.825, JUNGLE_PILLARS], [-0.425, JUNGLE_PILLARS], [-0.375, 0]])], +]); + +// blocks per unit of tectonic's height. without its vertical scale of 1.125, which is for minecraft's taller world +const BLOCKS_PER_UNIT = 128; +// the 3d noise's strength at tectonic's usual factor +const ROUGHNESS = 0.12; +// rivers that reach mountains go under them in a tunnel this tall around sea level, this wide in ridges +const RIVER_TUNNEL_BOTTOM = SEA_LEVEL - 5; +const RIVER_TUNNEL_TOP = SEA_LEVEL + 4; +const RIVER_TUNNEL_WIDTH = 0.035; +// only where the ground is this far above the river, otherwise it's an open valley +const RIVER_TUNNEL_COVER = 12; export class OverworldTerrain { - #continentalness: OctaveNoise2D; + #continents: OctaveNoise2D; + #island_a: OctaveNoise2D; + #island_b: OctaveNoise2D; #erosion: OctaveNoise2D; - #weirdness: OctaveNoise2D; + #ridges: OctaveNoise2D; #temperature: OctaveNoise2D; #humidity: OctaveNoise2D; #warp_x: OctaveNoise2D; #warp_z: OctaveNoise2D; - #jagged: OctaveNoise2D; - #plateau: OctaveNoise2D; - #shattered: OctaveNoise2D; - #sky: OctaveNoise2D; - #island_shape: OctaveNoise2D; - #island_height: OctaveNoise2D; + #region: OctaveNoise2D; + #height_multiplier: OctaveNoise2D; + #lower_tier: OctaveNoise2D; + #upper_tier: OctaveNoise2D; + #badlands: OctaveNoise2D; + #hills: OctaveNoise2D; + #wetland: OctaveNoise2D; + #pillar: OctaveNoise2D; + #dune: OctaveNoise2D; + #dune_warp: OctaveNoise2D; + #mountain_ridges: OctaveNoise2D; #ground: OctaveNoise3D; - #island_noise: OctaveNoise3D; #cheese: OctaveNoise3D; #spaghetti_a: OctaveNoise3D; #spaghetti_b: OctaveNoise3D; #entrances: OctaveNoise2D; + // the amplitudes match the quantile tables above, so each noise can be spread evenly constructor(seed: string) { - this.#continentalness = new OctaveNoise2D(seed, "continentalness", 1024, [1, 1, 2, 2, 1, 1]); - this.#erosion = new OctaveNoise2D(seed, "erosion", 768, [1, 1, 0, 1, 1]); - this.#weirdness = new OctaveNoise2D(seed, "weirdness", 256, [1, 2, 1]); + this.#continents = new OctaveNoise2D(seed, "continents", 2560, [1, 1, 2, 2, 1, 1]); + this.#island_a = new OctaveNoise2D(seed, "island_a", 320, [1, 1]); + this.#island_b = new OctaveNoise2D(seed, "island_b", 320, [1, 1]); + this.#erosion = new OctaveNoise2D(seed, "erosion", 1280, [1, 1, 0, 1, 1]); + this.#ridges = new OctaveNoise2D(seed, "ridges", 640, [1, 2, 1]); this.#temperature = new OctaveNoise2D(seed, "temperature", 1536, [1.5, 0, 1]); this.#humidity = new OctaveNoise2D(seed, "humidity", 512, [1, 1]); this.#warp_x = new OctaveNoise2D(seed, "warp_x", 200, [1, 1]); this.#warp_z = new OctaveNoise2D(seed, "warp_z", 200, [1, 1]); - this.#jagged = new OctaveNoise2D(seed, "jagged", 48, [1, 1]); - this.#plateau = new OctaveNoise2D(seed, "plateau", 640, [1, 1]); - this.#shattered = new OctaveNoise2D(seed, "shattered", 512, [1, 1]); - this.#sky = new OctaveNoise2D(seed, "sky", 900, [1, 1]); - this.#island_shape = new OctaveNoise2D(seed, "island_shape", 56, [1, 1]); - this.#island_height = new OctaveNoise2D(seed, "island_height", 300, [1, 1]); + this.#region = new OctaveNoise2D(seed, "region", 2048, [1, 1, 2, 2, 1, 1]); + this.#height_multiplier = new OctaveNoise2D(seed, "height_multiplier", 1024, [1, 2, 1]); + this.#lower_tier = new OctaveNoise2D(seed, "lower_tier", 512, [1, 2, 1]); + this.#upper_tier = new OctaveNoise2D(seed, "upper_tier", 512, [1, 2, 1]); + this.#badlands = new OctaveNoise2D(seed, "badlands", 512, [1, 2, 1]); + this.#hills = new OctaveNoise2D(seed, "hills", 320, [1, 1]); + this.#wetland = new OctaveNoise2D(seed, "wetland", 96, [1, 1]); + this.#pillar = new OctaveNoise2D(seed, "pillar", 32, [1, 1]); + this.#dune = new OctaveNoise2D(seed, "dune", 96, [1, 1]); + this.#dune_warp = new OctaveNoise2D(seed, "dune_warp", 400, [1, 1]); + this.#mountain_ridges = new OctaveNoise2D(seed, "mountain_ridges", 256, [1, 1]); this.#ground = new OctaveNoise3D(seed, "ground", 64, [1, 1, 0.5], 1.2); - this.#island_noise = new OctaveNoise3D(seed, "island_noise", 24, [1, 1]); this.#cheese = new OctaveNoise3D(seed, "cheese", 80, [1, 0.5], 0.6); this.#spaghetti_a = new OctaveNoise3D(seed, "spaghetti_a", 64, [1], 0.8); this.#spaghetti_b = new OctaveNoise3D(seed, "spaghetti_b", 64, [1], 0.8); @@ -255,83 +526,84 @@ export class OverworldTerrain { // a small warp, so coasts and biome edges aren't the noise's smooth blobs const wx = x + this.#warp_x.sample(x, z) * 24; const wz = z + this.#warp_z.sample(x, z) * 24; - const weirdness = QUANTILES_3.even(this.#weirdness.sample(wx, wz)); return { - continentalness: QUANTILES_6.even(this.#continentalness.sample(wx, wz)), - erosion: QUANTILES_4.even(this.#erosion.sample(wx, wz)), - weirdness, - pv: peaks_and_valleys(weirdness), + continentalness: this.#continentalness(wx, wz), + erosion: QUANTILES_4.even(this.#erosion.sample(wx, wz)) * 1.05, + ridges: QUANTILES_3.even(this.#ridges.sample(wx, wz)) * 0.7, temperature: QUANTILES_TEMPERATURE.even(this.#temperature.sample(wx, wz)), humidity: QUANTILES_2.even(this.#humidity.sample(wx, wz)), }; } - column(x: number, z: number): TerrainColumn { - const climate = this.climate(x, z); - const { continentalness: c, erosion: e } = climate; - const inputs: SplineInputs = climate; - const inland = smoothstep(-0.1, 0.3, c); - - let height = OFFSET.get(inputs); - - // jagged peaks: sharp ridges pushed up from the tallest mountains - const jaggedness = clamp(JAGGEDNESS.get(inputs), 0, 1) * inland; - if (jaggedness > 0) { - const ridge = 1 - Math.abs(this.#jagged.sample(x, z)); - height += jaggedness * 26 * ridge * ridge; - } - - // terraced plateaus: raised land cut into flat benches and cliffs, like terralith's - // yosemite cliffs and painted mountains - const plateau = smoothstep(0.35, 0.55, QUANTILES_2.even(this.#plateau.sample(x, z))) * - smoothstep(-0.75, -0.45, e) * (1 - smoothstep(0.1, 0.4, e)) * smoothstep(-0.05, 0.1, c); - if (plateau > 0 && climate.pv > -0.8) { - const raised = height + 20 * plateau; - height = lerp(plateau, height, terrace(raised, 16)); - } - - // shattered hills: ground broken up by strong 3d noise into overhangs, arches and spires - const shattered = smoothstep(0.55, 0.75, QUANTILES_2.even(this.#shattered.sample(x, z))) * - smoothstep(-0.6, -0.3, e) * (1 - smoothstep(0.3, 0.5, e)) * smoothstep(-0.05, 0.1, c); - - const roughness = ROUGHNESS.get(inputs) + shattered * 0.9; - - return { - climate, - height: SEA_LEVEL + height, - roughness, - plateau, - shattered, - jaggedness, - island: this.#island(x, z), - }; + // like tectonic: land is where the continents noise is far from 0, so oceans wind along where it crosses 0. out + // in the deep ocean, islands come up where either of two island noises is high + #continentalness(x: number, z: number) { + const far = Math.abs(QUANTILES_6.even(this.#continents.sample(x, z))) * 0.85; + const continents = -0.8 + CONTINENT_SHAPE.get({ continents: far } as TerrainInputs); + if (continents >= -0.5) return continents; + // scaled so about 3 in 100 of the deep ocean is island, both noises are spread evenly unlike tectonic's + const island = Math.max( + QUANTILES_2.even(this.#island_a.sample(x, z)), + QUANTILES_2.even(this.#island_b.sample(x, z)), + ) * 0.76; + const deep = smoothstep(-0.5, -0.8, continents) * 0.7; + return Math.max(continents, (island + 0.05) * deep - 0.7); } - // skylands: rare regions of floating islands, flat topped with long hanging undersides - #island(x: number, z: number): TerrainColumn["island"] { - const region = smoothstep(0.9, 0.97, QUANTILES_2.even(this.#sky.sample(x, z))); - if (region <= 0) { - return undefined; + column(x: number, z: number): TerrainColumn { + const climate = this.climate(x, z); + const { continentalness, erosion, ridges } = climate; + const lower = QUANTILES_3.even(this.#lower_tier.sample(x, z)); + const upper = QUANTILES_3.even(this.#upper_tier.sample(x, z)); + const inputs: TerrainInputs = { + continents: continentalness, + erosion, + erosion_folded: Math.abs(erosion), + ridges, + ridges_folded: Math.abs(ridges), + region: QUANTILES_6.even(this.#region.sample(x, z)) * 0.5 + 0.1, + regions: 0, + temperature: TEMPERATURE_INDEX.get({ temperature: climate.temperature } as TerrainInputs), + vegetation: VEGETATION_INDEX.get({ vegetation: climate.humidity } as TerrainInputs), + lower_tier: Math.abs(lower) * 0.3, + upper_tier: Math.abs(upper) * 0.3, + badlands: Math.abs(QUANTILES_3.even(this.#badlands.sample(x, z))) * 0.7, + hills: Math.abs(QUANTILES_2.even(this.#hills.sample(x, z))), + wetland: QUANTILES_2.even(this.#wetland.sample(x, z)) * 0.6, + pillar: 1.7 * (QUANTILES_2.even(this.#pillar.sample(x, z)) * 0.7 - 0.35), + }; + const multiplier = clamp(1.2 + 0.4 * QUANTILES_3.even(this.#height_multiplier.sample(x, z)), 0.8, 1.6); + inputs.regions = multiplier * REGIONS.get(inputs); + + const offset = OFFSET.get(inputs) + PILLARS.get(inputs); + let height = offset * BLOCKS_PER_UNIT; + + // jagged peaks: sharp ridgelines along the tallest mountains + const jaggedness = clamp(JAGGEDNESS.get(inputs) / 0.2, 0, 1); + if (jaggedness > 0) { + const ridge = 1 - Math.abs(this.#mountain_ridges.sample(x, z)); + height += jaggedness * 36 * ridge * ridge; } - const shape = region * smoothstep(0.05, 0.35, this.#island_shape.sample(x, z)); - if (shape <= 0) { - return undefined; + + // dunes: long ridges of sand, swept one way + const dunes = DUNES.get(inputs) / 6; + if (dunes > 0) { + const sweep = this.#dune_warp.sample(x, z) * 40; + const crest = 1 - Math.abs(this.#dune.sample(x + sweep, z * 0.35)); + height += dunes * 7 * crest * crest; } - const center = 178 + this.#island_height.sample(x, z) * 24; - return { top: center + 2 + 6 * shape, bottom: center - 4 - 34 * shape * Math.sqrt(shape) }; + + const roughness = ROUGHNESS * 5.6 / FACTOR.get(inputs); + const valley = 1 - inputs.ridges_folded / RIVER_TUNNEL_WIDTH; + const covered = height > RIVER_TUNNEL_TOP - SEA_LEVEL + RIVER_TUNNEL_COVER; + const underground_river = valley > 0 && covered && continentalness > -0.17 ? valley : 0; + + return { climate, height: SEA_LEVEL + height, roughness, jaggedness, underground_river }; } // positive is solid, before caves density(column: TerrainColumn, x: number, y: number, z: number) { let density = (column.height - y) / THICKNESS + column.roughness * this.#ground.sample(x, y, z); - - const island = column.island; - if (island && y > island.bottom - 4 && y < island.top + 4) { - const solid = Math.min((island.top - y) / 3, (y - island.bottom) / 6) + - 0.4 * this.#island_noise.sample(x, y, z); - density = Math.max(density, solid); - } - if (y > TOP_SLIDE_START) { density -= smoothstep(TOP_SLIDE_START, TOP_SLIDE_END, y) * 4; } @@ -342,17 +614,23 @@ export class OverworldTerrain { } // negative where a cave is. caves stay under the ground's skin except at entrances, and never break - // the floor of oceans and rivers + // the floor of oceans and rivers. rivers under mountains are tunnels, see generate_overworld for their water cave(column: TerrainColumn, x: number, y: number, z: number) { if (y < MIN_CAVE_Y) { return 1; } + let river = 1; + if (column.underground_river > 0 && y >= RIVER_TUNNEL_BOTTOM - 2 && y <= RIVER_TUNNEL_TOP + 2) { + const middle = (RIVER_TUNNEL_BOTTOM + RIVER_TUNNEL_TOP) / 2; + const half = (RIVER_TUNNEL_TOP - RIVER_TUNNEL_BOTTOM) / 2; + river = (Math.max(1 - column.underground_river, Math.abs(y - middle) / half) - 1) * 4; + } const depth = column.height - y; if (column.height < SEA_LEVEL + 3 && depth < 14) { - return 1; + return river; } if (depth < 7 && this.#entrances.sample(x, z) < 0.5) { - return 1; + return river; } // cheese caves: big open caverns @@ -361,13 +639,6 @@ export class OverworldTerrain { const a = Math.abs(this.#spaghetti_a.sample(x, y, z)); const b = Math.abs(this.#spaghetti_b.sample(x, y, z)); const spaghetti = (Math.max(a, b) - 0.07) * 8; - return Math.min(cheese, spaghetti); + return Math.min(cheese, spaghetti, river); } } - -// flat benches every step blocks, joined by steep cliffs -function terrace(height: number, step: number) { - const k = height / step; - const floor = Math.floor(k); - return (floor + smoothstep(0.4, 0.6, k - floor)) * step; -} diff --git a/common/worldgen/trees.ts b/common/worldgen/trees.ts index f1ea664..abb1b6b 100644 --- a/common/worldgen/trees.ts +++ b/common/worldgen/trees.ts @@ -47,14 +47,8 @@ export const BIOME_TREES: Record "bworld:snowy_taiga": { chance: 0.6, kinds: ["spruce"] }, "bworld:snowy_plains": { chance: 0.03, kinds: ["spruce"] }, "bworld:snowy_slopes": { chance: 0.06, kinds: ["spruce"] }, - "bworld:snowy_cliffs": { chance: 0.1, kinds: ["spruce"] }, - "bworld:alpine_highlands": { chance: 0.2, kinds: ["spruce", "spruce", "oak"] }, - "bworld:yosemite_cliffs": { chance: 0.2, kinds: ["spruce", "oak"] }, - "bworld:stony_spires": { chance: 0.12, kinds: ["spruce"] }, "bworld:savanna": { chance: 0.15, kinds: ["acacia", "acacia", "oak"] }, - "bworld:shattered_savanna": { chance: 0.12, kinds: ["acacia"] }, "bworld:jungle": { chance: 1, kinds: ["jungle", "jungle", "big_oak"] }, - "bworld:skylands": { chance: 0.3, kinds: ["oak", "big_oak"] }, }; export interface TreeSite { diff --git a/docs/modding/worldgen/index.md b/docs/modding/worldgen/index.md index ba010e3..09e5502 100644 --- a/docs/modding/worldgen/index.md +++ b/docs/modding/worldgen/index.md @@ -94,13 +94,16 @@ Generated blocks don't run `on_create`, and worldgen scripts can't use the serve ## Terrain -The terrain itself is built into the engine (`common/worldgen/`). It works like Minecraft 1.18+ with the Terralith -datapack: continentalness, erosion and weirdness noises set every column's height and roughness, a 3D density is carved -into caves, and on top of that come terraced plateaus, shattered hills, river valleys and gorges, jagged peaks and rare -sky islands. Biome ids are the keys of `BIOMES` in `common/worldgen/overworld.ts`, like `bworld:yosemite_cliffs` or -`bworld:skylands`. +The terrain itself is built into the engine (`common/worldgen/`). It works like Minecraft 1.18+, shaped after the +[Tectonic](https://github.com/Apollounknowndev/tectonic) mod: continents, erosion and ridges noises set every column's +height and roughness, and a 3D density is carved into caves. Oceans wind between large continents, with islands out at +sea. Mountain ranges rise where erosion is low, and rivers run along the valleys between ridges, going underground where +they reach mountains. The flatter land is split into regions with their own shapes: valleys and plateaus (with badlands +ridges where it's hot), tiered mesas, rolling hills and jungle pillars, and wetlands and desert dunes. -`deno run -A tools/worldgen_preview.ts [seed]` renders it to PNG files. +Biome ids are the keys of `BIOMES` in `common/worldgen/overworld.ts`, like `bworld:plains` or `bworld:jagged_peaks`. + +`deno run -A tools/worldgen_preview.ts [seed] [out dir] [x z]` renders it to PNG files, around chunk `x z`. > [!NOTE] > `register_terrain` exists in the API for mods that replace the terrain generator, but it throws for now: the terrain diff --git a/mods/bworld/CREDITS.md b/mods/bworld/CREDITS.md index 24458be..d46ff6a 100644 --- a/mods/bworld/CREDITS.md +++ b/mods/bworld/CREDITS.md @@ -81,6 +81,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ``` +# Tectonic + +The overworld's terrain is shaped after Tectonic by Apollo: https://github.com/Apollounknowndev/tectonic + +License: MIT + # Voxel libre https://github.com/VoxeLibre/VoxeLibre diff --git a/tests/fishing_test.ts b/tests/fishing_test.ts index 33774b1..d5057a1 100644 --- a/tests/fishing_test.ts +++ b/tests/fishing_test.ts @@ -9,6 +9,8 @@ import { test_game } from "./helpers.ts"; type Msg = any; const ROD = "bworld:fishing_rod"; +// below where the hook floats, even at the bottom of its bobbing, see the bworld mod's fishing +const HOOK_UNDER = 0.3; // a player on a stone floor at y 99 with water next to them and a rod in hand async function setup() { @@ -27,16 +29,15 @@ async function setup() { const cast = () => t.send(1, { type: "use_block", x: 2, y: 100, z: 0, face: "top" }); const reel = () => t.send(1, { type: "use_item" }); const fish = () => inventory().filter((i: Msg) => i?.id === "bworld:cod" || i?.id === "bworld:salmon"); - // ticks until something bites, false if nothing did in 35 seconds + const hooks = () => t.game.entities.all().filter((e) => e.type === "bworld:fishing_hook"); + // ticks until something bites, which pulls the hook under the water. false if nothing did in 35 seconds const wait_for_bite = () => { - t.take(1); for (let i = 0; i < 700; i++) { t.game.tick(); - if (t.take(1).some((m: Msg) => m.type === "chat" && m.text.includes("biting"))) return true; + if (hooks()[0]?.y < 101 - HOOK_UNDER) return true; } return false; }; - const hooks = () => t.game.entities.all().filter((e) => e.type === "bworld:fishing_hook"); return { ...t, slot, rod, cast, reel, fish, wait_for_bite, hooks }; } diff --git a/tests/helpers.ts b/tests/helpers.ts index f7ca485..7d60b0c 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -44,8 +44,9 @@ export function mod_sources(mods_dir: string): ServerModSource[] { }); } -// a game with an in memory host that remembers what it sent to each connection -export async function test_game(mods_dir: string, save?: WorldSave, seed = "test-seed") { +// a game with an in memory host that remembers what it sent to each connection. the seed has low, dry land around +// 0, 0, where players spawn and where tests build things +export async function test_game(mods_dir: string, save?: WorldSave, seed = "test-seed-90") { EverythingRegistry.clear(); const outbox = new Map(); const closed = new Set(); diff --git a/tests/worldgen_test.ts b/tests/worldgen_test.ts index bab05c0..e7d5d74 100644 --- a/tests/worldgen_test.ts +++ b/tests/worldgen_test.ts @@ -55,7 +55,7 @@ Deno.test("trees grow on the ground, never closer than 4 blocks, even across chu let spilled_leaves = 0; for (let cx = -6; cx < 6; cx++) { for (let cz = -6; cz < 6; cz++) { - const { blocks, spills } = generate_raw_chunk(cx, cz, "trees-test", ids); + const { blocks, spills } = generate_raw_chunk(cx, cz, game.world.seed, ids); blocks.forEach((block, i) => { if (logs.has(block) && ground.has(blocks[i - CHUNK_AREA])) { const x = cx * 16 + (i % 16); diff --git a/tools/worldgen_preview.ts b/tools/worldgen_preview.ts index e20fc87..079ee97 100644 --- a/tools/worldgen_preview.ts +++ b/tools/worldgen_preview.ts @@ -1,8 +1,8 @@ // renders the world generator to png files, for tuning it without starting the game: -// deno run -A tools/worldgen_preview.ts [seed] [out dir] +// deno run -A tools/worldgen_preview.ts [seed] [out dir] [x z, the middle, in chunks] // map.png: 4096 blocks across from the terrain's heights and biomes (fast, no caves or 3d noise) // blocks.png: 768 blocks across from real generated chunks, top block with hill shading -// section.png: a slice down through the world along x, showing caves, overhangs and islands +// section.png: a slice down through the world along x, showing caves, overhangs and underground rivers import { CHUNK_AREA, CHUNK_HEIGHT, CHUNK_SIZE, SEA_LEVEL } from "$/common/constants.ts"; import { generate_raw_chunk } from "$/common/generation.ts"; import { OverworldTerrain } from "$/common/worldgen/terrain.ts"; @@ -10,6 +10,7 @@ import { pick_biome } from "$/common/worldgen/overworld.ts"; const seed = Deno.args[0] ?? "preview"; const out = Deno.args[1] ?? "."; +const [center_x, center_z] = [Number(Deno.args[2] ?? 0), Number(Deno.args[3] ?? 0)]; const NAMES = [ "bworld:stone", @@ -67,17 +68,10 @@ const BIOME_COLORS: Record = { "bworld:savanna": [190, 180, 90], "bworld:jungle": [40, 160, 40], "bworld:desert": [240, 215, 140], - "bworld:alpine_highlands": [120, 150, 110], "bworld:snowy_slopes": [220, 230, 240], "bworld:stony_peaks": [150, 145, 140], "bworld:jagged_peaks": [200, 200, 215], "bworld:frozen_peaks": [210, 225, 250], - "bworld:yosemite_cliffs": [120, 120, 90], - "bworld:snowy_cliffs": [200, 205, 210], - "bworld:painted_mountains": [200, 120, 70], - "bworld:stony_spires": [110, 120, 100], - "bworld:shattered_savanna": [170, 150, 80], - "bworld:skylands": [255, 120, 220], }; async function write_png(path: string, width: number, height: number, rgb: Uint8Array) { @@ -140,14 +134,13 @@ const shade = (color: [number, number, number], factor: number): [number, number const started = performance.now(); for (let pz = 0; pz < size; pz++) { for (let px = 0; px < size; px++) { - const x = (px - size / 2) * step; - const z = (pz - size / 2) * step; + const x = (px - size / 2) * step + center_x * CHUNK_SIZE; + const z = (pz - size / 2) * step + center_z * CHUNK_SIZE; const column = terrain.column(x, z); heights[pz * size + px] = column.height; const surface = Math.round(column.height); const biome = pick_biome(column, surface, false); - let color = BIOME_COLORS[biome] ?? [255, 0, 255]; - if (column.island) color = [255, 120, 220]; + const color = BIOME_COLORS[biome] ?? [255, 0, 255]; rgb.set(color, (pz * size + px) * 3); } } @@ -181,8 +174,8 @@ const shade = (color: [number, number, number], factor: number): [number, number const started = performance.now(); for (let cz = 0; cz < chunks; cz++) { for (let cx = 0; cx < chunks; cx++) { - const chunk_x = origin / CHUNK_SIZE + cx; - const chunk_z = origin / CHUNK_SIZE + cz; + const chunk_x = origin / CHUNK_SIZE + cx + center_x; + const chunk_z = origin / CHUNK_SIZE + cz + center_z; const { blocks } = generate_raw_chunk(chunk_x, chunk_z, seed, block_ids); for (let lz = 0; lz < CHUNK_SIZE; lz++) { for (let lx = 0; lx < CHUNK_SIZE; lx++) {