Files
2026-11-14 12:18:41 -03:00

30 lines
1.3 KiB
TypeScript

// SPDX-FileCopyrightText: 2026 Paula Wisnievski
// SPDX-License-Identifier: AGPL-3.0-or-later
// 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 "cubi/client";
import { type Entry, ItemList, type Mode } from "./item_list.ts";
import { RecipeIndex, RecipesScreen } from "./recipes_screen.ts";
export function client(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 = (entry: Entry, mode: Mode) => {
if (index.find(entry, mode).length > 0) ctx.ui.open(new RecipesScreen(ctx, index, list, entry, mode));
};
// the item list on every menu's screen, right of it
ctx.ui.add_inventory_overlay({
on_render(g, screen) {
const slot = screen.hovered_item;
const hovered = list.render(g, screen.x + screen.width, open) ??
(slot && { kind: "item", id: slot.id } satisfies Entry);
if (hovered && g.key_pressed("KeyR")) open(hovered, "recipes");
if (hovered && g.key_pressed("KeyU")) open(hovered, "uses");
},
});
}