Files
bworld/mods/recipe_viewer/scripts/client.ts
T
2026-10-03 13:41:01 -03:00

25 lines
1.2 KiB
TypeScript

// a recipe viewer like just enough items: every item in a list next to the inventory, searchable, and clicking one (or
// R and U over any item) opens a screen with the recipes that make it or the ones that use it, like jei's. it only
// reads recipes, so it works with any mod's, and draws the ones it has no category for from their json
import type { ClientContext } from "bworld/client";
import { ItemList, type Mode } from "./item_list.ts";
import { RecipeIndex, RecipesScreen } from "./recipes_screen.ts";
export function setup(ctx: ClientContext) {
const index = new RecipeIndex(ctx);
const list = new ItemList(ctx);
// like jei's IRecipesGui.show, only when there's something to show
const open = (item: string, mode: Mode) => {
if (index.find(item, mode).length > 0) ctx.ui.open(new RecipesScreen(ctx, index, list, item, mode));
};
// the item list on every menu's screen, right of it
ctx.ui.add_inventory_overlay({
on_render(g, screen) {
const hovered = list.render(g, screen.x + screen.width, open) ?? screen.hovered_item?.id;
if (hovered && g.key_pressed("KeyR")) open(hovered, "recipes");
if (hovered && g.key_pressed("KeyU")) open(hovered, "uses");
},
});
}