fix: correctly display item names in inventory GUI

fix: fix opening nested inventory GUI on servers!
This commit is contained in:
Vitaly Turovsky 2024-05-18 05:57:50 +03:00
commit 5198e69816
3 changed files with 28 additions and 9 deletions

View file

@ -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)

View file

@ -8,7 +8,7 @@ import type { OptionsGroupType } from './optionsGuiScheme'
const notHideableModalsWithoutForce = new Set(['app-status'])
type Modal = ({ elem?: HTMLElement & Record<string, any> } & { reactType?: string })
type Modal = ({ elem?: HTMLElement & Record<string, any> } & { reactType: string })
type ContextMenuItem = { callback; label }
@ -57,7 +57,7 @@ const showModalInner = (modal: Modal) => {
}
export const showModal = (elem: /* (HTMLElement & Record<string, any>) | */{ 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
}

View file

@ -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<import('prismarine-item').Item, 'nbt'>
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)