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/auto-eat.js
Views: 789
1
const mineflayer = require('mineflayer')
2
const autoeat = require('mineflayer-auto-eat')
3
4
const bot = mineflayer.createBot({
5
host: process.argv[2],
6
port: process.argv[3],
7
username: process.argv[4],
8
password: process.argv[5]
9
})
10
11
// Load the plugin
12
bot.loadPlugin(autoeat)
13
14
bot.once('spawn', () => {
15
bot.autoEat.options = {
16
priority: 'foodPoints',
17
startAt: 14,
18
bannedFood: []
19
}
20
})
21
// The bot eats food automatically and emits these events when it starts eating and stops eating.
22
23
bot.on('autoeat_started', () => {
24
console.log('Auto Eat started!')
25
})
26
27
bot.on('autoeat_stopped', () => {
28
console.log('Auto Eat stopped!')
29
})
30
31
bot.on('health', () => {
32
if (bot.food === 20) bot.autoEat.disable()
33
// Disable the plugin if the bot is at 20 food points
34
else bot.autoEat.enable() // Else enable the plugin again
35
})
36
37