Add natural mob spawning for rotwalker

This commit is contained in:
2026-09-30 22:15:42 -03:00
parent 0052faa24d
commit a6fd508529
22 changed files with 714 additions and 7 deletions
+41
View File
@@ -75,6 +75,22 @@ export interface OreJson {
threshold: number;
}
// mobs that spawn on their own, like neoforge's add_spawns biome modifier and undergarden's biome spawners. only
// monsters for now: in the dark near players, like minecraft's NaturalSpawner
export interface SpawnJson {
entity: string;
// how often it's picked over the other spawns where both can spawn
weight: number;
// how many spawn together
min_count: number;
max_count: number;
// only in these biomes, every biome when not set
biomes?: string[];
// the chance each spawn that passed every other check goes ahead, like undergarden's 1 in 10 for its rotspawn. 1
// when not set
chance?: number;
}
export interface ItemJson {
id: string;
texture: string;
@@ -701,6 +717,31 @@ export function validate_ore(json: unknown): Problems {
return problems;
}
export function validate_spawn(json: unknown): Problems {
if (!is_object(json)) return ["spawn must be an object"];
const problems = validate_id(json.entity, "entity");
for (const key of ["weight", "min_count", "max_count"]) {
if (!Number.isInteger(json[key]) || (json[key] as number) < (key === "weight" ? 0 : 1)) {
problems.push(
key === "weight"
? "weight must be a whole number, 0 or more"
: `${key} must be a whole number, 1 or more`,
);
}
}
if (typeof json.min_count === "number" && typeof json.max_count === "number" && json.min_count > json.max_count) {
problems.push("min_count must not be above max_count");
}
if (json.biomes !== undefined) {
if (!Array.isArray(json.biomes)) problems.push("biomes must be a list of biome ids");
else json.biomes.forEach((biome, i) => problems.push(...validate_id(biome, `biomes[${i}]`)));
}
if (json.chance !== undefined && (typeof json.chance !== "number" || !(json.chance > 0 && json.chance <= 1))) {
problems.push("chance must be a number above 0, at most 1");
}
return problems;
}
export function validate_entity(json: unknown): Problems {
if (!is_object(json)) return ["entity must be an object"];
const problems = [