UNPKG

mineflayer-pvp

Version:

Adds support for basic PVP and PVE to Mineflayer bots.

92 lines (91 loc) 2.9 kB
import { Bot } from "mineflayer"; import { Movements } from "mineflayer-pathfinder"; import { Entity } from "prismarine-entity"; import { TimingSolver } from "./TimingSolver"; /** * The main pvp manager plugin class. */ export declare class PVP { private readonly bot; private timeToNextAttack; private wasInRange; private blockingExplosion; /** * The current target. This value should never be assigned to from outside the plugin. */ target?: Entity; /** * The movements object to pass to pathfinder when creating the follow entity goal. Assign * to null in order to avoid passing any movement config to pathfinder. (If you plan on using * your own) */ movements?: Movements; /** * How close the bot will attempt to get to the target when when pursuing it. */ followRange: number; /** * How far away the target entity must be to lose the target. Target entities further than this * distance from the bot will be considered defeated. */ viewDistance: number; /** * How close must the bot be to the target in order to try attacking it. */ attackRange: number; /** * The timing solver to use when deciding how long to wait before preforming another attack * after finishing an attack. * * // TODO Check for 'hasAtttackCooldown' feature. If feature not present, default to RandomTicks solver. */ meleeAttackRate: TimingSolver; /** * Creates a new instance of the PVP plugin. * * @param bot - The bot this plugin is being attached to. */ constructor(bot: Bot); /** * Causes the bot to begin attacking an entity until it is killed or told to stop. * * @param target - The target to attack. */ attack(target: Entity): Promise<void>; /** * Stops attacking the current entity. */ stop(): Promise<void>; /** * Resolve if event fires within the timeout. Rejects if the event did not fire within the timeout. * @param eventName Event name to listen to * @param timeout Timeout in ms * @returns {Promise<void>} */ onceWithTimeout(eventName: string, timeout: number): Promise<void>; /** * Stops attacking the current entity. Force stops pathfinder. May result in the bot falling off of things or failing jumps. * @returns void */ forceStop(): void; /** * Called each tick to update attack timers. */ private update; /** * Updates whether the bot is in attack range of the target or not. */ private checkRange; /** * Blocks a creeper explosion with a shield. */ private checkExplosion; /** * Attempts to preform an attack on the target. */ private attemptAttack; /** * Check if the bot currently has a shield equipped. */ private hasShield; }