Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PrismarineJS
GitHub Repository: PrismarineJS/mineflayer
Path: blob/master/examples/bee.js
3738 views
1
const mineflayer = require('mineflayer')
2
3
if (process.argv.length < 4 || process.argv.length > 6) {
4
console.log('Usage : node bee.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] : 'bee',
12
password: process.argv[5],
13
verbose: true
14
})
15
16
// /gamemode creative bee
17
18
async function loop (n) {
19
for (let i = 0; i <= n; i++) {
20
const { position } = bot.entity
21
await bot.creative.flyTo(position.offset(Math.sin(i) * 2, 0.5, Math.cos(i) * 2))
22
}
23
bot.chat('My flight was amazing !')
24
}
25
26
bot.on('chat', async (username, message) => {
27
if (username === bot.username) return
28
switch (message) {
29
case 'loaded':
30
await bot.waitForChunksToLoad()
31
bot.chat('Ready!')
32
break
33
case 'fly':
34
bot.creative.startFlying()
35
loop(10)
36
break
37
}
38
})
39
40