World shape for dimension
This commit is contained in:
@@ -5,7 +5,8 @@
|
||||
// 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 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 { CHUNK_AREA, CHUNK_SIZE } from "@/common/constants.ts";
|
||||
import type { WorldShape } from "@/common/world_shape.ts";
|
||||
import { get_biome } from "./biomes.ts";
|
||||
import type { NoiseTerrain, TerrainColumn } from "./terrain.ts";
|
||||
import {
|
||||
@@ -16,7 +17,7 @@ import {
|
||||
type SurfaceContext,
|
||||
} from "./surface_rules.ts";
|
||||
|
||||
// fills blocks (indexed y * CHUNK_AREA + z * CHUNK_SIZE + x) and each column's surface height and biome. block is
|
||||
// fills blocks (indexed (y - min_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_noise_chunk(
|
||||
blocks: Uint32Array,
|
||||
@@ -24,6 +25,7 @@ export function generate_noise_chunk(
|
||||
biomes: string[],
|
||||
chunk_x: number,
|
||||
chunk_z: number,
|
||||
shape: WorldShape,
|
||||
terrain: NoiseTerrain,
|
||||
block: (id: string) => number,
|
||||
) {
|
||||
@@ -32,8 +34,9 @@ export function generate_noise_chunk(
|
||||
const cell_height = settings.terrain.cell_height;
|
||||
const cave_cell_height = settings.caves.cell_height;
|
||||
const corners = CHUNK_SIZE / cell_width + 1;
|
||||
const terrain_levels = CHUNK_HEIGHT / cell_height + 1;
|
||||
const cave_levels = CHUNK_HEIGHT / cave_cell_height + 1;
|
||||
const { min_y, max_y, height } = shape;
|
||||
const terrain_levels = height / cell_height + 1;
|
||||
const cave_levels = height / cave_cell_height + 1;
|
||||
const x0 = chunk_x * CHUNK_SIZE;
|
||||
const z0 = chunk_z * CHUNK_SIZE;
|
||||
|
||||
@@ -51,10 +54,10 @@ export function generate_noise_chunk(
|
||||
const x = x0 + (i % corners) * cell_width;
|
||||
const z = z0 + Math.floor(i / corners) * cell_width;
|
||||
for (let level = 0; level < terrain_levels; level++) {
|
||||
solid[i * terrain_levels + level] = terrain.density(column, x, level * cell_height, z);
|
||||
solid[i * terrain_levels + level] = terrain.density(column, x, min_y + level * cell_height, z);
|
||||
}
|
||||
for (let level = 0; level < cave_levels; level++) {
|
||||
caves[i * cave_levels + level] = terrain.cave(column, x, level * cave_cell_height, z);
|
||||
caves[i * cave_levels + level] = terrain.cave(column, x, min_y + level * cave_cell_height, z);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,9 +137,9 @@ export function generate_noise_chunk(
|
||||
grid[c00 * levels + level] * w00 + grid[c10 * levels + level] * w10 +
|
||||
grid[c01 * levels + level] * w01 + grid[c11 * levels + level] * w11;
|
||||
|
||||
// solid where both the terrain and the caves are above 0
|
||||
const is_solid = new Uint8Array(CHUNK_HEIGHT);
|
||||
for (let y = 0; y < CHUNK_HEIGHT; y++) {
|
||||
// solid where both the terrain and the caves are above 0, by y above min_y
|
||||
const is_solid = new Uint8Array(height);
|
||||
for (let y = 0; y < height; y++) {
|
||||
const level = Math.min(Math.floor(y / cell_height), terrain_levels - 2);
|
||||
const t = (y - level * cell_height) / cell_height;
|
||||
let density = blend(solid, terrain_levels, level) * (1 - t) + blend(solid, terrain_levels, level + 1) * t;
|
||||
@@ -151,8 +154,8 @@ export function generate_noise_chunk(
|
||||
}
|
||||
|
||||
const column = column_at(x, z);
|
||||
let surface_y = CHUNK_HEIGHT - 1;
|
||||
while (surface_y > 0 && !is_solid[surface_y]) surface_y--;
|
||||
let surface_y = max_y - 1;
|
||||
while (surface_y > min_y && !is_solid[surface_y - min_y]) surface_y--;
|
||||
|
||||
const ground = column.height;
|
||||
const neighbors = [column_at(x - 1, z), column_at(x + 1, z), column_at(x, z - 1), column_at(x, z + 1)];
|
||||
@@ -168,7 +171,7 @@ export function generate_noise_chunk(
|
||||
context.preliminary = ground;
|
||||
context.biome = biome;
|
||||
context.surface = surface_of(biome);
|
||||
const index = (y: number) => y * CHUNK_AREA + z * CHUNK_SIZE + x;
|
||||
const index = (y: number) => (y - min_y) * CHUNK_AREA + z * CHUNK_SIZE + x;
|
||||
// the same sum as the rule's own condition, so it can't disagree with it
|
||||
const lowest = ground + reach;
|
||||
// solid blocks since the last air going down, 0 is a block with air on top
|
||||
@@ -177,9 +180,9 @@ export function generate_noise_chunk(
|
||||
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--) {
|
||||
for (let y = max_y - 1; y >= min_y; y--) {
|
||||
context.y = y;
|
||||
if (!is_solid[y]) {
|
||||
if (!is_solid[y - min_y]) {
|
||||
depth = -1;
|
||||
if (y < fluid_top) {
|
||||
const fluid = fluids(context, open_sky);
|
||||
|
||||
Reference in New Issue
Block a user