import { EventEmitter } from 'events' import TypedEmitter from 'typed-emitter' import { Client, ClientOptions } from 'minecraft-protocol' import { Vec3 } from 'vec3' import { Item } from 'prismarine-item' import { Window } from 'prismarine-windows' import { Recipe } from 'prismarine-recipe' import { Block } from 'prismarine-block' import { Entity } from 'prismarine-entity' import { ChatMessage } from 'prismarine-chat' import { world } from 'prismarine-world' import { Registry } from 'prismarine-registry' export function createBot (options: { client: Client } & Partial): Bot export function createBot (options: BotOptions): Bot export interface BotOptions extends ClientOptions { logErrors?: boolean hideErrors?: boolean loadInternalPlugins?: boolean plugins?: PluginOptions chat?: ChatLevel colorsEnabled?: boolean viewDistance?: ViewDistance mainHand?: MainHands difficulty?: number chatLengthLimit?: number physicsEnabled?: boolean client?: Client brand?: string defaultChatPatterns?: boolean respawn?: boolean } export type ChatLevel = 'enabled' | 'commandsOnly' | 'disabled' export type ViewDistance = 'far' | 'normal' | 'short' | 'tiny' | number export type MainHands = 'left' | 'right' export interface PluginOptions { [plugin: string]: boolean | Plugin } export type Plugin = (bot: Bot, options: BotOptions) => void export interface BotEvents { chat: ( username: string, message: string, translate: string | null, jsonMsg: ChatMessage, matches: string[] | null ) => Promise | void whisper: ( username: string, message: string, translate: string | null, jsonMsg: ChatMessage, matches: string[] | null ) => Promise | void actionBar: (jsonMsg: ChatMessage) => Promise | void error: (err: Error) => Promise | void message: (jsonMsg: ChatMessage, position: string) => Promise | void messagestr: (message: string, position: string, jsonMsg: ChatMessage) => Promise | void unmatchedMessage: (stringMsg: string, jsonMsg: ChatMessage) => Promise | void inject_allowed: () => Promise | void login: () => Promise | void spawn: () => Promise | void respawn: () => Promise | void game: () => Promise | void title: (text: string) => Promise | void rain: () => Promise | void time: () => Promise | void kicked: (reason: string, loggedIn: boolean) => Promise | void end: (reason: string) => Promise | void spawnReset: () => Promise | void death: () => Promise | void health: () => Promise | void breath: () => Promise | void entitySwingArm: (entity: Entity) => Promise | void entityHurt: (entity: Entity) => Promise | void entityDead: (entity: Entity) => Promise | void entityTaming: (entity: Entity) => Promise | void entityTamed: (entity: Entity) => Promise | void entityShakingOffWater: (entity: Entity) => Promise | void entityEatingGrass: (entity: Entity) => Promise | void entityHandSwap: (entity: Entity) => Promise | void entityWake: (entity: Entity) => Promise | void entityEat: (entity: Entity) => Promise | void entityCriticalEffect: (entity: Entity) => Promise | void entityMagicCriticalEffect: (entity: Entity) => Promise | void entityCrouch: (entity: Entity) => Promise | void entityUncrouch: (entity: Entity) => Promise | void entityEquip: (entity: Entity) => Promise | void entitySleep: (entity: Entity) => Promise | void entitySpawn: (entity: Entity) => Promise | void entityElytraFlew: (entity: Entity) => Promise | void usedFirework: () => Promise | void itemDrop: (entity: Entity) => Promise | void playerCollect: (collector: Entity, collected: Entity) => Promise | void entityAttributes: (entity: Entity) => Promise | void entityGone: (entity: Entity) => Promise | void entityMoved: (entity: Entity) => Promise | void entityDetach: (entity: Entity, vehicle: Entity) => Promise | void entityAttach: (entity: Entity, vehicle: Entity) => Promise | void entityUpdate: (entity: Entity) => Promise | void entityEffect: (entity: Entity, effect: Effect) => Promise | void entityEffectEnd: (entity: Entity, effect: Effect) => Promise | void playerJoined: (player: Player) => Promise | void playerUpdated: (player: Player) => Promise | void playerLeft: (entity: Player) => Promise | void blockUpdate: (oldBlock: Block | null, newBlock: Block) => Promise | void 'blockUpdate:(x, y, z)': (oldBlock: Block | null, newBlock: Block | null) => Promise | void chunkColumnLoad: (entity: Vec3) => Promise | void chunkColumnUnload: (entity: Vec3) => Promise | void soundEffectHeard: ( soundName: string, position: Vec3, volume: number, pitch: number ) => Promise | void hardcodedSoundEffectHeard: ( soundId: number, soundCategory: number, position: Vec3, volume: number, pitch: number ) => Promise | void noteHeard: (block: Block, instrument: Instrument, pitch: number) => Promise | void pistonMove: (block: Block, isPulling: number, direction: number) => Promise | void chestLidMove: (block: Block, isOpen: number, block2: Block | null) => Promise | void blockBreakProgressObserved: (block: Block, destroyStage: number) => Promise | void blockBreakProgressEnd: (block: Block) => Promise | void diggingCompleted: (block: Block) => Promise | void diggingAborted: (block: Block) => Promise | void move: (position: Vec3) => Promise | void forcedMove: () => Promise | void mount: () => Promise | void dismount: (vehicle: Entity) => Promise | void windowOpen: (window: Window) => Promise | void windowClose: (window: Window) => Promise | void sleep: () => Promise | void wake: () => Promise | void experience: () => Promise | void physicsTick: () => Promise | void physicTick: () => Promise | void scoreboardCreated: (scoreboard: ScoreBoard) => Promise | void scoreboardDeleted: (scoreboard: ScoreBoard) => Promise | void scoreboardTitleChanged: (scoreboard: ScoreBoard) => Promise | void scoreUpdated: (scoreboard: ScoreBoard, item: number) => Promise | void scoreRemoved: (scoreboard: ScoreBoard, item: number) => Promise | void scoreboardPosition: (position: DisplaySlot, scoreboard: ScoreBoard) => Promise | void teamCreated: (team: Team) => Promise | void teamRemoved: (team: Team) => Promise | void teamUpdated: (team: Team) => Promise | void teamMemberAdded: (team: Team) => Promise | void teamMemberRemoved: (team: Team) => Promise | void bossBarDeleted: (bossBar: BossBar) => Promise | void bossBarUpdated: (bossBar: BossBar) => Promise | void resourcePack: (url: string, hash: string) => Promise | void particle: (particle: Particle) => Promise | void } export interface Bot extends TypedEmitter { username: string protocolVersion: string majorVersion: string version: string entity: Entity entities: { [id: string]: Entity } fireworkRocketDuration: number spawnPoint: Vec3 game: GameState player: Player players: { [username: string]: Player } isRaining: boolean thunderState: number chatPatterns: ChatPattern[] settings: GameSettings experience: Experience health: number food: number foodSaturation: number oxygenLevel: number physics: PhysicsOptions physicsEnabled: boolean time: Time quickBarSlot: number inventory: Window targetDigBlock: Block isSleeping: boolean scoreboards: { [name: string]: ScoreBoard } scoreboard: { [slot in DisplaySlot]: ScoreBoard } teamMap: { [name: string]: Team } controlState: ControlStateStatus creative: creativeMethods world: world.World _client: Client heldItem: Item | null usingHeldItem: boolean currentWindow: Window | null simpleClick: simpleClick tablist: Tablist registry: Registry connect: (options: BotOptions) => void supportFeature: (feature: string) => boolean end: (reason?: string) => void blockAt: (point: Vec3, extraInfos?: boolean) => Block | null blockInSight: (maxSteps: number, vectorLength: number) => Block | null blockAtCursor: (maxDistance?: number, matcher?: Function) => Block | null blockAtEntityCursor: (entity?: Entity, maxDistance?: number, matcher?: Function) => Block | null canSeeBlock: (block: Block) => boolean findBlock: (options: FindBlockOptions) => Block | null findBlocks: (options: FindBlockOptions) => Vec3[] canDigBlock: (block: Block) => boolean recipesFor: ( itemType: number, metadata: number | null, minResultCount: number | null, craftingTable: Block | boolean | null ) => Recipe[] recipesAll: ( itemType: number, metadata: number | null, craftingTable: Block | boolean | null ) => Recipe[] quit: (reason?: string) => void tabComplete: ( str: string, assumeCommand?: boolean, sendBlockInSight?: boolean ) => Promise chat: (message: string) => void whisper: (username: string, message: string) => void chatAddPattern: (pattern: RegExp, chatType: string, description?: string) => number setSettings: (options: Partial) => void loadPlugin: (plugin: Plugin) => void loadPlugins: (plugins: Plugin[]) => void hasPlugin: (plugin: Plugin) => boolean sleep: (bedBlock: Block) => Promise isABed: (bedBlock: Block) => boolean wake: () => Promise elytraFly: () => Promise setControlState: (control: ControlState, state: boolean) => void getControlState: (control: ControlState) => boolean clearControlStates: () => void getExplosionDamages: (targetEntity: Entity, position: Vec3, radius: number, rawDamages?: boolean) => number | null lookAt: (point: Vec3, force?: boolean) => Promise look: ( yaw: number, pitch: number, force?: boolean ) => Promise updateSign: (block: Block, text: string, back?: boolean) => void equip: ( item: Item | number, destination: EquipmentDestination | null ) => Promise unequip: ( destination: EquipmentDestination | null ) => Promise tossStack: (item: Item) => Promise toss: ( itemType: number, metadata: number | null, count: number | null ) => Promise dig: ((block: Block, forceLook?: boolean | 'ignore') => Promise) & ((block: Block, forceLook: boolean | 'ignore', digFace: 'auto' | Vec3 | 'raycast') => Promise) stopDigging: () => void digTime: (block: Block) => number placeBlock: (referenceBlock: Block, faceVector: Vec3) => Promise placeEntity: (referenceBlock: Block, faceVector: Vec3) => Promise activateBlock: (block: Block, direction?: Vec3, cursorPos?: Vec3) => Promise activateEntity: (entity: Entity) => Promise activateEntityAt: (entity: Entity, position: Vec3) => Promise consume: () => Promise fish: () => Promise activateItem: (offhand?: boolean) => void deactivateItem: () => void useOn: (targetEntity: Entity) => void attack: (entity: Entity) => void swingArm: (hand: 'left' | 'right' | undefined, showHand?: boolean) => void mount: (entity: Entity) => void dismount: () => void moveVehicle: (left: number, forward: number) => void setQuickBarSlot: (slot: number) => void craft: ( recipe: Recipe, count?: number, craftingTable?: Block ) => Promise writeBook: ( slot: number, pages: string[] ) => Promise openContainer: (chest: Block | Entity, direction?: Vec3, cursorPos?: Vec3) => Promise openChest: (chest: Block | Entity, direction?: number, cursorPos?: Vec3) => Promise openFurnace: (furnace: Block) => Promise openDispenser: (dispenser: Block) => Promise openEnchantmentTable: (enchantmentTable: Block) => Promise openAnvil: (anvil: Block) => Promise openVillager: ( villager: Entity ) => Promise trade: ( villagerInstance: Villager, tradeIndex: string | number, times?: number ) => Promise setCommandBlock: (pos: Vec3, command: string, trackOutput: boolean) => void clickWindow: ( slot: number, mouseButton: number, mode: number ) => Promise putSelectedItemRange: ( start: number, end: number, window: Window, slot: any ) => Promise putAway: (slot: number) => Promise closeWindow: (window: Window) => void transfer: (options: TransferOptions) => Promise openBlock: (block: Block, direction?: Vec3, cursorPos?: Vec3) => Promise openEntity: (block: Entity, Class: new () => EventEmitter) => Promise moveSlotItem: ( sourceSlot: number, destSlot: number ) => Promise updateHeldItem: () => void getEquipmentDestSlot: (destination: string) => number waitForChunksToLoad: () => Promise nearestEntity: (filter?: (entity: Entity) => boolean) => Entity | null waitForTicks: (ticks: number) => Promise addChatPattern: (name: string, pattern: RegExp, options?: chatPatternOptions) => number addChatPatternSet: (name: string, patterns: RegExp[], options?: chatPatternOptions) => number removeChatPattern: (name: string | number) => void awaitMessage: (...args: string[] | RegExp[]) => Promise acceptResourcePack: () => void denyResourcePack: () => void } export interface simpleClick { leftMouse: (slot: number) => Promise rightMouse: (slot: number) => Promise } export interface Tablist { header: ChatMessage footer: ChatMessage } export interface chatPatternOptions { repeat: boolean parse: boolean } export interface GameState { levelType: LevelType gameMode: GameMode hardcore: boolean dimension: Dimension difficulty: Difficulty maxPlayers: number } export type LevelType = | 'default' | 'flat' | 'largeBiomes' | 'amplified' | 'customized' | 'buffet' | 'default_1_1' export type GameMode = 'survival' | 'creative' | 'adventure' | 'spectator' export type Dimension = 'the_nether' | 'overworld' | 'the_end' export type Difficulty = 'peaceful' | 'easy' | 'normal' | 'hard' export interface Player { uuid: string username: string displayName: ChatMessage gamemode: number ping: number entity: Entity skinData: SkinData | undefined profileKeys?: { publicKey: Buffer signature: Buffer } } export interface SkinData { url: string model: string | null } export interface ChatPattern { pattern: RegExp type: string description: string } export interface SkinParts { showCape: boolean showJacket: boolean showLeftSleeve: boolean showRightSleeve: boolean showLeftPants: boolean showRightPants: boolean showHat: boolean } export interface GameSettings { chat: ChatLevel colorsEnabled: boolean viewDistance: ViewDistance difficulty: number skinParts: SkinParts mainHand: MainHands } export interface Experience { level: number points: number progress: number } export interface PhysicsOptions { maxGroundSpeed: number terminalVelocity: number walkingAcceleration: number gravity: number groundFriction: number playerApothem: number playerHeight: number jumpSpeed: number yawSpeed: number sprintSpeed: number maxGroundSpeedSoulSand: number maxGroundSpeedWater: number } export interface Time { doDaylightCycle: boolean bigTime: BigInt time: number timeOfDay: number day: number isDay: boolean moonPhase: number bigAge: BigInt age: number } export interface ControlStateStatus { forward: boolean back: boolean left: boolean right: boolean jump: boolean sprint: boolean sneak: boolean } export type ControlState = | 'forward' | 'back' | 'left' | 'right' | 'jump' | 'sprint' | 'sneak' export interface Effect { id: number amplifier: number duration: number } export interface Instrument { id: number name: 'harp' | 'doubleBass' | 'snareDrum' | 'sticks' | 'bassDrum' } export interface FindBlockOptions { point?: Vec3 matching: number | number[] | ((block: Block) => boolean) maxDistance?: number count?: number useExtraInfo?: boolean | ((block: Block) => boolean) } export type EquipmentDestination = 'hand' | 'head' | 'torso' | 'legs' | 'feet' | 'off-hand' export interface TransferOptions { window: Window itemType: number metadata: number | null count?: number, sourceStart: number sourceEnd: number destStart: number destEnd: number } export interface creativeMethods { setInventorySlot: ( slot: number, item: Item | null ) => Promise clearSlot: (slot: number) => Promise clearInventory: () => Promise flyTo: (destination: Vec3) => Promise startFlying: () => void stopFlying: () => void } export class Location { floored: Vec3 blockPoint: Vec3 chunkCorner: Vec3 blockIndex: number biomeBlockIndex: number chunkYIndex: number constructor (absoluteVector: Vec3); } export class Painting { id: number position: Vec3 name: string direction: Vec3 constructor (id: number, position: Vec3, name: string, direction: Vec3); } interface StorageEvents { open: () => void close: () => void updateSlot: (oldItem: Item | null, newItem: Item | null) => void } interface FurnaceEvents extends StorageEvents { update: () => void } interface ConditionalStorageEvents extends StorageEvents { ready: () => void } export class Chest extends Window { constructor (); close (): void; deposit ( itemType: number, metadata: number | null, count: number | null ): Promise; withdraw ( itemType: number, metadata: number | null, count: number | null ): Promise; } export class Furnace extends Window { fuel: number progress: number constructor (); close (): void; takeInput (): Promise; takeFuel (): Promise; takeOutput (): Promise; putInput ( itemType: number, metadata: number | null, count: number ): Promise; putFuel ( itemType: number, metadata: number | null, count: number ): Promise; inputItem (): Item; fuelItem (): Item; outputItem (): Item; } export class Dispenser extends Window { constructor (); close (): void; deposit ( itemType: number, metadata: number | null, count: number | null ): Promise; withdraw ( itemType: number, metadata: number | null, count: number | null ): Promise; } export class EnchantmentTable extends Window { enchantments: Enchantment[] constructor (); close (): void; targetItem (): Item; enchant ( choice: string | number ): Promise; takeTargetItem (): Promise; putTargetItem (item: Item): Promise; putLapis (item: Item): Promise; } export class Anvil { combine (itemOne: Item, itemTwo: Item, name?: string): Promise rename (item: Item, name?: string): Promise } export interface Enchantment { level: number expected: { enchant: number, level: number } } export class Villager extends Window { trades: VillagerTrade[] constructor (); close (): void; } export interface VillagerTrade { inputItem1: Item outputItem: Item inputItem2: Item | null hasItem2: boolean tradeDisabled: boolean nbTradeUses: number maximumNbTradeUses: number xp?: number specialPrice?: number priceMultiplier?: number demand?: number realPrice?: number } export class ScoreBoard { name: string title: string itemsMap: { [name: string]: ScoreBoardItem } items: ScoreBoardItem[] constructor (packet: object); setTitle (title: string): void; add (name: string, value: number, displayName: ChatMessage): ScoreBoardItem; remove (name: string): ScoreBoardItem; } export interface ScoreBoardItem { name: string displayName: ChatMessage value: number } export class Team { name: ChatMessage friendlyFire: number nameTagVisibility: string collisionRule: string color: string prefix: ChatMessage suffix: ChatMessage constructor (packet: object); parseMessage (value: string): ChatMessage; add (name: string, value: number): void; remove (name: string): void; update (name: string, friendlyFire: boolean, nameTagVisibility: string, collisionRule: string, formatting: number, prefix: string, suffix: string): void; displayName (member: string): ChatMessage; } export type DisplaySlot = | 'list' | 'sidebar' | 'belowName' | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 export class BossBar { entityUUID: string title: ChatMessage health: number dividers: number color: 'pink' | 'blue' | 'red' | 'green' | 'yellow' | 'purple' | 'white' shouldDarkenSky: boolean isDragonBar: boolean shouldCreateFog: boolean constructor ( uuid: string, title: string, health: number, dividers: number, color: number, flags: number ); } export class Particle { id: number name: string position: Vec3 offset: Vec3 count: number movementSpeed: number longDistanceRender: boolean static fromNetwork(packet: Object): Particle constructor ( id: number, position: Vec3, offset: Vec3, count?: number, movementSpeed?: number, longDistanceRender?: boolean ); } export let supportedVersions: string[] export let testedVersions: string[] export function supportFeature (feature: string, version: string): boolean