Locate biome

This commit is contained in:
2026-10-02 14:16:50 -03:00
parent d2dde8c14f
commit 5a018a0470
4 changed files with 92 additions and 12 deletions
+14
View File
@@ -188,6 +188,20 @@ function generators_for(seed: string): SeedGenerators {
// fills blocks (indexed y * CHUNK_AREA + z * CHUNK_SIZE + x) and each column's surface height and biome.
// blocks trees put in other chunks go to spill
// a column's biome without generating its chunk, from its height before 3d noise, so it can be a little off near
// coasts and cliffs. for searching far away, like /locatebiome
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 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 };
const neighbors = [[x - 1, z], [x + 1, z], [x, z - 1], [x, z + 1]].map(([nx, nz]) => terrain.column(nx, nz));
const steep = neighbors.some((neighbor) => Math.abs(neighbor.height - column.height) >= STEEP);
return { biome: steep ? pick_biome(column, y, true) : flat, y };
}
export function generate_overworld(
blocks: Uint32Array,
heights: Int32Array,