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/crystal.js
Views: 789
1
const mineflayer = require('mineflayer')
2
3
if (process.argv.length < 4 || process.argv.length > 6) {
4
console.log('Usage : node crystal.js <host> <port> [<name>] [<password>]')
5
process.exit(1)
6
}
7
8
const bot = mineflayer.createBot({
9
host: process.argv[2],
10
port: parseInt(process.argv[3]),
11
username: process.argv[4] ? process.argv[4] : 'crystal',
12
password: process.argv[5]
13
})
14
15
bot.on('chat', (username, message) => {
16
if (message === 'compute') {
17
const target = bot.players[username]?.entity
18
if (!target) {
19
bot.chat('I don\'t know where you are')
20
return
21
}
22
const crystal = bot.nearestEntity(entity => entity.name.includes('crystal'))
23
if (!crystal) {
24
bot.chat('No crystal nearby')
25
return
26
}
27
28
const damages = bot.getExplosionDamages(target, crystal.position, 6)
29
30
bot.chat(`You'll take ${damages} damages.`)
31
}
32
})
33
34