Messy but working chicken

This commit is contained in:
2026-09-28 17:42:56 -03:00
parent fe149bb9ad
commit d606bc4b55
22 changed files with 622 additions and 21 deletions
+30 -2
View File
@@ -1,6 +1,14 @@
// checks between mods: dependencies, load order, and ids one mod uses from another. pure, so the build, check-mods
// and the server (on .bmod files) all use it
import { type BlockJson, choice_ids, type ItemJson, type OreJson, type RecipeJson } from "./mod_data.ts";
import {
type BlockJson,
choice_ids,
type EntityJson,
type EntityModelJson,
type ItemJson,
type OreJson,
type RecipeJson,
} from "./mod_data.ts";
import { BUILTIN_MODELS, type ModelJson } from "./block_models.ts";
export interface ModReport {
@@ -19,6 +27,8 @@ export interface LoadedMod {
items: { file: string; json: ItemJson }[];
recipes: { file: string; json: RecipeJson }[];
ores: { file: string; json: OreJson }[];
entities: { file: string; json: EntityJson }[];
entity_models: { file: string; json: EntityModelJson }[];
textures: string[];
// absolute paths by texture id
texture_files: Map<string, string>;
@@ -56,6 +66,8 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
const block_owners = new Map<string, string[]>();
const item_owners = new Map<string, string[]>();
const model_owners = new Map<string, string[]>();
const entity_owners = new Map<string, string[]>();
const entity_model_owners = new Map<string, string[]>();
const add = (map: Map<string, string[]>, id: string, mod: string) => map.set(id, [...(map.get(id) ?? []), mod]);
const textures = new Set<string>(engine_textures);
@@ -67,6 +79,8 @@ 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.entity_models) add(entity_model_owners, json.id, mod.id);
for (const texture of mod.textures) textures.add(texture);
}
@@ -81,13 +95,15 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
if (!mod_ids.has(dep)) errors.push(`manifest.json: depends on "${dep}", which isn't installed`);
}
const uses = (file: string, id: string, what: "block" | "item" | "texture" | "model") => {
const uses = (file: string, id: string, what: "block" | "item" | "texture" | "model" | "entity model") => {
const namespace = id.split(":")[0];
if (namespace !== mod.id && namespace !== "engine" && !dependencies.has(namespace)) {
warnings.push(`${file}: uses ${id} but doesn't list "${namespace}" in dependencies`);
}
if (what === "model") {
if (!BUILTIN_MODELS[id] && !model_owners.has(id)) errors.push(`${file}: model ${id} doesn't exist`);
} else if (what === "entity model") {
if (!entity_model_owners.has(id)) errors.push(`${file}: entity model ${id} doesn't exist`);
} else if (what === "texture") {
if (!textures.has(id)) warnings.push(`${file}: texture ${id} doesn't exist, it will show as missing`);
} else if (!(what === "block" ? block_owners : item_owners).has(id)) {
@@ -158,5 +174,17 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
uses(file, json.id, "block");
uses(file, json.replaces, "block");
}
for (const { file, json } of mod.entities) {
if ((entity_owners.get(json.id)?.length ?? 0) > 1) {
errors.push(`${file}: entity ${json.id} is also defined by ${entity_owners.get(json.id)!.join(", ")}`);
}
uses(file, json.model, "entity model");
uses(file, json.texture, "texture");
}
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`);
}
}
}
}