Change whole gui system

This commit is contained in:
2026-10-01 16:22:02 -03:00
parent 013a4fbb97
commit deba36260e
48 changed files with 1925 additions and 1302 deletions
+42 -29
View File
@@ -7,7 +7,7 @@ export const AIR_ID = "bworld:air";
// bump when a client and server of different versions can't play together.
// the server rejects a different version before the client downloads anything
export const PROTOCOL_VERSION = 13;
export const PROTOCOL_VERSION = 14;
export interface PlayerInfo {
id: string;
@@ -52,28 +52,24 @@ export type EntityEvent = "hurt" | "death" | "swing";
// x, y, z, block id, and its state bits when they aren't 0
export type BlockChange = [number, number, number, string, number?];
// the containers a client can see and click. "screen" is whatever the open server screen shows
export type ContainerKey = "inventory" | "crafting" | "screen";
// the player's own containers, synced to them whether or not a menu is open
export type ContainerKey = "inventory" | "crafting";
export const CRAFTING_RESULT_SLOT = 9;
// a screen the server opens, drawn below the player's inventory and hotbar
export interface ScreenLayout {
// height of the screen's own area, in slots
rows: number;
// x and y in slots, can be fractional
// output slots can only be taken from, like the furnace result. icon is a texture drawn in the slot while it's empty
slots: { index: number; x: number; y: number; output?: boolean; icon?: string }[];
// progress bars filled from properties[value] / properties[max]
bars: {
x: number;
y: number;
value: string;
max: string;
direction: "up" | "right";
empty_texture: string;
full_texture: string;
}[];
// menus, like neoforge's: the server's menu decides what every click does, clients draw it and send clicks by menu
// slot index. menu 0 is the player's own inventory and crafting grid, always there and never opened or sent, like
// minecraft's InventoryMenu: slots 0-35 are the inventory (the hotbar is 0-8), 36-45 the crafting grid
export const PLAYER_MENU = 0;
export const PLAYER_MENU_CRAFTING = 36;
// one slot of an opened menu as the client draws it. x and y in gui pixels from the screen's top left, output slots
// can only be taken from, icon is a texture drawn while it's empty
export interface MenuSlotInfo {
x: number;
y: number;
output?: boolean;
icon?: string;
}
// clients send what the player is trying to do, the server decides what happens
@@ -100,12 +96,15 @@ export type ClientMessage =
// right click on a block: interact with it, or place the held block against `face`
| { type: "use_block"; x: number; y: number; z: number; face: Faces }
| { type: "select_slot"; slot: number }
// shift moves the stack to the other part of the screen instead, like minecraft's quick move
| { type: "click"; container: ContainerKey; index: number; button: number; shift?: boolean }
// q on a slot (the held one when no screen is open) throws one item, or the whole stack with ctrl
| { type: "drop_item"; container: ContainerKey; index: number; all: boolean }
// closes the open screen, including the player's own inventory screen
| { type: "close_screen" }
// a slot of the open menu, or of menu 0 when none is. shift moves the stack to the other part of the menu instead,
// like minecraft's quick move. clicks for a menu that isn't open any more are ignored
| { type: "click"; menu: number; slot: number; button: number; shift?: boolean }
// q on a slot (the held one when no screen is open, in menu 0) throws one item, or the whole stack with ctrl
| { type: "drop_item"; menu: number; slot: number; all: boolean }
// a button of the open menu, like minecraft's clickMenuButton. the menu decides what the number means
| { type: "menu_button"; menu: number; button: number }
// closes the open menu, or the player's own inventory screen with 0
| { type: "close_menu"; menu: number }
| { type: "chat"; text: string }
// what could come next in a command being typed, answered with suggestions. id matches them up
| { type: "suggest"; id: number; text: string }
@@ -186,9 +185,23 @@ export type ServerMessage =
| { type: "teleport"; id: number; x: number; y: number; z: number; motion?: [number, number, number] }
| { type: "container"; container: ContainerKey; items: (ItemData | null)[] }
| { type: "cursor"; item: ItemData | null }
| { type: "open_screen"; layout: ScreenLayout; properties: Record<string, number> }
| { type: "screen_properties"; properties: Record<string, number> }
| { type: "close_screen" }
// a menu opened, replacing any other. id counts 1 to 100 and around, type is the menu type whose screen draws it.
// its slots' items come in menu_content, its data's changes in menu_data
| {
type: "open_menu";
id: number;
menu_type: string;
title: string;
open_data: unknown;
slots: MenuSlotInfo[];
data: Record<string, number>;
}
// what's in every slot of the open menu, by menu slot index, when any of it changed
| { type: "menu_content"; id: number; items: (ItemData | null)[] }
// all the menu's data, when any of it changed
| { type: "menu_data"; id: number; data: Record<string, number> }
// the server closed it (the block broke, the player walked away), it already put everything back
| { type: "close_menu"; id: number }
// the world time, every second and when it's changed. clients count ticks in between
| { type: "time"; time: number }
// answers suggest: start is where in the text the suggestions replace from, up to the caret