34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
// stonecutting recipes: the stonecutter cuts one item into another, picked from every recipe that takes it. the type is
|
|
// registered by the shared script, so the server's menu and the client's screen both list them from ctx.recipes.all, in
|
|
// the same order, so a button's number means the same recipe to both
|
|
import type { SharedContext } from "bworld/shared";
|
|
|
|
export const STONECUTTING = "bworld:stonecutting";
|
|
|
|
export interface StonecuttingRecipe {
|
|
// the items it cuts
|
|
input: string[];
|
|
output: { id: string; count: number };
|
|
}
|
|
|
|
export function register_stonecutting(ctx: SharedContext) {
|
|
ctx.recipes.register_type<StonecuttingRecipe, string>(STONECUTTING, {
|
|
parse: (json, read) => ({
|
|
input: read.ingredient(json.input, "input"),
|
|
output: read.stack(json.output, "output"),
|
|
}),
|
|
matches: (recipe, id) => recipe.input.includes(id),
|
|
});
|
|
}
|
|
|
|
// what an item can be cut into, in the order the stonecutter shows them
|
|
export function stonecutting_options(
|
|
recipes: readonly StonecuttingRecipe[],
|
|
id: string | undefined,
|
|
): StonecuttingRecipe[] {
|
|
return id === undefined ? [] : recipes.filter((recipe) => recipe.input.includes(id));
|
|
}
|