Skip to content

Commit

Permalink
feat(devtools): add len and inspectPacket global functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy committed May 13, 2024
1 parent 0a1b978 commit ce68498
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,23 @@ Object.defineProperty(window, 'debugSceneChunks', {
return (viewer.world as WorldRendererThree).getLoadedChunksRelative?.(bot.entity.position, true)
},
})

window.len = (obj) => Object.keys(obj).length

window.inspectPacket = (packetName, full = false) => {
const listener = (...args) => console.log('packet', packetName, full ? args : args[0])
const attach = () => {
bot?.on(packetName, listener)
}
attach()
customEvents.on('mineflayerBotCreated', attach)
const returnobj = {}
Object.defineProperty(returnobj, 'detach', {
get () {
bot?.removeListener(packetName, listener)
customEvents.removeListener('mineflayerBotCreated', attach)
return true
},
})
return returnobj
}

0 comments on commit ce68498

Please sign in to comment.