Hud api
This commit is contained in:
@@ -7,7 +7,8 @@ There are a few ways for a mod to show players a GUI. Pick the first one that's
|
||||
| [Menus](../inventories/menus.md) | server, and client | Inventories and machines: slots, filters, progress bars |
|
||||
| [Plain screens](#plain-screens) | client only | Screens with nothing the server checks: maps, guide books |
|
||||
| [Inventory overlays](#inventory-overlays) | client only | Drawing next to every menu's screen, like a recipe list |
|
||||
| Forms and HUD elements | not built yet | See [below](#not-built-yet) |
|
||||
| [HUD layers](hud.md) | client only | Drawing over the world while playing, like health bars |
|
||||
| Forms | not built yet | See [below](#not-built-yet) |
|
||||
|
||||
Everything is in **GUI pixels**, like NeoForge's: 18 of them are a slot, and the game draws each one 3 screen pixels
|
||||
wide.
|
||||
@@ -111,7 +112,13 @@ interface Graphics {
|
||||
|
||||
rect(x: number, y: number, w: number, h: number, color?: [r, g, b, a]): void;
|
||||
panel(x: number, y: number, w: number, h: number): void; // the game's panel background
|
||||
text(text: string, x: number, y: number, options?: { scale?: number; color?: [r, g, b, a] }): void; // scale 1 is normal
|
||||
// scale 1 is normal. shadow draws it again under, in dark grey, so it reads over the world
|
||||
text(
|
||||
text: string,
|
||||
x: number,
|
||||
y: number,
|
||||
options?: { scale?: number; color?: [r, g, b, a]; shadow?: boolean },
|
||||
): void;
|
||||
measure_text(text: string, scale?: number): number;
|
||||
// any texture. part is [u, v, width, height] from 0 to 1, the part of it to draw, like a progress bar's filled part
|
||||
texture(id: string, x: number, y: number, w: number, h: number, part?: [u, v, w, h]): void;
|
||||
@@ -126,7 +133,10 @@ interface Graphics {
|
||||
filled: number,
|
||||
direction?: "right" | "up",
|
||||
): void;
|
||||
item(id: string, x: number, y: number, count?: number): void; // an item as a slot shows it
|
||||
// one of the engine's gui sprites, like "cubi:heart_full", at its size unless given one. color multiplies it
|
||||
sprite(id: string, x: number, y: number, options?: { width?: number; height?: number; color?: [r, g, b, a] }): void;
|
||||
// an item as a slot shows it. a stack draws with its count and data, like a worn tool's durability bar
|
||||
item(item: string | ItemStack, x: number, y: number, count?: number): void;
|
||||
// a fluid as a slot shows it, like { id: "bworld:juice", data: { item: "bworld:apple" } }. filled is how much of
|
||||
// the slot it fills from the bottom up, 0 to 1, like a tank's amount / capacity
|
||||
fluid(fluid: FluidVariant, x: number, y: number, filled?: number): void;
|
||||
@@ -203,7 +213,8 @@ ctx.player.biome; // and ctx.player.season, see ../worldgen/biomes.md#seasons
|
||||
ctx.world.get_block(x, y, z); // a block id, what this client sees
|
||||
ctx.world.get_client_data<number>(x, y, z, "speed"); // see ../blocks/tiledata.md#client-data, a copy
|
||||
ctx.world.biome_at(x, y, z); // and ctx.world.season_at(x, y, z), undefined where nothing's loaded
|
||||
ctx.world.time; // see Time
|
||||
ctx.world.time; // see Time, and ctx.world.day and ctx.world.hour like the server's
|
||||
ctx.player.health; // and the rest of the vitals, the hotbar and the attack cooldown, see hud.md
|
||||
ctx.world.min_y; // and ctx.world.max_y, see ../worldgen/terrain.md#height
|
||||
ctx.items.ids(); // every item, in load order
|
||||
ctx.items.exists(id);
|
||||
@@ -235,7 +246,6 @@ The client and server APIs have types for these, but calling them throws for now
|
||||
|
||||
- **Forms** (`ctx.ui.message_form`, `action_form` and `modal_form` on the server): simple dialogs defined entirely by
|
||||
the server script, like Bedrock's server forms. They'll be menus whose screens the engine draws.
|
||||
- **HUD elements** (`ctx.hud.register`): drawing over the world every frame.
|
||||
- **Keybinds** (`ctx.input.bind`). Until then, an inventory overlay can check `g.key_pressed` while an inventory is
|
||||
open.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user