Better recipe api and port smithing to it

This commit is contained in:
2026-11-01 19:21:40 -03:00
parent ad782839ec
commit c8b5f2a3bd
50 changed files with 371 additions and 120 deletions
+3 -8
View File
@@ -57,7 +57,7 @@ import type {
ServerContext,
SlotOptions,
} from "$/common/mod_api/server.ts";
import { ModLoadError, shared_recipes_api } from "$/common/mod_loader.ts";
import { ModLoadError, recipe_lookup, shared_recipes_api } from "$/common/mod_loader.ts";
import {
argument,
block as block_argument,
@@ -303,7 +303,7 @@ export class ModRuntime {
this.fluid_rules.register(mod, id, rules);
},
},
recipes: shared_recipes_api(() => this.game.recipes, () => this.#shared_setup, (message) => {
recipes: shared_recipes_api(mod, () => this.game.recipes, () => this.#shared_setup, (message) => {
throw new ModLoadError(mod, message);
}),
world: {
@@ -1014,12 +1014,7 @@ export class ModRuntime {
fuel_value: (item) => game().recipes.fuel.get(item) ?? 0,
is_fuel: (item) => game().recipes.fuel.has(item),
is_smeltable: (item) => game().recipes.furnace.has(item),
smithing: (tool, material, addition) => {
const recipe = game().recipes.smithing.find((r) =>
r.tool === tool && r.material.id === material && r.addition === addition
);
return recipe && { result: recipe.result, material_count: recipe.material.count };
},
...recipe_lookup(() => game().recipes),
list: (type) => structuredClone(game().recipes.by_type.get(type) ?? []),
},
tags: tag_api(),