Tooltip api

This commit is contained in:
2026-11-05 23:06:37 -03:00
parent 9bc8fd992a
commit 34f001285d
15 changed files with 264 additions and 81 deletions
+8 -2
View File
@@ -27,6 +27,7 @@ import { AIR_ID } from "@/common/protocol.ts";
import type { Client } from "./client.ts";
import { code_url, fetch_verified } from "./handshake.ts";
import { GuiModScreen } from "./gui/gui_mod_screens.ts";
import { item_tooltips } from "./gui/tooltip.ts";
import { clear_hooks, expose_engine, loading_mod } from "@/common/hooks.ts";
import { common_engine } from "@/common/engine_modules.ts";
import { client_engine } from "./engine_modules.ts";
@@ -165,6 +166,7 @@ export async function load_client_mods(listings: ModListing[], mods: Mod[]) {
const recipes = register_mod_data(mods.map((mod) => ({ id: mod.manifest.id, data: mod.data })));
recipe_book = recipes;
inventory_overlays.length = 0;
item_tooltips.length = 0;
menu_screens.clear();
net_handlers.clear();
block_visuals.clear();
@@ -239,7 +241,7 @@ function shared_context(listing: ModListing): SharedContext {
side: "client",
tags: tag_api(),
blocks: blocks_api(mod),
items: shared_items_api(mod),
items: shared_items_api(mod, fluid_rules),
fluids: {
exists: fluid_exists,
same: same_fluid,
@@ -309,6 +311,10 @@ function client_context(listing: ModListing): ClientContext {
add_inventory_overlay(overlay) {
inventory_overlays.push({ mod, overlay });
},
add_item_tooltip(fn) {
if (typeof fn !== "function") throw new Error(`[${mod}] add_item_tooltip takes a function`);
item_tooltips.push((item, lines) => run_mod(mod, "an item tooltip", () => fn(item, lines)));
},
},
hud: not_yet("hud", "HUD elements") as ClientContext["hud"],
input: not_yet("input", "keybinds") as ClientContext["input"],
@@ -359,7 +365,7 @@ function client_context(listing: ModListing): ClientContext {
},
},
items: {
...shared_items_api(mod),
...shared_items_api(mod, fluid_rules),
mod(id) {
known_item(id);
return mod_name(id);