-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathclickmove.js
37 lines (28 loc) · 1.18 KB
/
clickmove.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const mineflayer = require('mineflayer')
const mineflayerViewer = require('prismarine-viewer').mineflayer
const { pathfinder, Movements } = require('mineflayer-pathfinder')
const { GoalBlock } = require('mineflayer-pathfinder').goals
const bot = mineflayer.createBot({
username: 'Bot'
})
bot.loadPlugin(pathfinder)
bot.once('spawn', () => {
mineflayerViewer(bot, { port: 3000 })
bot.on('path_update', (r) => {
const nodesPerTick = (r.visitedNodes * 50 / r.time).toFixed(2)
console.log(`I can get there in ${r.path.length} moves. Computation took ${r.time.toFixed(2)} ms (${nodesPerTick} nodes/tick). ${r.status}`)
const path = [bot.entity.position.offset(0, 0.5, 0)]
for (const node of r.path) {
path.push({ x: node.x, y: node.y + 0.5, z: node.z })
}
bot.viewer.drawLine('path', path, 0xff00ff)
})
const mcData = require('minecraft-data')(bot.version)
const defaultMove = new Movements(bot, mcData)
bot.viewer.on('blockClicked', (block, face, button) => {
if (button !== 2) return // only right click
const p = block.position.offset(0, 1, 0)
bot.pathfinder.setMovements(defaultMove)
bot.pathfinder.setGoal(new GoalBlock(p.x, p.y, p.z))
})
})