From 5198e698160483fcc2aaacb508cee63501d546a2 Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Sat, 18 May 2024 05:57:50 +0300 Subject: [PATCH] fix: correctly display item names in inventory GUI fix: fix opening nested inventory GUI on servers! --- README.MD | 4 ++++ src/globalState.ts | 6 +++--- src/inventoryWindows.ts | 27 +++++++++++++++++++++------ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/README.MD b/README.MD index ce368540..225cdda2 100644 --- a/README.MD +++ b/README.MD @@ -126,3 +126,7 @@ Press `Y` to set query parameters to url of your current game state. - [Minecraft Protocol](https://github.com/PrismarineJS/node-minecraft-protocol) - Makes connections to servers possible - [Peer.js](https://peerjs.com/) - P2P networking (when you open to wan) - [Three.js](https://threejs.org/) - Helping in 3D rendering + +### Alternatives + +- [https://github.com/ClassiCube/ClassiCube](ClassiCube - Better C# Rewrite) [https://www.classicube.net/](https://www.classicube.net/server/play/?warned=true) diff --git a/src/globalState.ts b/src/globalState.ts index 1b0526f9..4b62f8d6 100644 --- a/src/globalState.ts +++ b/src/globalState.ts @@ -8,7 +8,7 @@ import type { OptionsGroupType } from './optionsGuiScheme' const notHideableModalsWithoutForce = new Set(['app-status']) -type Modal = ({ elem?: HTMLElement & Record } & { reactType?: string }) +type Modal = ({ elem?: HTMLElement & Record } & { reactType: string }) type ContextMenuItem = { callback; label } @@ -57,7 +57,7 @@ const showModalInner = (modal: Modal) => { } export const showModal = (elem: /* (HTMLElement & Record) | */{ reactType: string }) => { - const resolved = elem instanceof HTMLElement ? { elem: ref(elem) } : elem + const resolved = elem const curModal = activeModalStack.at(-1) if (/* elem === curModal?.elem || */(elem.reactType && elem.reactType === curModal?.reactType) || !showModalInner(resolved)) return if (curModal) defaultModalActions.hide(curModal) @@ -123,7 +123,7 @@ export type AppConfig = { defaultProxy?: string // defaultProxySave?: string // defaultVersion?: string - promoteServers?: Array<{ip, description, version?}> + promoteServers?: Array<{ ip, description, version?}> mapsProvider?: string } diff --git a/src/inventoryWindows.ts b/src/inventoryWindows.ts index d9fda1c7..d87d4008 100644 --- a/src/inventoryWindows.ts +++ b/src/inventoryWindows.ts @@ -123,6 +123,11 @@ export const onGameLoad = (onLoad) => { // todo hide up to the window itself! hideCurrentModal() }) + bot.on('respawn', () => { // todo validate logic against native client (maybe login) + if (lastWindow) { + hideCurrentModal() + } + }) customEvents.on('search', (q) => { if (!lastWindow) return @@ -316,10 +321,10 @@ export const getItemNameRaw = (item: Pick const getItemName = (slot: Item | null) => { const parsed = getItemNameRaw(slot) - if (!parsed || parsed['extra']) return + if (!parsed) return // todo display full text renderer from sign renderer const text = flat(parsed as MessageFormatPart).map(x => x.text) - return text + return text.join('') } export const renderSlotExternal = (slot) => { @@ -362,12 +367,15 @@ export const onModalClose = (callback: () => any) => { callback() unsubscribe() } - }) + }, true) } const implementedContainersGuiMap = { // todo allow arbitrary size instead! + 'minecraft:generic_9x1': 'ChestWin', + 'minecraft:generic_9x2': 'ChestWin', 'minecraft:generic_9x3': 'ChestWin', + 'minecraft:generic_9x4': 'Generic95Win', 'minecraft:generic_9x5': 'Generic95Win', // hopper 'minecraft:generic_5x1': 'HopperWin', @@ -401,22 +409,29 @@ export const openItemsCanvas = (type, _bot = bot as typeof bot | null) => { return inv } +let skipClosePacketSending = false const openWindow = (type: string | undefined) => { // if (activeModalStack.some(x => x.reactType?.includes?.('player_win:'))) { if (activeModalStack.length) { // game is not in foreground, don't close current modal - if (type) bot.currentWindow?.['close']() - return + if (type) { + skipClosePacketSending = true + hideCurrentModal() + } else { + bot.currentWindow?.['close']() + return + } } showModal({ reactType: `player_win:${type}`, }) onModalClose(() => { // might be already closed (event fired) - if (type !== undefined && bot.currentWindow) bot.currentWindow['close']() + if (type !== undefined && bot.currentWindow && !skipClosePacketSending) bot.currentWindow['close']() lastWindow.destroy() lastWindow = null as any miscUiState.displaySearchInput = false destroyFn() + skipClosePacketSending = false }) cleanLoadedImagesCache() const inv = openItemsCanvas(type)