Better recipe api and port smithing to it
This commit is contained in:
+14
-15
@@ -603,15 +603,6 @@ const furnace_recipe = z.object({
|
||||
|
||||
const fuel_recipe = z.object({ type: z.literal("fuel"), item: item_choice, burn_time: z.int().min(1) });
|
||||
|
||||
// upgrades a tool at a smithing table, with some of a material and maybe one more item
|
||||
const smithing_recipe = z.object({
|
||||
type: z.literal("smithing"),
|
||||
tool: id,
|
||||
material: stack,
|
||||
addition: id.optional(),
|
||||
result: id,
|
||||
});
|
||||
|
||||
export interface ModRecipeJson {
|
||||
type: `${string}:${string}`;
|
||||
[field: string]: unknown;
|
||||
@@ -621,29 +612,37 @@ export type RecipeJson =
|
||||
| z.infer<typeof shaped_recipe>
|
||||
| z.infer<typeof furnace_recipe>
|
||||
| z.infer<typeof fuel_recipe>
|
||||
| z.infer<typeof smithing_recipe>
|
||||
| ModRecipeJson;
|
||||
|
||||
const engine_recipes = new Map<string, z.ZodType>([
|
||||
["shaped", shaped_recipe],
|
||||
["furnace", furnace_recipe],
|
||||
["fuel", fuel_recipe],
|
||||
["smithing", smithing_recipe],
|
||||
]);
|
||||
|
||||
// a mod's own types, like "bworld:cooking" for its cooking pot, are only stored by the engine. the mod's server
|
||||
// script reads them with ctx.recipes.list and checks them
|
||||
// a mod's own types, like "bworld:cooking" for its cooking pot, are only stored by the engine. the mod parses them,
|
||||
// with ctx.recipes.register_type, or reads them with ctx.recipes.list and checks them
|
||||
const recipe_schema = by_kind(
|
||||
"type",
|
||||
(type) => engine_recipes.get(type) ?? (ID_PATTERN.test(type) ? json_object : undefined),
|
||||
'must be "shaped", "furnace", "fuel", "smithing" or a mod\'s own type like "bworld:cooking"',
|
||||
'must be "shaped", "furnace", "fuel" or a mod\'s own type like "bworld:cooking"',
|
||||
);
|
||||
|
||||
// a recipe type a mod made up, as opposed to the engine's shaped, furnace, fuel and smithing
|
||||
// a recipe type a mod made up, as opposed to the engine's shaped, furnace and fuel
|
||||
export function is_mod_recipe(recipe: RecipeJson): recipe is ModRecipeJson {
|
||||
return recipe.type.includes(":");
|
||||
}
|
||||
|
||||
// the problems with an item or a stack in a mod's own recipe type, like the engine's own types' fields have, see
|
||||
// RecipeReader
|
||||
export function item_problems(json: unknown): Problems {
|
||||
return find_problems(id, json);
|
||||
}
|
||||
|
||||
export function stack_problems(json: unknown): Problems {
|
||||
return find_problems(stack, json);
|
||||
}
|
||||
|
||||
// the crafting grid's format, see server/game/crafting.ts
|
||||
export interface GridRecipe {
|
||||
width: number;
|
||||
|
||||
Reference in New Issue
Block a user