Skip to content

Commit

Permalink
fix: held item display was not updated after server/window GUI manipu…
Browse files Browse the repository at this point in the history
…lation on inventory
  • Loading branch information
zardoy committed May 13, 2024
1 parent 03a26d5 commit 3329d0e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,15 @@ async function connect (connectOptions: ConnectOptions) {
window.Vec3 = Vec3
window.pathfinder = pathfinder

// patch mineflayer
// todo move to mineflayer
bot.inventory.on('updateSlot', (index) => {
if ((index as unknown as number) === bot.quickBarSlot + bot.inventory.hotbarStart) {
//@ts-expect-error
bot.emit('heldItemChanged')
}
})

miscUiState.gameLoaded = true
miscUiState.loadedServerIndex = connectOptions.serverIndex ?? ''
customEvents.emit('gameLoaded')
Expand Down
3 changes: 2 additions & 1 deletion src/react/HeldMapUi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ export default () => {
return canvas.toDataURL('image/png')
})

// TODO delete maps!
const updateHeldMap = () => {
setDataUrl(null)
if (!bot.heldItem || !['filled_map', 'map'].includes(bot.heldItem.name)) return
// setDataUrl(true)
const mapNumber = (bot.heldItem?.nbt?.value as any)?.map?.value
// if (!mapNumber) return
setDataUrl(bot.mapDownloader.maps[mapNumber] as unknown as string)
setDataUrl(bot.mapDownloader.maps?.[mapNumber] as unknown as string)
}

bot.on('heldItemChanged' as any, () => {
Expand Down

0 comments on commit 3329d0e

Please sign in to comment.