Change curios to always show on inventory
This commit is contained in:
@@ -19,6 +19,7 @@ import { Connection } from "./network.ts";
|
||||
import { PauseScreen } from "./gui/pause_screen.ts";
|
||||
import { back_to_title } from "./gui/title_screen.ts";
|
||||
import { TICK_DELTA } from "$/common/constants.ts";
|
||||
import { Container } from "$/common/inventory.ts";
|
||||
import { PLAYER_MENU } from "$/common/protocol.ts";
|
||||
import { EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import type { EntityJson } from "$/common/mod_data.ts";
|
||||
@@ -76,6 +77,8 @@ export class Client {
|
||||
this.player.yaw = spawn.yaw;
|
||||
this.player.pitch = spawn.pitch;
|
||||
this.player.inventories.hotbar_selected = connection.selected_slot;
|
||||
this.player.inventories.extra_slots = connection.player_menu;
|
||||
this.player.inventories.extra = new Container(connection.player_menu.length);
|
||||
this.level.add_entity(this.player);
|
||||
for (const info of connection.initial_players) {
|
||||
this.level.add_entity(new RemotePlayer(this.level, info));
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
import { GuiMenuScreen } from "./gui_screen.ts";
|
||||
import { ClientInventories } from "../inventory.ts";
|
||||
import { ClientMessage } from "$/common/protocol.ts";
|
||||
import { ClientMessage, PLAYER_MENU_EXTRA } from "$/common/protocol.ts";
|
||||
import { player_menu } from "../menu.ts";
|
||||
import type { ModGraphics } from "./mod_graphics.ts";
|
||||
|
||||
const WIDTH = 176;
|
||||
const HEIGHT = 166;
|
||||
const SLOT = 18;
|
||||
// around the slots, like minecraft's
|
||||
const MARGIN = 7;
|
||||
|
||||
// menu 0's screen: the crafting grid over the inventory. the recipes live on the server, which fills in the result
|
||||
// menu 0's screen: the crafting grid over the inventory, and any slots mods added. the recipes live on the server,
|
||||
// which fills in the result
|
||||
export class GuiPlayerInventory extends GuiMenuScreen {
|
||||
constructor(inventories: ClientInventories, send: (message: ClientMessage) => void) {
|
||||
super(inventories, send, player_menu(inventories), WIDTH, HEIGHT);
|
||||
@@ -15,6 +19,16 @@ export class GuiPlayerInventory extends GuiMenuScreen {
|
||||
|
||||
render_background(g: ModGraphics): void {
|
||||
g.panel(0, 0, WIDTH, HEIGHT);
|
||||
// the slots mods added outside the panel get one of their own, around them with the same margin
|
||||
const outside = this.menu.slots.slice(PLAYER_MENU_EXTRA)
|
||||
.filter((s) => s.x + SLOT < 0 || s.x > WIDTH || s.y + SLOT < 0 || s.y > HEIGHT);
|
||||
if (outside.length > 0) {
|
||||
const left = Math.min(...outside.map((s) => s.x)) - MARGIN;
|
||||
const top = Math.min(...outside.map((s) => s.y)) - MARGIN;
|
||||
const right = Math.max(...outside.map((s) => s.x)) + SLOT + MARGIN;
|
||||
const bottom = Math.max(...outside.map((s) => s.y)) + SLOT + MARGIN;
|
||||
g.panel(left, top, right - left, bottom - top);
|
||||
}
|
||||
}
|
||||
|
||||
render_labels(g: ModGraphics): void {
|
||||
|
||||
@@ -154,6 +154,7 @@ export abstract class GuiMenuScreen extends GuiScreen {
|
||||
#render_overlays() {
|
||||
const hovered = this.hovering && this.hovering.container.get_item(this.hovering.index);
|
||||
const view = {
|
||||
menu_type: this.menu.id === PLAYER_MENU ? undefined : this.menu.type,
|
||||
x: this.x / GUI_SCALE,
|
||||
y: this.y / GUI_SCALE,
|
||||
width: this.width,
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import { Container, Cursor } from "$/common/inventory.ts";
|
||||
import type { MenuSlotInfo } from "$/common/protocol.ts";
|
||||
|
||||
// the local copies of the containers the server syncs to this player
|
||||
export class ClientInventories {
|
||||
inventory = new Container(9 * 4);
|
||||
crafting = new Container(10);
|
||||
// the slots mods added to menu 0 and what's in them, see join's player_menu
|
||||
extra_slots: MenuSlotInfo[] = [];
|
||||
extra = new Container(0);
|
||||
cursor: Cursor = { item: undefined };
|
||||
hotbar_selected = 0;
|
||||
}
|
||||
|
||||
+7
-4
@@ -1,7 +1,7 @@
|
||||
// the client's copy of a menu, like neoforge's client menu: built from what the server sent when it opened, kept up
|
||||
// to date with what it syncs. clicks go to the server, which decides what they do
|
||||
import { Container } from "$/common/inventory.ts";
|
||||
import { CRAFTING_RESULT_SLOT, type MenuSlotInfo, PLAYER_MENU, PLAYER_MENU_CRAFTING } from "$/common/protocol.ts";
|
||||
import { CRAFTING_RESULT_SLOT, type MenuSlotInfo, PLAYER_MENU, PLAYER_MENU_EXTRA } from "$/common/protocol.ts";
|
||||
import type { ClientInventories } from "./inventory.ts";
|
||||
|
||||
export interface ClientSlot {
|
||||
@@ -61,8 +61,8 @@ export class ClientMenu {
|
||||
}
|
||||
}
|
||||
|
||||
// menu 0, the player's inventory and crafting grid, laid out for the inventory screen. its slots are the player's
|
||||
// own containers, which the server syncs whether or not a menu is open
|
||||
// menu 0, the player's inventory and crafting grid, laid out for the inventory screen, then the slots mods added. its
|
||||
// slots are the player's own containers, which the server syncs whether or not a menu is open
|
||||
export function player_menu(inventories: ClientInventories): ClientMenu {
|
||||
const slot = (container: Container, index: number, x: number, y: number, output = false): ClientSlot => ({
|
||||
container,
|
||||
@@ -81,6 +81,9 @@ export function player_menu(inventories: ClientInventories): ClientMenu {
|
||||
slots.push(slot(inventories.crafting, i, 25 + (i % 3) * 18, 16 + Math.floor(i / 3) * 18));
|
||||
}
|
||||
slots.push(slot(inventories.crafting, CRAFTING_RESULT_SLOT, 115, 34, true));
|
||||
if (slots.length !== PLAYER_MENU_CRAFTING + CRAFTING_RESULT_SLOT + 1) throw new Error("menu 0 has the wrong slots");
|
||||
if (slots.length !== PLAYER_MENU_EXTRA) throw new Error("menu 0 has the wrong slots");
|
||||
for (const [i, info] of inventories.extra_slots.entries()) {
|
||||
slots.push({ ...slot(inventories.extra, i, info.x, info.y, info.output === true), icon: info.icon });
|
||||
}
|
||||
return new ClientMenu(PLAYER_MENU, "", "Crafting", null, slots);
|
||||
}
|
||||
|
||||
+4
-1
@@ -1,4 +1,4 @@
|
||||
import { ClientMessage, EntityInfo, PlayerInfo, ServerMessage } from "$/common/protocol.ts";
|
||||
import { ClientMessage, EntityInfo, MenuSlotInfo, PlayerInfo, ServerMessage } from "$/common/protocol.ts";
|
||||
import type { ModListing } from "$/common/mod_loader.ts";
|
||||
import type { Join, ServerSocket, Welcome } from "./handshake.ts";
|
||||
|
||||
@@ -11,6 +11,8 @@ export class Connection {
|
||||
server_blocks: string[];
|
||||
spawn: { x: number; y: number; z: number; yaw: number; pitch: number };
|
||||
selected_slot: number;
|
||||
// the slots mods added to menu 0
|
||||
player_menu: MenuSlotInfo[];
|
||||
time: number;
|
||||
// who was already there when we joined, they become entities in the level
|
||||
initial_players: PlayerInfo[];
|
||||
@@ -24,6 +26,7 @@ export class Connection {
|
||||
this.server_blocks = join.blocks;
|
||||
this.spawn = join.spawn;
|
||||
this.selected_slot = join.selected_slot;
|
||||
this.player_menu = join.player_menu;
|
||||
this.time = join.time;
|
||||
this.initial_players = join.players;
|
||||
this.initial_entities = join.entities;
|
||||
|
||||
Reference in New Issue
Block a user