Tags for smithing recipes

This commit is contained in:
2026-11-13 20:19:37 -03:00
parent 51b5d148bd
commit d48fa8cca5
7 changed files with 130 additions and 47 deletions
+13 -4
View File
@@ -5,7 +5,16 @@
// blocks it's made in (jei's recipe catalysts), and where its items go. types no category knows get one from their
// recipes' json, see mod_category
import type { ClientContext, FluidVariant, TagApi } from "cubi/client";
import { fluid_outputs, type Ingredient, mod_recipe_inputs, outputs, type Recipe, seconds, stack } from "./recipes.ts";
import {
choice_stack,
fluid_outputs,
type Ingredient,
mod_recipe_inputs,
outputs,
type Recipe,
seconds,
stack,
} from "./recipes.ts";
// in gui pixels, a slot with its border, like minecraft's
export const SLOT = 18;
@@ -98,9 +107,9 @@ function base_categories(tags: TagApi): RecipeCategory[] {
height: 18,
catalysts: ["bworld:smithing_table"],
draw(recipe, layout) {
layout.slot({ ids: [recipe.tool], count: 1 }, 0, 0);
layout.slot(stack(recipe.material), SLOT, 0);
layout.slot(recipe.addition && stack(recipe.addition), SLOT * 2, 0);
layout.slot({ ids: tags.expand(recipe.tool), count: 1 }, 0, 0);
layout.slot(choice_stack(recipe.material, tags), SLOT, 0);
layout.slot(recipe.addition && choice_stack(recipe.addition, tags), SLOT * 2, 0);
layout.texture("bworld:arrow_full", 61, 1, ARROW, ARROW);
layout.slot({ ids: [recipe.result], count: 1 }, 90, 0);
},
+9 -3
View File
@@ -46,7 +46,8 @@ export function fluid_inputs(recipe: Recipe): FluidAmount[] {
return recipe.fluid_ingredients ?? [];
}
// what a recipe takes. shaped keys, smelting inputs and fuels can be an item or #tag, or a list any of which fits
// what a recipe takes. shaped keys, smelting inputs, fuels and smithing inputs can be an item or #tag, or a list any of
// which fits
export function inputs(recipe: Recipe, tags: TagApi): Ingredient[] {
switch (recipe.type) {
case "shaped":
@@ -59,8 +60,8 @@ export function inputs(recipe: Recipe, tags: TagApi): Ingredient[] {
case "bworld:fuel":
return [{ ids: tags.expand(recipe.item), count: 1 }];
case "bworld:smithing":
return [{ ids: [recipe.tool], count: 1 }, stack(recipe.material)].concat(
recipe.addition ? [stack(recipe.addition)] : [],
return [{ ids: tags.expand(recipe.tool), count: 1 }, choice_stack(recipe.material, tags)].concat(
recipe.addition ? [choice_stack(recipe.addition, tags)] : [],
);
default: {
const { grid, extras } = mod_recipe_inputs(recipe, tags);
@@ -97,6 +98,11 @@ export function stack(value: { id: string; count: number }): Ingredient {
return { ids: [value.id], count: value.count };
}
// { id, count } where id is an item, a #tag or a list of them, like smithing's material
export function choice_stack(value: { id: string | string[]; count: number }, tags: TagApi): Ingredient {
return { ids: tags.expand(value.id), count: value.count };
}
export function seconds(ticks: number): string {
const s = ticks / 20;
return `${Number.isInteger(s) ? s : s.toFixed(1)} s`;