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
+42
View File
@@ -19,6 +19,7 @@ export interface ServerContext {
blocks: BlockApi;
recipes: RecipeApi;
tags: TagApi;
loot: LootApi;
menus: MenuRegistry;
ui: ServerUi;
net: ServerNet;
@@ -388,6 +389,47 @@ export interface RecipeApi {
list(type: Id): any[];
}
// loot tables, see docs/modding/resources/loot_tables.md
// what's happening when a table is rolled. its built in conditions read block, tool and killed_by_player, mods'
// conditions and functions get all of it
export interface LootContext {
// where it happens, like the broken block or the fishing hook
position?: Position;
// the block being broken. its states are read from the world when not given
block?: { id: Id; x: number; y: number; z: number; states?: Record<string, number> };
// what it's done with, like the tool breaking the block or the fishing rod
tool?: ItemStack;
// who did it: broke the block, fished, killed the mob
player?: Player;
// the mob that died
entity?: EntityRef;
// a player killed it, for the "killed_by_player" condition
killed_by_player?: boolean;
}
// a condition's or function's json, with its "condition" or "function" id and whatever params it has
// deno-lint-ignore no-explicit-any
export type LootParams = Record<string, any>;
export interface LootApi {
exists(id: Id): boolean;
// what rolling the table gives, stacks split to fit a slot. throws for a table that doesn't exist
roll(id: Id, context?: LootContext): ItemStack[];
// rolls the table into the container's empty slots, at random like minecraft's chests. returns what didn't fit
fill(container: Container, id: Id, context?: LootContext): ItemStack[];
// a condition tables can use by its id, in the mod's namespace. only during setup
register_condition(id: Id, condition: (params: LootParams, context: LootContext) => boolean): void;
// a function tables can use by its id: the item changed, or undefined to take it away. only during setup
register_function(
id: Id,
fn: (item: ItemStack, params: LootParams, context: LootContext) => ItemStack | undefined,
): void;
// changes what a table gives every time it's rolled, or every table's with "*", like neoforge's global loot
// modifiers. return the new items, or change the list. only during setup
modify(table: Id | "*", fn: (items: ItemStack[], context: LootContext, table: Id) => ItemStack[] | void): void;
}
// forms, not built yet: menus whose screens the engine provides, see docs/modding_plan.md
export interface ActionForm {