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
+20 -1
View File
@@ -9,11 +9,13 @@ import {
type OreJson,
type RecipeJson,
SHARED_TAG_NAMESPACE,
type SpawnJson,
type TagJson,
type TagRegistry,
} from "./mod_data.ts";
import { BUILTIN_MODELS, type ModelJson } from "./block_models.ts";
import { resolve_tags } from "./tags.ts";
import { BIOMES } from "./worldgen/overworld.ts";
export interface ModReport {
id: string;
@@ -31,6 +33,7 @@ export interface LoadedMod {
items: { file: string; json: ItemJson }[];
recipes: { file: string; json: RecipeJson }[];
ores: { file: string; json: OreJson }[];
spawns: { file: string; json: SpawnJson }[];
entities: { file: string; json: EntityJson }[];
entity_models: { file: string; json: EntityModelJson }[];
tags: { file: string; json: TagJson }[];
@@ -72,6 +75,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
const item_owners = new Map<string, string[]>();
const model_owners = new Map<string, string[]>();
const entity_owners = new Map<string, string[]>();
const entity_jsons = new Map<string, EntityJson>();
const entity_model_owners = new Map<string, string[]>();
const tag_owners = new Map<TagRegistry, Set<string>>();
const add = (map: Map<string, string[]>, id: string, mod: string) => map.set(id, [...(map.get(id) ?? []), mod]);
@@ -85,7 +89,10 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
}
for (const { json } of mod.items) add(item_owners, json.id, mod.id);
for (const { json } of mod.models) add(model_owners, json.id, mod.id);
for (const { json } of mod.entities) add(entity_owners, json.id, mod.id);
for (const { json } of mod.entities) {
add(entity_owners, json.id, mod.id);
entity_jsons.set(json.id, json);
}
for (const { json } of mod.entity_models) add(entity_model_owners, json.id, mod.id);
for (const { json } of mod.tags) {
if (!tag_owners.has(json.registry)) tag_owners.set(json.registry, new Set());
@@ -203,6 +210,18 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
if (json.model !== undefined) uses(file, json.model, "entity model");
uses(file, json.texture, "texture");
}
for (const { file, json } of mod.spawns) {
check_namespace(file, json.entity);
const entity = entity_jsons.get(json.entity);
if (!entity) errors.push(`${file}: entity ${json.entity} doesn't exist`);
else if (entity.behavior !== "monster") {
errors.push(`${file}: ${json.entity} isn't a monster, only monsters spawn on their own for now`);
}
// biomes are the engine's, whatever their namespace
for (const biome of json.biomes ?? []) {
if (!(biome in BIOMES)) errors.push(`${file}: biome ${biome} doesn't exist`);
}
}
for (const { file, json } of mod.entity_models) {
if ((entity_model_owners.get(json.id)?.length ?? 0) > 1) {
errors.push(`${file}: entity model ${json.id} is defined more than once`);