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`);
|
||||
|
||||
@@ -779,6 +779,7 @@ export class ModRuntime {
|
||||
},
|
||||
items: {
|
||||
exists: (id) => EverythingRegistry.get("items", id) !== undefined,
|
||||
ids: () => EverythingRegistry.entries("items").map(([id]) => id),
|
||||
max_stack: (id) => {
|
||||
const item = EverythingRegistry.get<ItemRegistry>("items", id);
|
||||
if (!item) throw new Error(`unknown item ${id}`);
|
||||
@@ -856,6 +857,10 @@ export class ModRuntime {
|
||||
setup_only("loot modifiers");
|
||||
this.loot.modify(mod, table, fn);
|
||||
},
|
||||
register_table: (id, table) => {
|
||||
setup_only("loot tables");
|
||||
this.loot.register_table(mod, id, table);
|
||||
},
|
||||
},
|
||||
containers: {
|
||||
create: (size) => {
|
||||
|
||||
Reference in New Issue
Block a user