World gen stuff

This commit is contained in:
2026-11-13 00:01:59 -03:00
parent e013fbe550
commit e8ca9753f5
25 changed files with 645 additions and 162 deletions
+13 -3
View File
@@ -13,6 +13,7 @@ import { generate_noise_chunk } from "./worldgen/noise_chunk.ts";
import { get_biome } from "./worldgen/biomes.ts";
import type { Generator } from "./worldgen/generator.ts";
import { named_noise_2d, named_noise_3d } from "./worldgen/noise.ts";
import { Tags } from "./tags.ts";
export { named_noise_2d, named_noise_3d };
@@ -115,8 +116,17 @@ function generate_ores(
default_values: number[] | undefined,
) {
const usable = ores
.map((ore) => ({ ...ore, nid: block_ids[ore.id], replaces_nid: block_ids[ore.replaces] }))
.filter((ore) => ore.nid !== undefined && ore.replaces_nid !== undefined);
.map((ore) => ({
...ore,
nid: block_ids[ore.id],
replaces_nids: new Set(
[ore.replaces].flat()
.flatMap((id) => id.startsWith("#") ? Tags.get("blocks", id) : [id])
.map((id) => block_ids[id])
.filter((nid) => nid !== undefined),
),
}))
.filter((ore) => ore.nid !== undefined && ore.replaces_nids.size > 0);
if (usable.length === 0) {
return;
}
@@ -132,7 +142,7 @@ function generate_ores(
}
for (let i = 0; i < usable.length; i++) {
const ore = usable[i];
if (current !== ore.replaces_nid || y < ore.min_y || y > ore.max_y) {
if (!ore.replaces_nids.has(current) || y < ore.min_y || y > ore.max_y) {
continue;
}
const wx = chunk_x * CHUNK_SIZE + lx;
+1 -1
View File
@@ -369,7 +369,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
}
for (const { file, json } of mod.ores) {
uses(file, json.id, "block");
uses(file, json.replaces, "block");
for (const replaces of [json.replaces].flat()) uses(file, replaces, "block");
}
for (const { file, json } of mod.entities) {
if ((entity_owners.get(json.id)?.length ?? 0) > 1) {
+2 -1
View File
@@ -330,7 +330,8 @@ const model_schema: z.ZodType<ModelFileJson> = z.object({
const ore_schema = z.object({
id,
replaces: id,
// a block, a "#tag" of blocks, or a list of those
replaces: z.union([id_or_tag, z.array(id_or_tag).min(1)]),
min_y: z.number(),
max_y: z.number(),
scale: z.number(),
+6
View File
@@ -109,6 +109,8 @@ export type SurfaceConditionJson =
| { type: "bare_cliffs" }
// at or above where a density function says
| { type: "y_at_least"; function: DensityJson }
// where a density function is in a range
| ({ type: "density"; function: DensityJson } & RangeJson)
| { type: "biome"; biome_is: string[] }
| { type: "not"; invert: SurfaceConditionJson };
@@ -283,6 +285,10 @@ const surface_condition: z.ZodType<SurfaceConditionJson> = z.lazy(() =>
z.object({ type: z.literal(["filler_depth", "surface_underwater", "steep", "bare_cliffs"]) }),
z.object({ type: z.literal("above_preliminary_surface"), offset: z.number().optional() }),
z.object({ type: z.literal("y_at_least"), function: density }),
z.object({ type: z.literal("density"), function: density, ...bounds(z.number()) }).refine(
has_bound,
NEEDS_BOUND,
),
z.object({ type: z.literal("biome"), biome_is: z.array(biome_id) }),
z.object({ type: z.literal("not"), invert: surface_condition }),
])
+5
View File
@@ -90,6 +90,11 @@ function compile_condition(json: SurfaceConditionJson, terrain: NoiseTerrain): C
const at = terrain.compiler.compile(json.function);
return (context) => context.y >= at(context.x, context.y, context.z);
}
case "density": {
const value = terrain.compiler.compile(json.function);
const test = range_test(json);
return (context) => test(value(context.x, context.y, context.z));
}
case "biome": {
const biomes = new Set(json.biome_is);
return (context) => biomes.has(context.biome);