Hud api
This commit is contained in:
@@ -48,6 +48,20 @@ export interface ClientContext {
|
||||
readonly season: Season | undefined;
|
||||
is_swimming(): boolean;
|
||||
is_sneaking(): boolean;
|
||||
// health and hunger as the server last sent them, like the server's Player. air is out of 20 like food, 2 a
|
||||
// bubble
|
||||
readonly health: number;
|
||||
readonly max_health: number;
|
||||
readonly food: number;
|
||||
readonly saturation: number;
|
||||
readonly air: number;
|
||||
// their eyes are in water, like minecraft's isUnderWater
|
||||
is_underwater(): boolean;
|
||||
// how far the attack cooldown is, 0 right after attacking and 1 when it's done, like getAttackStrengthScale
|
||||
attack_strength(): number;
|
||||
// their 36 slots, hotbar is 0-8, as the server last synced them. copies
|
||||
readonly inventory: { readonly size: number; get(slot: number): ItemStack | undefined };
|
||||
readonly selected_slot: number;
|
||||
};
|
||||
// read only, what this client sees
|
||||
world: {
|
||||
@@ -61,8 +75,10 @@ export interface ClientContext {
|
||||
// the dimension's blocks go from min_y up to max_y - 1
|
||||
readonly min_y: number;
|
||||
readonly max_y: number;
|
||||
// ticks since 06:00 of day 1, see ServerWorld.time
|
||||
// ticks since 06:00 of day 1, see ServerWorld.time. day and hour are like ServerWorld's
|
||||
readonly time: number;
|
||||
readonly day: number;
|
||||
readonly hour: number;
|
||||
};
|
||||
// every item any mod registered, in load order
|
||||
items: {
|
||||
@@ -281,7 +297,8 @@ export interface Graphics {
|
||||
panel(x: number, y: number, w: number, h: number): void;
|
||||
// how tall a line of text is at scale 1, the game's text size
|
||||
readonly text_height: number;
|
||||
text(text: string, x: number, y: number, options?: { scale?: number; color?: Color }): void;
|
||||
// shadow draws it again under, a bit down and right in dark grey, so it reads over the world, like drawString's
|
||||
text(text: string, x: number, y: number, options?: { scale?: number; color?: Color; shadow?: boolean }): void;
|
||||
measure_text(text: string, scale?: number): number;
|
||||
// part is the part of the texture to draw, [u, v, width, height] from 0 to 1, like a progress bar's filled part
|
||||
texture(id: Id, x: number, y: number, w: number, h: number, part?: [number, number, number, number]): void;
|
||||
@@ -296,7 +313,12 @@ export interface Graphics {
|
||||
filled: number,
|
||||
direction?: "right" | "up",
|
||||
): void;
|
||||
item(id: Id, x: number, y: number, count?: number): void;
|
||||
// one of the engine's gui sprites (assets/sprites/gui.png), like "cubi:heart_full", at its size unless given one.
|
||||
// like neoforge's blitSprite. color multiplies it, like a shadow drawn in see through black
|
||||
sprite(id: Id, x: number, y: number, options?: { width?: number; height?: number; color?: Color }): void;
|
||||
// an item at a slot's top left. a stack draws like a slot does, with its count and its data, like a worn tool's
|
||||
// durability bar
|
||||
item(item: Id | ItemStack, x: number, y: number, count?: number): void;
|
||||
// a fluid as a slot shows it, its texture in its color, at a slot's top left like item. filled (0 to 1, 1 when not
|
||||
// set) is how much of the slot it fills from the bottom up, like amount / capacity for a machine's tank
|
||||
fluid(fluid: FluidVariant, x: number, y: number, filled?: number): void;
|
||||
@@ -349,8 +371,25 @@ export interface ClientUi {
|
||||
add_item_tooltip(fn: (item: ItemStack, lines: TooltipLine[]) => void): void;
|
||||
}
|
||||
|
||||
// what's drawn over the world while playing, under screens, like neoforge's gui layers. see docs/modding/gui/hud.md
|
||||
export interface HudRegistry {
|
||||
register(id: Id, element: { on_render(g: Graphics): void }): void;
|
||||
// a layer, drawn every frame in the order they're registered, mods in load order, like RegisterGuiLayersEvent's
|
||||
// registerAboveAll. only during setup. one that throws is removed, with the error in the console
|
||||
register(id: Id, layer: HudLayer): void;
|
||||
// a server script sent an overlay message (MessageOptions.overlay), for a layer to show
|
||||
on_overlay_message(fn: (text: string) => void): void;
|
||||
}
|
||||
|
||||
export interface HudLayer {
|
||||
on_render(g: Graphics, hud: HudSpace): void;
|
||||
}
|
||||
|
||||
// how far up from the bottom of the window the hud reaches on the left and right, in gui pixels, like neoforge's
|
||||
// leftHeight and rightHeight. both start at 0 each frame. a layer drawing along the bottom, like a row of hearts, draws
|
||||
// above them and raises them, so the next one goes on top. chat goes above the higher one
|
||||
export interface HudSpace {
|
||||
left_height: number;
|
||||
right_height: number;
|
||||
}
|
||||
|
||||
export interface ClientNet {
|
||||
|
||||
Reference in New Issue
Block a user