link-discord / mineflayer-auto-eat

Auto eat plugin for mineflayer
https://www.npmjs.com/package/mineflayer-auto-eat
MIT License
33 stars 4 forks source link
javascript minecraft mineflayer typescript

mineflayer-auto-eat

npm npm bundle size GitHub

A customizable and flexible auto-eat utility plugin for Mineflayer bots

Table of Contents

Install

npm install mineflayer-auto-eat

Example

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].

API

Properties

bot.autoEat.enabled

Boolean value indicating whether the auto-eat utility is enabled or disabled.

bot.autoEat.isEating

Boolean value indicating whether the bot is currently eating or not. This value should not be manually set.

bot.autoEat.opts

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
}

bot.autoEat.foods

Returns the foods registry from the bot, which contains all food-related information from the Minecraft data.

bot.autoEat.foodsArray

Returns an array of all available foods in Minecraft from the bot's registry.

bot.autoEat.foodsByName

Returns an object mapping food item names to their properties (e.g., saturation, foodPoints).

Methods

bot.autoEat.setOpts(opts: Partial\<IEatUtilOpts>)

Allows you to modify the configuration options for the auto-eat utility dynamically.

bot.autoEat.setOpts({
    minHunger: 10,
    priority: 'saturation'
})

bot.autoEat.eat(opts: EatOptions)

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)
    })

bot.autoEat.enableAuto()

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()

bot.autoEat.disableAuto()

Disables the automatic eating functionality.

bot.autoEat.disableAuto()

bot.autoEat.cancelEat()

Cancels the current eating action if the bot is in the process of eating.

bot.autoEat.cancelEat()

Settings

IEatUtilOpts

These options define how the EatUtil behaves:

EatOpts

These options are provided to the eat method to override default behavior.:

Events

bot.autoEat.on('eatStart', (opts) => {
    console.log(`Started eating ${opts.food.name}`)
})
bot.autoEat.on('eatFinish', (opts) => {
    console.log(`Finished eating ${opts.food.name}`)
})
bot.autoEat.on('eatFail', (error) => {
    console.error('Eating failed:', error)
})

Authors

👤 Rocco A

👤 Link

Show your support

Give a ⭐️ if this plugin helped you!