Loot tables

This commit is contained in:
2026-10-08 00:54:45 -03:00
parent 757ee74bc7
commit ec2b53c02a
45 changed files with 1733 additions and 150 deletions
+21 -1
View File
@@ -18,6 +18,7 @@ import { PLAYER_PARTS } from "./everything_registry.ts";
import { BUILTIN_MODELS, type ModelJson } from "./block_models.ts";
import { resolve_tags } from "./tags.ts";
import type { TextureJson } from "./texture_animation.ts";
import { loot_references, type LootTableJson } from "./loot.ts";
import { BIOMES } from "./worldgen/overworld.ts";
export interface ModReport {
@@ -41,6 +42,7 @@ export interface LoadedMod {
entity_models: { file: string; json: EntityModelJson }[];
effects: { file: string; json: EffectJson }[];
tags: { file: string; json: TagJson }[];
loot_tables: { file: string; json: LootTableJson }[];
textures: string[];
// absolute paths by texture id
texture_files: Map<string, string>;
@@ -87,6 +89,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
const effect_owners = new Map<string, string[]>();
const tag_owners = new Map<TagRegistry, Set<string>>();
const liquids = new Set<string>();
const loot_tables = new Set<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);
@@ -109,6 +112,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
entity_model_jsons.set(json.id, json);
}
for (const { json } of mod.effects) add(effect_owners, json.id, mod.id);
for (const { json } of mod.loot_tables ?? []) loot_tables.add(json.id);
for (const { json } of mod.tags) {
if (!tag_owners.has(json.registry)) tag_owners.set(json.registry, new Set());
tag_owners.get(json.registry)!.add(json.id);
@@ -138,7 +142,11 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
};
// block and item ids can be #tags, like in recipes and place_on
const uses = (file: string, id: string, what: "block" | "item" | "texture" | "model" | "entity model") => {
const uses = (
file: string,
id: string,
what: "block" | "item" | "texture" | "model" | "entity model" | "loot table",
) => {
check_namespace(file, id);
if (id.startsWith("#") && (what === "block" || what === "item")) {
if (!tag_owners.get(what === "block" ? "blocks" : "items")?.has(id.slice(1))) {
@@ -150,6 +158,8 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
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 === "loot table") {
if (!loot_tables.has(id)) errors.push(`${file}: loot table ${id} doesn't exist`);
} else if (!(what === "block" ? block_owners : item_owners).has(id)) {
errors.push(`${file}: ${what} ${id} doesn't exist`);
}
@@ -167,6 +177,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
}
}
if (json.drops) uses(file, json.drops, "item");
if (json.loot_table) uses(file, json.loot_table, "loot table");
if (json.waterloggable) {
uses(file, json.waterloggable, "block");
if (block_owners.has(json.waterloggable) && !liquids.has(json.waterloggable)) {
@@ -251,6 +262,15 @@ 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");
if (json.loot_table) uses(file, json.loot_table, "loot table");
}
for (const { file, json } of mod.loot_tables ?? []) {
const refs = loot_references(json);
for (const id of refs.items) uses(file, id, "item");
for (const id of refs.tags) uses(file, id, "item");
for (const id of refs.tables) uses(file, id, "loot table");
// mods' conditions and functions are registered by scripts, the server checks them when it starts
for (const id of refs.custom) check_namespace(file, id);
}
for (const { file, json } of mod.effects) {
if ((effect_owners.get(json.id)?.length ?? 0) > 1) {