All the stone cutter recipes
This commit is contained in:
@@ -26,16 +26,20 @@ interface RecipeReader {
|
||||
export function stonecutting_recipes(ctx: RecipeReader): StonecuttingRecipe[] {
|
||||
return ctx.recipes.list(STONECUTTING).map((json, i) => {
|
||||
const where = `${STONECUTTING} recipe ${i + 1}`;
|
||||
const choice = json.input;
|
||||
const input = typeof choice === "string" || Array.isArray(choice) ? ctx.tags.expand(choice) : [];
|
||||
if (input.length === 0 || !input.every((id) => ctx.items.exists(id))) {
|
||||
// a tag can be empty, like one of another mod's items that isn't installed
|
||||
const choice: unknown = json.input;
|
||||
const entries = typeof choice === "string" ? [choice] : Array.isArray(choice) ? choice : [];
|
||||
const exists = (entry: unknown) =>
|
||||
typeof entry === "string" &&
|
||||
(entry.startsWith("#") ? ctx.tags.exists("items", entry.slice(1)) : ctx.items.exists(entry));
|
||||
if (entries.length === 0 || !entries.every(exists)) {
|
||||
throw new Error(`${where}: input must be an item, a #tag or a list of them, and they must exist`);
|
||||
}
|
||||
const { id, count } = json.output ?? {};
|
||||
if (typeof id !== "string" || !ctx.items.exists(id) || !Number.isInteger(count) || count < 1) {
|
||||
throw new Error(`${where}: output must be { id, count } of an item that exists`);
|
||||
}
|
||||
return { input, output: { id, count } };
|
||||
return { input: ctx.tags.expand(choice as string | string[]), output: { id, count } };
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user