Change whole gui system
This commit is contained in:
+58
-43
@@ -18,6 +18,7 @@ export interface ServerContext {
|
||||
items: ItemApi;
|
||||
recipes: RecipeApi;
|
||||
tags: TagApi;
|
||||
menus: MenuRegistry;
|
||||
ui: ServerUi;
|
||||
net: ServerNet;
|
||||
storage: ModStorage;
|
||||
@@ -62,7 +63,7 @@ export interface ComponentRegistry {
|
||||
register_item<P>(id: Id, component: ItemComponent<P>): void;
|
||||
}
|
||||
|
||||
// commands, fabric's (brigadier's) way: see common/commands.ts and docs/modding/misc/commands.md
|
||||
// commands, brigadier's way like neoforge's: see common/commands.ts and docs/modding/misc/commands.md
|
||||
|
||||
// who ran a command
|
||||
export interface CommandSource {
|
||||
@@ -79,7 +80,7 @@ export interface Command {
|
||||
}
|
||||
|
||||
export interface CommandRegistry {
|
||||
// a tree of literal() and argument() nodes, like fabric's dispatcher.register(literal("heal").then(...))
|
||||
// a tree of literal() and argument() nodes, like neoforge's dispatcher.register(literal("heal").then(...))
|
||||
register(node: CommandNode<CommandSource>): void;
|
||||
register(name: string, command: Command): void;
|
||||
literal(name: string): CommandNode<CommandSource>;
|
||||
@@ -304,7 +305,7 @@ export interface RecipeApi {
|
||||
list(type: Id): any[];
|
||||
}
|
||||
|
||||
// guis
|
||||
// forms, not built yet: menus whose screens the engine provides, see docs/modding_plan.md
|
||||
|
||||
export interface ActionForm {
|
||||
title: string;
|
||||
@@ -331,60 +332,74 @@ export interface ModalForm {
|
||||
|
||||
export type FormResult<T> = ({ canceled: true } & Partial<T>) | ({ canceled: false } & T);
|
||||
|
||||
// menus, like neoforge's: the server side of a gui, see docs/modding/inventories/menus.md
|
||||
|
||||
export type SlotFilter = "smeltable" | "fuel" | ((item: ItemStack) => boolean);
|
||||
|
||||
export interface ContainerScreenOptions {
|
||||
container: Container;
|
||||
// x and y in slot units, below the player's inventory. can be fractional
|
||||
layout: {
|
||||
slot: number;
|
||||
x: number;
|
||||
y: number;
|
||||
// what can be put in, checked on the server
|
||||
filter?: SlotFilter;
|
||||
// can only be taken from, all at once, like the furnace result
|
||||
output_only?: boolean;
|
||||
// runs when a player takes from an output_only slot, before they get it. false stops them taking it
|
||||
on_take?: (item: ItemStack) => boolean;
|
||||
// a texture drawn in the slot while it's empty, like minecraft's armor slots
|
||||
icon?: Id;
|
||||
}[];
|
||||
// height of the screen's area in slots, fits the layout and bars when not set
|
||||
rows?: number;
|
||||
// progress bars, filled with the property value divided by the property max
|
||||
bars?: {
|
||||
x: number;
|
||||
y: number;
|
||||
value: string;
|
||||
max: string;
|
||||
direction: "up" | "right";
|
||||
empty_texture: Id;
|
||||
full_texture: Id;
|
||||
}[];
|
||||
export interface SlotOptions {
|
||||
// gui pixels from the screen's top left to the slot's 18 pixel frame
|
||||
x: number;
|
||||
y: number;
|
||||
// what can be put in, checked on the server
|
||||
filter?: SlotFilter;
|
||||
// can only be taken from, all at once, like the furnace result
|
||||
output_only?: boolean;
|
||||
// runs when a player takes from an output_only slot, before they get it. false stops them taking it
|
||||
on_take?: (item: ItemStack) => boolean;
|
||||
// a texture drawn in the slot while it's empty, like minecraft's armor slots
|
||||
icon?: Id;
|
||||
}
|
||||
|
||||
export interface ScreenHandle<Props = unknown> {
|
||||
// what a menu type's build function gets, like neoforge's server menu constructor
|
||||
export interface MenuBuilder {
|
||||
title: string;
|
||||
// sent to the client once when it opens, any json up to 16 KB, like IContainerFactory's extra data
|
||||
open_data: unknown;
|
||||
// a slot of a container from ctx.containers, or of player.inventory. returns its menu slot index
|
||||
add_slot(container: Container, slot: number, options: SlotOptions): number;
|
||||
// the player's 36 slots, like addStandardInventorySlots: the rest of the inventory in 3 rows from x and y, the
|
||||
// hotbar 58 pixels under them. added in inventory order, so inventory slot i is the returned index plus i
|
||||
add_player_inventory(x: number, y: number): number;
|
||||
// a number the screen shows, like DataSlot: read every tick and sent when it changes
|
||||
add_data(name: string, get: () => number): void;
|
||||
// checked every tick, false closes it
|
||||
still_valid(check: (player: Player) => boolean): void;
|
||||
// closes it when the player is over 8 blocks from the block, or it's been broken or replaced
|
||||
still_valid_near(block: BlockRef): void;
|
||||
// a button the client pressed, like clickMenuButton. any number can come, check it
|
||||
on_button(fn: (player: Player, id: number) => void): void;
|
||||
// shift clicks: the menu slot indexes the stack in this one tries, in order. the default rule when not set
|
||||
quick_move(fn: (player: Player, index: number) => number[]): void;
|
||||
on_tick(fn: () => void): void;
|
||||
// when it closes for any reason: the player closed it, left, opened another, or it was closed
|
||||
on_close(fn: () => void): void;
|
||||
}
|
||||
|
||||
export interface MenuHandle {
|
||||
readonly player: Player;
|
||||
readonly open: boolean;
|
||||
// numbers the bars show, synced to the player when they change
|
||||
set_property(id: string, value: number): void;
|
||||
update(props: Props): void; // custom screens only
|
||||
close(): void;
|
||||
// when it closes for any reason: the player closed it, left, opened another screen, or it was closed
|
||||
on_close(fn: () => void): void;
|
||||
}
|
||||
|
||||
export interface MenuType<Args> {
|
||||
readonly id: Id;
|
||||
// like openMenu: builds a menu for the player with these args and opens it, closing whatever they had open
|
||||
open(player: Player, args: Args): MenuHandle;
|
||||
}
|
||||
|
||||
export interface MenuRegistry {
|
||||
// like registering a MenuType. the client script gives it a screen with ctx.ui.register_menu_screen
|
||||
register<Args = undefined>(
|
||||
id: Id,
|
||||
build: (menu: MenuBuilder, args: Args, player: Player) => void,
|
||||
): MenuType<Args>;
|
||||
}
|
||||
|
||||
export interface ServerUi {
|
||||
message_form(player: Player, form: MessageForm): Promise<FormResult<{ selection: 0 | 1 }>>;
|
||||
action_form(player: Player, form: ActionForm): Promise<FormResult<{ selection: number }>>;
|
||||
modal_form(player: Player, form: ModalForm): Promise<FormResult<{ values: (boolean | number | string)[] }>>;
|
||||
open_container(player: Player, options: ContainerScreenOptions): ScreenHandle;
|
||||
open_screen<Props>(
|
||||
player: Player,
|
||||
id: Id,
|
||||
props: Props,
|
||||
options?: { containers?: Record<string, Container> },
|
||||
): ScreenHandle<Props>;
|
||||
}
|
||||
|
||||
// mod channels
|
||||
|
||||
Reference in New Issue
Block a user