World shape for dimension

This commit is contained in:
2026-11-06 22:49:43 -03:00
parent 7458a2d42a
commit 818ce22dd6
60 changed files with 749 additions and 349 deletions
+16 -18
View File
@@ -6,7 +6,7 @@
// one file. the types and modifiers here are built in, worldgen scripts register more
import { EverythingRegistry } from "../everything_registry.ts";
import type { BlockRegistry } from "../everything_registry.ts";
import { CHUNK_HEIGHT, CHUNK_SIZE } from "../constants.ts";
import { CHUNK_SIZE } from "../constants.ts";
import * as z from "zod";
import {
add_problems,
@@ -371,8 +371,8 @@ const MODIFIERS: Record<string, Builtin<Modifier>> = {
return (chunk, positions) =>
positions.flatMap((p) => {
if (!inside(chunk, p.x, p.z)) return [];
let y = CHUNK_HEIGHT - 1;
while (y >= 0 && !counts_for_heightmap(chunk.get_block(p.x, y, p.z), floor)) y--;
let y = chunk.max_y - 1;
while (y >= chunk.min_y && !counts_for_heightmap(chunk.get_block(p.x, y, p.z), floor)) y--;
return [{ x: p.x, y: y + 1, z: p.z }];
});
},
@@ -457,7 +457,7 @@ function block_predicate(json: unknown): Predicate {
// whether a block could be at x y z: where it is, it isn't air, and it can stand on what's under it (place_on)
function survives(chunk: FeatureChunk, id: string, x: number, y: number, z: number) {
if (y < 0 || y >= CHUNK_HEIGHT) return false;
if (y < chunk.min_y || y >= chunk.max_y) return false;
const below = block_at(chunk, x, y - 1, z);
return below !== undefined && can_stand_on(EverythingRegistry.get<BlockRegistry>("blocks", id), below);
}
@@ -518,24 +518,22 @@ function int_provider(json: unknown): IntProvider {
// heights: an anchor ({ "absolute" }, { "above_bottom" } or { "below_top" }), { "type": "constant", "value": anchor }
// or { "type": "uniform", "min_inclusive": anchor, "max_inclusive": anchor }
function anchor(json: unknown): number {
// the bottom and top are the chunk's dimension's
function anchor(json: unknown): IntProvider {
const object = json as Record<string, number>;
if (object.absolute !== undefined) return object.absolute;
if (object.above_bottom !== undefined) return object.above_bottom;
return CHUNK_HEIGHT - 1 - object.below_top;
if (object.absolute !== undefined) return () => object.absolute;
if (object.above_bottom !== undefined) return (chunk) => chunk.min_y + object.above_bottom;
return (chunk) => chunk.max_y - 1 - object.below_top;
}
function height_provider(json: unknown): IntProvider {
const object = json as Record<string, unknown>;
if (object.type === undefined) {
const y = anchor(object);
return () => y;
}
if (builtin_name(String(object.type)) === "constant") {
const y = anchor(object.value);
return () => y;
}
if (object.type === undefined) return anchor(object);
if (builtin_name(String(object.type)) === "constant") return anchor(object.value);
const min = anchor(object.min_inclusive);
const span = anchor(object.max_inclusive) - min + 1;
return (chunk) => min + Math.floor(chunk.rng.next() * span);
const max = anchor(object.max_inclusive);
return (chunk) => {
const low = min(chunk);
return low + Math.floor(chunk.rng.next() * (max(chunk) - low + 1));
};
}