Rework biome generation according to tectonic
This commit is contained in:
@@ -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<string, Surface> = {
|
||||
"bworld:deep_ocean": SEA_FLOOR,
|
||||
"bworld:deep_frozen_ocean": SEA_FLOOR,
|
||||
@@ -99,42 +97,33 @@ export const BIOMES: Record<string, Surface> = {
|
||||
"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<string, SeedGenerators>();
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user