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
+17
View File
@@ -20,6 +20,7 @@ import {
import { check_references, load_order, type LoadedMod, type ModReport } from "$/common/mod_check.ts";
import { png_size, texture_size_problem } from "$/common/bmod.ts";
import { type TextureJson, validate_texture_json } from "$/common/texture_animation.ts";
import { type LootTableJson, validate_loot_table } from "$/common/loot.ts";
import { dirname } from "@std/path";
export { load_order, type LoadedMod, type ModReport };
@@ -80,6 +81,7 @@ function load_mod(mods_dir: string, id: string): LoadedMod {
entity_models: [],
effects: [],
tags: [],
loot_tables: [],
textures: [],
texture_files: new Map(),
texture_json: new Map(),
@@ -178,6 +180,21 @@ function load_mod(mods_dir: string, id: string): LoadedMod {
if (problems.length === 0) mod.tags.push({ file: path, json: json as TagJson });
}
// loot_tables/<path>.json is the loot table <mod id>:<path>, like minecraft's
for (const file of walk(`${dir}/loot_tables`, ".json")) {
const path = `loot_tables/${file}`;
const wrapper = read_json(`${dir}/${path}`, (m) => error(`${path}: ${m}`));
if (wrapper === undefined) continue;
if (!is_object(wrapper) || wrapper.format_version !== FORMAT_VERSION || !is_object(wrapper.loot_table)) {
error(`${path}: must be { "format_version": ${FORMAT_VERSION}, "loot_table": { "pools": [ ... ] } }`);
continue;
}
const json = { ...wrapper.loot_table, id: `${id}:${file.replace(/\.json$/, "")}` };
const problems = validate_loot_table(json);
for (const problem of problems) error(`${path}: ${problem}`);
if (problems.length === 0) mod.loot_tables.push({ file: path, json: json as LootTableJson });
}
if (exists(`${dir}/worldgen/ores.json`)) {
const ores = read_json(`${dir}/worldgen/ores.json`, (m) => error(`worldgen/ores.json: ${m}`));
if (!is_object(ores) || ores.format_version !== FORMAT_VERSION || !Array.isArray(ores.ores)) {
+1
View File
@@ -42,6 +42,7 @@ export async function pack_mod(mod: LoadedMod): Promise<Uint8Array<ArrayBuffer>>
entity_models: mod.entity_models.map((m) => m.json),
effects: mod.effects.map((e) => e.json),
tags: mod.tags.map((t) => t.json),
loot_tables: mod.loot_tables.map((t) => t.json),
},
scripts,
textures,