Single module modding

This commit is contained in:
2026-11-14 12:18:41 -03:00
parent 605008f584
commit 313098892e
134 changed files with 919 additions and 924 deletions
+7 -7
View File
@@ -3,7 +3,7 @@
// data features: worldgen/features/<path>.json in a mod, a feature's type and config (what) with a list of placement
// modifiers (where), see docs/modding/worldgen/index.md. like minecraft's configured and placed features joined into
// one file. the types and modifiers here are built in, worldgen scripts register more
// one file. the types and modifiers here are built in, worldgen phases register more
import { EverythingRegistry } from "../everything_registry.ts";
import type { BlockRegistry } from "../everything_registry.ts";
import { CHUNK_SIZE } from "../constants.ts";
@@ -42,7 +42,7 @@ export const DEFAULT_STEP: FeatureStep = "top_layer_modification";
export interface FeatureJson {
id: string;
// a built in type, like "minecraft:block_column", or one a worldgen script registers
// a built in type, like "minecraft:block_column", or one a mod's worldgen phase registers
type: string;
config?: Record<string, unknown>;
placement?: PlacementJson[];
@@ -73,7 +73,7 @@ export function builtin_name(type: string): string | undefined {
export interface FeatureRefs {
blocks: Set<string>;
biomes: Set<string>;
// types and modifiers that aren't built in, which a worldgen script has to register
// types and modifiers that aren't built in, which a mod's worldgen phase has to register
custom: Set<string>;
}
@@ -141,7 +141,7 @@ const block_predicate_schema: z.ZodType = z.lazy(() =>
], "must be matching_blocks, solid, replaceable, would_survive, not, all_of, any_of or true")
);
// a mod's own modifier is checked by the worldgen script that registers it
// a mod's own modifier is checked by the worldgen phase that registers it
const placement_modifier = by_kind<PlacementJson>("type", (type) => {
const name = builtin_name(type);
if (name === undefined) return json_object;
@@ -156,7 +156,7 @@ const feature_schema: z.ZodType<FeatureJson> = z.object({
biomes: z.union([biome_id, z.array(biome_id)], "must be a biome's id or a list of them").optional(),
step: z.enum(FEATURE_STEPS).optional(),
}).superRefine((feature, ctx) => {
// a built in type's config. a mod's own type is checked by the worldgen script that registers it, like modifiers
// a built in type's config. a mod's own type is checked by the worldgen phase that registers it, like modifiers
const name = builtin_name(feature.type);
if (name === undefined) return;
if (!Object.hasOwn(FEATURE_TYPES, name)) {
@@ -205,7 +205,7 @@ export function compile_feature(
const type = types.get(json.type);
if (!type) {
throw new Error(
`feature ${json.id}: type ${json.type} isn't built in, and no worldgen script registered it`,
`feature ${json.id}: type ${json.type} isn't built in, and no mod's worldgen phase registered it`,
);
}
place = (chunk, origin) => type(chunk, config, origin);
@@ -216,7 +216,7 @@ export function compile_feature(
const custom = modifiers.get(modifier.type);
if (!custom) {
throw new Error(
`feature ${json.id}: placement[${i}] ${modifier.type} isn't built in, and no worldgen script registered it`,
`feature ${json.id}: placement[${i}] ${modifier.type} isn't built in, and no mod's worldgen phase registered it`,
);
}
return (chunk: FeatureChunk, positions: Position[]) => custom(chunk, modifier, positions);