mineflayer-auto-eat
Version:
An auto eat plugin for mineflayer
101 lines (100 loc) • 3.01 kB
TypeScript
import type { Item } from 'prismarine-item';
import { EventEmitter } from 'events';
import { Bot } from 'mineflayer';
import { Food as MdFood } from 'minecraft-data';
import { StrictEventEmitter } from 'strict-event-emitter-types';
type FoodSelection = MdFood | Item | number | string;
type FoodPriority = 'foodPoints' | 'saturation' | 'effectiveQuality' | 'saturationRatio';
export interface IEatUtilOpts {
priority: FoodPriority;
minHunger: number;
minHealth: number;
bannedFood: string[];
returnToLastItem: boolean;
offhand: boolean;
eatingTimeout: number;
strictErrors: boolean;
}
export interface EatOpts {
food?: FoodSelection;
offhand?: boolean;
equipOldItem?: boolean;
priority?: FoodPriority;
}
export interface SanitizedEatOpts {
food: Item;
offhand: boolean;
equipOldItem: boolean;
}
export interface EatUtilEvents {
eatStart: (opts: SanitizedEatOpts) => void;
eatFail: (error: Error) => void;
eatFinish: (opts: SanitizedEatOpts) => void;
}
declare const EatUtil_base: {
new (): StrictEventEmitter<EventEmitter, EatUtilEvents>;
};
export declare class EatUtil extends EatUtil_base {
private readonly bot;
opts: IEatUtilOpts;
private _eating;
private _enabled;
private _rejectionBinding?;
get foods(): {
[id: number]: MdFood;
};
get foodsArray(): MdFood[];
get foodsByName(): {
[name: string]: MdFood;
};
get isEating(): boolean;
get enabled(): boolean;
constructor(bot: Bot, opts?: Partial<IEatUtilOpts>);
setOpts(opts: Partial<IEatUtilOpts>): void;
cancelEat(): void;
/**
* Given a list of items, determine which food is optimal.
* @param items
* @returns Optimal item.
*/
findBestChoices(items: Item[], priority: FoodPriority): Item[];
/**
* Handle different typings of a food selection.
* Used in {@link sanitizeOpts}.
* @param sel A variety of types that refer to a wanted food item.
* @returns The wanted item in bot's inventory, or nothing.
*/
private normalizeFoodChoice;
/**
* Sanitize options provided to eat function,
* normalizing them to plugin options.
* @param opts
* @returns {boolean} whether opts is correctly sanitized.
*/
private sanitizeOpts;
/**
* Utility function to handle potential changes in inventory and eating status.
* Immediately handles events on a subscriber basis instead of polling.
* @param relevantItem
* @param timeout
* @returns
*/
private buildEatingListener;
/**
* Call this to eat an item.
* @param opts
*/
eat(opts?: EatOpts): Promise<void>;
/**
* Utility function to to eat whenever under health or hunger.
*/
private statusCheck;
/**
* Using timer to desync from physicsTick (attempt to work with mcproxy)
*
* Note: did not change anything.
*/
enableAuto(): void;
disableAuto(): void;
}
export {};