A customizable and flexible auto-eat utility plugin for Mineflayer bots
npm install mineflayer-auto-eat
Warning: This package is ESM only and does not support CommonJS.
import { createBot } from 'mineflayer'
import { loader as autoEat } from 'mineflayer-auto-eat'
const bot = createBot({
host: process.argv[2] || 'localhost',
port: process.argv[3] || 25565,
username: process.argv[4] || 'bot',
auth: process.argv[5] || 'microsoft'
})
bot.once('spawn', async () => {
bot.loadPlugin(autoEat)
bot.autoEat.enableAuto()
bot.autoEat.on('eatStart', (opts) => {
console.log(`Started eating ${opts.food.name} in ${opts.offhand ? 'offhand' : 'hand'}`)
})
bot.autoEat.on('eatFinish', (opts) => {
console.log(`Finished eating ${opts.food.name}`)
})
bot.autoEat.on('eatFail', (error) => {
console.error('Eating failed:', error)
})
})
Run this with node <file>.js [host] [port] [username] [auth]
.
Boolean value indicating whether the auto-eat utility is enabled or disabled.
Boolean value indicating whether the bot is currently eating or not. This value should not be manually set.
This object holds the configurable options for the auto-eat utility.
{
priority: "foodPoints",
minHunger: 15,
minHealth: 14,
returnToLastItem: true,
offhand: false,
eatingTimeout: 3000,
bannedFood: ["rotten_flesh", "pufferfish", "chorus_fruit", "poisonous_potato", "spider_eye"],
strictErrors: true
}
Returns the foods
registry from the bot, which contains all food-related information from the Minecraft data.
Returns an array of all available foods in Minecraft from the bot's registry.
Returns an object mapping food item names to their properties (e.g., saturation, foodPoints).
Allows you to modify the configuration options for the auto-eat utility dynamically.
bot.autoEat.setOpts({
minHunger: 10,
priority: 'saturation'
})
Manually triggers the eating function. If options are not provided, it will automatically pick the best food based on the current options.
bot.autoEat
.eat({
food: 'apple', // optional
offhand: true, // optional
equipOldItem: false, // optional
priority: 'saturation' // optional
})
.then(() => {
console.log('Successfully ate the food!')
})
.catch((err) => {
console.error('Failed to eat:', err)
})
Enables automatic eating based on the bot's hunger and health levels. The bot will automatically check if it needs to eat during each physicsTick
.
bot.autoEat.enableAuto()
Disables the automatic eating functionality.
bot.autoEat.disableAuto()
Cancels the current eating action if the bot is in the process of eating.
bot.autoEat.cancelEat()
These options define how the EatUtil
behaves:
- priority (
FoodPriority
): Defines the priority for choosing food. Acceptable values are"foodPoints"
,"saturation"
,"effectiveQuality"
, and"saturationRatio"
. Default is"foodPoints"
. - minHunger (
number
): If the bot's hunger is less than or equal to this value, the bot will attempt to eat. Default is15
. - minHealth (
number
): If the bot's health is less than or equal to this value, the bot will prioritize eating food with higher saturation. Default is14
. - bannedFood (
string[]
): An array of food names that the bot is not allowed to eat. Default includes"rotten_flesh"
,"pufferfish"
,"chorus_fruit"
,"poisonous_potato"
,"spider_eye"
. - returnToLastItem (
boolean
): Iftrue
, the bot will re-equip the previous item after eating. Default istrue
. - offhand (
boolean
): Iftrue
, the bot will use the offhand to eat. Default isfalse
. - eatingTimeout (
number
): The timeout (in milliseconds) for completing the eating action. Default is3000
. - strictErrors (
boolean
): Iftrue
, errors during the eating process will be thrown. Otherwise, they will be logged to the console. Default istrue
.
These options are provided to the eat
method to override default behavior.:
- food (
FoodSelection
): The food item to eat. If not provided, the bot will automatically choose the best food based on the current options. - offhand (
boolean
): Iftrue
, the bot will use the offhand to eat. Default isfalse
. - equipOldItem (
boolean
): Iftrue
, the bot will re-equip the previous item after eating. Default istrue
. - priority (
FoodPriority
): Defines the priority for choosing food. Acceptable values are"foodPoints"
,"saturation"
,"effectiveQuality"
, and"saturationRatio"
. Default is"foodPoints"
.
- eatStart: Emitted when the bot starts eating an item.
bot.autoEat.on('eatStart', (opts) => {
console.log(`Started eating ${opts.food.name}`)
})
- eatFinish: Emitted when the bot finishes eating.
bot.autoEat.on('eatFinish', (opts) => {
console.log(`Finished eating ${opts.food.name}`)
})
- eatFail: Emitted when the bot fails to eat due to an error.
bot.autoEat.on('eatFail', (error) => {
console.error('Eating failed:', error)
})
👤 Rocco A
👤 Link
- Github: https://github.com/link-discord
- Twitter: https://twitter.com/link0069
- Website: https://linkdiscord.xyz/
- Discord: @link0069
Give a ⭐️ if this plugin helped you!