Make the fishing loot table be generated from the fish items
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
type LootItem,
|
||||
type LootTableJson,
|
||||
roll_loot,
|
||||
validate_loot_table,
|
||||
} from "$/common/loot.ts";
|
||||
import type { ItemStack, LootContext, LootParams } from "$/common/mod_api/server.ts";
|
||||
import { ModLoadError } from "$/common/mod_loader.ts";
|
||||
@@ -53,6 +54,18 @@ export class LootTables {
|
||||
this.#modifiers.push({ mod, table, fn });
|
||||
}
|
||||
|
||||
// a table a script made, checked like a file's
|
||||
register_table(mod: string, id: string, table: Omit<LootTableJson, "id">) {
|
||||
if (!id.startsWith(`${mod}:`)) {
|
||||
throw new ModLoadError(mod, `loot table ${id} must be in the namespace "${mod}"`);
|
||||
}
|
||||
if (this.exists(id)) throw new ModLoadError(mod, `loot table ${id} already exists`);
|
||||
const json = { ...structuredClone(table), id };
|
||||
const problems = validate_loot_table(json);
|
||||
if (problems.length > 0) throw new ModLoadError(mod, `loot table ${id}: ${problems.join(", ")}`);
|
||||
EverythingRegistry.register<LootTableJson>("loot_tables", id, json);
|
||||
}
|
||||
|
||||
#own(mod: string, id: string, what: string, map: Map<string, unknown>) {
|
||||
if (!id.startsWith(`${mod}:`)) throw new ModLoadError(mod, `${what} ${id} must be in the namespace "${mod}"`);
|
||||
if (map.has(id)) throw new ModLoadError(mod, `${what} ${id} is registered twice`);
|
||||
|
||||
Reference in New Issue
Block a user