CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PrismarineJS

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: PrismarineJS/mineflayer
Path: blob/master/examples/pathfinder/gps.js
Views: 789
1
// This is an example that uses mineflayer-pathfinder to showcase how simple it is to walk to goals
2
3
const mineflayer = require('mineflayer')
4
const { pathfinder, Movements, goals: { GoalNear } } = require('mineflayer-pathfinder')
5
6
if (process.argv.length < 4 || process.argv.length > 6) {
7
console.log('Usage : node gps.js <host> <port> [<name>] [<password>]')
8
process.exit(1)
9
}
10
11
const bot = mineflayer.createBot({
12
host: process.argv[2],
13
port: parseInt(process.argv[3]),
14
username: process.argv[4] ? process.argv[4] : 'gps',
15
password: process.argv[5]
16
})
17
18
const RANGE_GOAL = 1 // get within this radius of the player
19
20
bot.loadPlugin(pathfinder)
21
22
bot.once('spawn', () => {
23
const defaultMove = new Movements(bot)
24
25
bot.on('chat', (username, message) => {
26
if (username === bot.username) return
27
if (message !== 'come') return
28
const target = bot.players[username]?.entity
29
if (!target) {
30
bot.chat("I don't see you !")
31
return
32
}
33
const { x: playerX, y: playerY, z: playerZ } = target.position
34
35
bot.pathfinder.setMovements(defaultMove)
36
bot.pathfinder.setGoal(new GoalNear(playerX, playerY, playerZ, RANGE_GOAL))
37
})
38
})
39
40