Tooltip api
This commit is contained in:
@@ -72,6 +72,8 @@ export interface ClientContext {
|
||||
// the components its json lists and their params, a copy, like the server's ctx.items.components. for showing
|
||||
// what a component means, like when a fish can be caught
|
||||
components(id: Id): Record<Id, unknown>;
|
||||
// what one sells for with this data, or undefined if it can't be sold, like the server's ctx.items.sell_value
|
||||
sell_value(id: Id, data?: unknown): number | undefined;
|
||||
};
|
||||
// every block any mod registered
|
||||
blocks: {
|
||||
@@ -244,6 +246,28 @@ export interface MenuScreen {
|
||||
|
||||
export type Color = [number, number, number, number];
|
||||
|
||||
// a line of a tooltip, see Graphics.tooltip and ClientUi.add_item_tooltip
|
||||
export interface TooltipLine {
|
||||
text: string;
|
||||
color?: Color;
|
||||
// a texture drawn before the text, as tall as the line
|
||||
icon?: Id;
|
||||
// lower comes first, TOOLTIP_PRIORITY.default when not set. lines with the same priority keep the order they were
|
||||
// added in: the game's first, then mods' in load order. only item tooltips are sorted
|
||||
priority?: number;
|
||||
}
|
||||
|
||||
// where the game's own lines of an item's tooltip go, so a mod's can go between them
|
||||
export const TOOLTIP_PRIORITY = {
|
||||
name: 0,
|
||||
fluid: 100,
|
||||
food: 200,
|
||||
default: 500,
|
||||
lore: 1000,
|
||||
// g.item_tooltip's extra lines
|
||||
extra: 2000,
|
||||
} as const;
|
||||
|
||||
// immediate mode drawing, like the debug ui, styled with the gui sprites (assets/sprites/gui.png). everything is in
|
||||
// gui pixels, like neoforge's: 18 of them are a slot
|
||||
export interface Graphics {
|
||||
@@ -279,10 +303,11 @@ export interface Graphics {
|
||||
slider(id: string, x: number, y: number, w: number, min: number, max: number): number;
|
||||
// false while a text input has the keyboard
|
||||
key_pressed(key: KeyCode): boolean;
|
||||
// shown next to the mouse over everything else, the last one this frame wins
|
||||
tooltip(lines: (string | { text: string; color?: Color })[], x: number, y: number): void;
|
||||
// the game's tooltip for an item (its name, food, lore), with extra lines under it
|
||||
item_tooltip(id: Id, x: number, y: number, extra?: (string | { text: string; color?: Color })[]): void;
|
||||
// shown next to the mouse over everything else, the last one this frame wins. white unless a line says
|
||||
tooltip(lines: (string | TooltipLine)[], x: number, y: number): void;
|
||||
// an item's tooltip as slots show it (its name, food, lore, mods' lines), with extra lines, grey unless they say.
|
||||
// they go under everything unless they have a priority
|
||||
item_tooltip(id: Id, x: number, y: number, extra?: (string | TooltipLine)[]): void;
|
||||
// the click was used, so nothing under it (like slots) gets it
|
||||
consume_click(): void;
|
||||
// the screen underneath ignores the mouse over this area this frame, for something drawn over it
|
||||
@@ -316,6 +341,9 @@ export interface ClientUi {
|
||||
// closes the screen on top
|
||||
close(): void;
|
||||
add_inventory_overlay(overlay: InventoryOverlay): void;
|
||||
// adds to every item's tooltip, like neoforge's ItemTooltipEvent. lines has the game's lines and earlier mods'. push
|
||||
// to it, and the lines are sorted by priority once every function has run
|
||||
add_item_tooltip(fn: (item: ItemStack, lines: TooltipLine[]) => void): void;
|
||||
}
|
||||
|
||||
export interface HudRegistry {
|
||||
|
||||
@@ -157,8 +157,9 @@ export interface SharedContext {
|
||||
name(id: Id): string;
|
||||
// the components its json lists and their params, a copy
|
||||
components(id: Id): Record<Id, unknown>;
|
||||
// what one sells for, from its "base_sell_value", or undefined if it can't be sold
|
||||
sell_value(id: Id): number | undefined;
|
||||
// what one of it sells for with this data, or undefined if it can't be sold: the item's "base_sell_value", and a
|
||||
// full fluid container's fluid on top, like the server's ctx.items.sell_value
|
||||
sell_value(id: Id, data?: unknown): number | undefined;
|
||||
};
|
||||
// every fluid any mod defines, like the server's and clients' ctx.fluids, without what rules decide
|
||||
readonly fluids: Pick<FluidApi, "exists" | "same"> & {
|
||||
|
||||
Reference in New Issue
Block a user