Change whole gui system
This commit is contained in:
+22
-16
@@ -1,6 +1,8 @@
|
||||
import { PLAYER_EYE_HEIGHT, PLAYER_HEIGHT, PLAYER_WIDTH } from "$/common/constants.ts";
|
||||
import { Container, Cursor, ItemData, ItemStack } from "$/common/inventory.ts";
|
||||
import { PlayerInfo, ScreenLayout } from "$/common/protocol.ts";
|
||||
import type { GridRecipe } from "$/common/mod_data.ts";
|
||||
import { Menu, PlayerMenu } from "./menu.ts";
|
||||
import { PlayerInfo } from "$/common/protocol.ts";
|
||||
import { EXHAUSTION, type SavedVitals, Vitals } from "./vitals.ts";
|
||||
import { PlayerChunks } from "./player_chunks.ts";
|
||||
import { ATTRIBUTES, type AttributeType } from "./entity/attributes.ts";
|
||||
@@ -10,19 +12,6 @@ import { LivingEntity } from "./entity/living_entity.ts";
|
||||
export const INVENTORY_SIZE = 9 * 4;
|
||||
export const CRAFTING_SIZE = 10;
|
||||
|
||||
// a container screen a mod opened for this player, see ctx.ui.open_container
|
||||
export interface OpenScreen {
|
||||
container: Container;
|
||||
layout: ScreenLayout;
|
||||
// what the bars show, synced when they change
|
||||
properties: Record<string, number>;
|
||||
// what can go into each slot, checked when the player clicks
|
||||
filters: Map<number, (item: ItemStack) => boolean>;
|
||||
// asked before a player takes from an output slot
|
||||
on_take: Map<number, (item: ItemStack) => boolean>;
|
||||
on_close: (() => void)[];
|
||||
}
|
||||
|
||||
// what's saved about a player between sessions, by name
|
||||
export interface SavedPlayer {
|
||||
x: number;
|
||||
@@ -71,7 +60,12 @@ export class ServerPlayer extends LivingEntity {
|
||||
crafting = new Container(CRAFTING_SIZE);
|
||||
cursor: Cursor = { item: undefined };
|
||||
selected_slot = 0;
|
||||
screen: OpenScreen | undefined;
|
||||
// menu 0, always there
|
||||
inventory_menu: PlayerMenu;
|
||||
// the menu they have open, like minecraft's containerMenu without the inventory menu
|
||||
menu: Menu | undefined;
|
||||
// the last menu id given out, they go 1 to 100 and around
|
||||
menu_id = 0;
|
||||
// base64 png, see /skin. undefined is the default skin
|
||||
skin: string | undefined;
|
||||
// the skin is for the model with 3 pixel wide arms
|
||||
@@ -84,11 +78,23 @@ export class ServerPlayer extends LivingEntity {
|
||||
// the chunks their client has and still needs
|
||||
chunks: PlayerChunks;
|
||||
|
||||
constructor(level: EntityLevel, conn: number, name: string, view_distance: number) {
|
||||
constructor(
|
||||
level: EntityLevel,
|
||||
conn: number,
|
||||
name: string,
|
||||
view_distance: number,
|
||||
recipes: () => GridRecipe[] = () => [],
|
||||
) {
|
||||
super(level);
|
||||
this.conn = conn;
|
||||
this.name = name;
|
||||
this.chunks = new PlayerChunks(view_distance);
|
||||
this.inventory_menu = new PlayerMenu(this.inventory, this.crafting, recipes);
|
||||
}
|
||||
|
||||
// the open menu, or menu 0 when none is
|
||||
get container_menu(): Menu {
|
||||
return this.menu ?? this.inventory_menu;
|
||||
}
|
||||
|
||||
override default_attributes(): [AttributeType, number?][] {
|
||||
|
||||
Reference in New Issue
Block a user