feat(mover): inform when goal reached

This commit is contained in:
jay 2021-01-16 13:25:26 +05:00
parent b519913355
commit 3d5ffe38cd

View File

@ -73,6 +73,23 @@ function hit(blockOrEntity) {
bot.chat(`hitting ${entity.name || entity.type}`) bot.chat(`hitting ${entity.name || entity.type}`)
} }
function goalReached(goal) {
console.log(goal)
const entity = goal?.entity
let entityInfo = ""
if (entity) {
entityInfo += entity.type + ": "
switch (entity.type) {
case "player":
entityInfo += entity.username
break;
default:
break;
}
}
cfg.quiet || bot.chat(`goal reached: ${entityInfo}; pos: [x:${goal?.x}, y:${goal?.y}, z:${goal?.z}]`)
}
function stop() { function stop() {
bot.pathfinder.setGoal(null) bot.pathfinder.setGoal(null)
bot.stopDigging() bot.stopDigging()
@ -94,11 +111,13 @@ const load = (config) => {
// initMoves(bot, mcData) // initMoves(bot, mcData)
setTimeout(initMoves, 500, bot, mcData) setTimeout(initMoves, 500, bot, mcData)
bot.on('goal_reached', goalReached)
} }
const unload = () => { const unload = () => {
stop() stop()
bot.off('goal_reached', goalReached)
} }
module.exports = { load, unload, stop, initMoves, moveNear, moveXZ, follow } module.exports = { load, unload, stop, initMoves, moveNear, moveXZ, follow }