High-level JavaScript API for creating Minecraft bots with comprehensive world interaction, entity management, and gameplay automation
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Complete inventory management system with equipment handling, item manipulation, crafting capabilities, and container interaction for sophisticated resource management and gameplay automation.
Equip and unequip items to various equipment slots for combat, protection, and functionality.
/**
* Equip an item to a specific equipment destination
* @param item - Item to equip or item type ID
* @param destination - Where to equip the item
* @returns Promise that resolves when equipment completes
*/
equip(item: Item | number, destination: EquipmentDestination | null): Promise<void>;
/**
* Unequip item from a specific equipment destination
* @param destination - Equipment slot to clear
* @returns Promise that resolves when unequip completes
*/
unequip(destination: EquipmentDestination | null): Promise<void>;
/**
* Get the slot number for an equipment destination
* @param destination - Equipment destination name
* @returns Slot number for the destination
*/
getEquipmentDestSlot(destination: string): number;
type EquipmentDestination = "hand" | "head" | "torso" | "legs" | "feet" | "off-hand";Usage Examples:
// Equip armor
const helmet = bot.inventory.items().find(item => item.name.includes("helmet"));
if (helmet) {
await bot.equip(helmet, "head");
}
const sword = bot.inventory.items().find(item => item.name.includes("sword"));
if (sword) {
await bot.equip(sword, "hand");
}
// Equip by item type ID
await bot.equip(bot.registry.itemsByName.diamond_pickaxe.id, "hand");
// Unequip items
await bot.unequip("hand"); // Unequip held item
await bot.unequip("head"); // Remove helmetThrow, drop, and move items within inventory and hotbar.
/**
* Toss/throw an entire item stack
* @param item - Item stack to toss
* @returns Promise that resolves when toss completes
*/
tossStack(item: Item): Promise<void>;
/**
* Toss a specific amount of an item type
* @param itemType - Item type ID to toss
* @param metadata - Item metadata/damage value
* @param count - Number of items to toss
* @returns Promise that resolves when toss completes
*/
toss(itemType: number, metadata: number | null, count: number | null): Promise<void>;
/**
* Select a hotbar slot
* @param slot - Hotbar slot number (0-8)
*/
setQuickBarSlot(slot: number): void;
/**
* Update the held item reference
*/
updateHeldItem(): void;Use and consume items for various effects and interactions.
/**
* Consume the held item (eat food, drink potion, etc.)
* @returns Promise that resolves when consumption completes
*/
consume(): Promise<void>;
/**
* Activate/use the held item
* @param offhand - Use offhand item instead of main hand
*/
activateItem(offhand?: boolean): void;
/**
* Stop using the held item
*/
deactivateItem(): void;
/**
* Start fishing (requires fishing rod in hand)
* @returns Promise that resolves when fishing completes
*/
fish(): Promise<void>;Usage Examples:
// Eat food when hungry
if (bot.food < 18) {
const food = bot.inventory.items().find(item =>
["bread", "apple", "cooked_beef", "cooked_porkchop"].includes(item.name)
);
if (food) {
await bot.equip(food, "hand");
await bot.consume();
}
}
// Use a bow
const bow = bot.inventory.items().find(item => item.name === "bow");
if (bow) {
await bot.equip(bow, "hand");
bot.activateItem(); // Start drawing bow
setTimeout(() => {
bot.deactivateItem(); // Release arrow
}, 1000);
}
// Go fishing
const fishingRod = bot.inventory.items().find(item => item.name === "fishing_rod");
if (fishingRod) {
await bot.equip(fishingRod, "hand");
await bot.fish();
}Access inventory contents and state information.
interface Bot {
/** Bot's inventory window */
inventory: Window<StorageEvents>;
/** Currently held item */
heldItem: Item | null;
/** Whether bot is using held item */
usingHeldItem: boolean;
/** Selected hotbar slot (0-8) */
quickBarSlot: number;
}
interface Window<T = any> {
/** Window type */
type: string;
/** Window ID */
id: number;
/** Window title */
title: string;
/** Number of slots */
slotCount: number;
/** Get all items in window */
items(): Item[];
/** Get item in specific slot */
slots: Array<Item | null>;
/** Get slot by ID */
slot(slot: number): Item | null;
/** Count items of specific type */
count(itemType: number, metadata?: number): number;
/** Find items matching criteria */
findItems(itemType: number, metadata?: number, notFull?: boolean): Item[];
/** Find item by name */
findItem(name: string): Item | null;
}
interface StorageEvents {
/** Window opened */
open(): void;
/** Window closed */
close(): void;
/** Slot updated */
updateSlot(slot: number, oldItem: Item | null, newItem: Item | null): void;
}
interface Item {
/** Item type ID */
type: number;
/** Item count in stack */
count: number;
/** Item metadata/damage value */
metadata: number;
/** Item name */
name: string;
/** Display name with formatting */
displayName: string;
/** Maximum stack size */
stackSize: number;
/** Durability used (for tools/armor) */
durabilityUsed?: number;
/** Maximum durability */
maxDurability?: number;
/** Enchantments on item */
enchants: Enchant[];
/** NBT data */
nbt?: NBT;
/** Slot number in inventory */
slot: number;
}
interface Enchant {
/** Enchantment type */
name: string;
/** Enchantment level */
level: number;
}Interact with inventory slots and manage window operations.
/**
* Click a window slot
* @param slot - Slot number to click
* @param mouseButton - Mouse button (0=left, 1=right, 2=middle)
* @param mode - Click mode (0=click, 1=shift-click, etc.)
* @returns Promise that resolves when click completes
*/
clickWindow(slot: number, mouseButton: number, mode: number): Promise<void>;
/**
* Move item from one slot to another
* @param sourceSlot - Source slot number
* @param destSlot - Destination slot number
* @returns Promise that resolves when move completes
*/
moveSlotItem(sourceSlot: number, destSlot: number): Promise<void>;
/**
* Put away item from a slot to available inventory space
* @param slot - Slot number to put away
* @returns Promise that resolves when operation completes
*/
putAway(slot: number): Promise<void>;
/**
* Transfer items between slots with advanced options
* @param options - Transfer configuration
* @returns Promise that resolves when transfer completes
*/
transfer(options: TransferOptions): Promise<void>;
interface TransferOptions {
/** Target window */
window: Window;
/** Item type to transfer */
itemType: number;
/** Item metadata filter */
metadata: number | null;
/** Number of items to transfer */
count?: number;
/** Source slot range start */
sourceStart: number;
/** Source slot range end */
sourceEnd: number;
/** Destination slot range start */
destStart: number;
/** Destination slot range end */
destEnd: number;
}Simplified mouse clicking for common inventory operations.
interface Bot {
/** Simple click interface */
simpleClick: SimpleClick;
}
interface SimpleClick {
/** Left click a slot */
leftMouse(slot: number): Promise<void>;
/** Right click a slot */
rightMouse(slot: number): Promise<void>;
}Usage Examples:
// Organize inventory - move items around
const sword = bot.inventory.findItem("diamond_sword");
if (sword && sword.slot !== 0) {
await bot.moveSlotItem(sword.slot, 0); // Move to first hotbar slot
}
// Click operations
await bot.simpleClick.leftMouse(10); // Left click slot 10
await bot.simpleClick.rightMouse(15); // Right click slot 15
// Transfer items to chest
const chest = await bot.openChest(chestBlock);
await bot.transfer({
window: chest,
itemType: bot.registry.itemsByName.cobblestone.id,
metadata: null,
count: 64,
sourceStart: 0,
sourceEnd: 35,
destStart: 0,
destEnd: 26
});Craft items and manage recipes for automated production.
/**
* Get recipes that produce a specific item
* @param itemType - Target item type ID
* @param metadata - Item metadata
* @param minResultCount - Minimum result count
* @param craftingTable - Crafting table block or boolean
* @returns Array of matching recipes
*/
recipesFor(
itemType: number,
metadata: number | null,
minResultCount: number | null,
craftingTable: Block | boolean | null
): Recipe[];
/**
* Get all recipes for an item type
* @param itemType - Target item type ID
* @param metadata - Item metadata
* @param craftingTable - Crafting table block or boolean
* @returns Array of all recipes
*/
recipesAll(
itemType: number,
metadata: number | null,
craftingTable: Block | boolean | null
): Recipe[];
/**
* Craft an item using a recipe
* @param recipe - Recipe to craft
* @param count - Number of times to craft (default: 1)
* @param craftingTable - Crafting table block for 3x3 recipes
* @returns Promise that resolves when crafting completes
*/
craft(recipe: Recipe, count?: number, craftingTable?: Block): Promise<void>;
interface Recipe {
/** Recipe ID */
id: number;
/** Result item */
result: Item;
/** Recipe ingredients */
ingredients: Array<Item | null>;
/** Requires crafting table */
requiresTable: boolean;
/** Recipe delta (net item changes) */
delta: Item[];
}Usage Examples:
// Find and craft wooden planks
const logType = bot.registry.itemsByName.oak_log.id;
const plankRecipes = bot.recipesFor(bot.registry.itemsByName.oak_planks.id, null, null, false);
if (plankRecipes.length > 0) {
const recipe = plankRecipes[0];
const hasLogs = bot.inventory.count(logType) > 0;
if (hasLogs) {
await bot.craft(recipe, 4); // Craft 4 times
console.log("Crafted wooden planks!");
}
}
// Craft tools at crafting table
const craftingTable = bot.findBlock({
matching: bot.registry.blocksByName.crafting_table.id,
maxDistance: 16
});
if (craftingTable) {
const pickaxeRecipes = bot.recipesFor(
bot.registry.itemsByName.wooden_pickaxe.id,
null,
null,
craftingTable
);
if (pickaxeRecipes.length > 0) {
await bot.craft(pickaxeRecipes[0], 1, craftingTable);
console.log("Crafted wooden pickaxe!");
}
}Monitor inventory changes and item updates.
interface BotEvents {
/** Window opened */
windowOpen(window: Window): void;
/** Window closed */
windowClose(window: Window): void;
/** Experience gained */
experience(): void;
}
// Storage events (emitted on inventory window)
bot.inventory.on("updateSlot", (slot, oldItem, newItem) => {
if (oldItem?.name !== newItem?.name) {
console.log(`Slot ${slot}: ${oldItem?.name || "empty"} -> ${newItem?.name || "empty"}`);
}
});Complex inventory management patterns and utilities.
// Auto-organize inventory
async function organizeInventory() {
const items = bot.inventory.items();
const itemGroups = new Map<string, Item[]>();
// Group items by type
items.forEach(item => {
if (!itemGroups.has(item.name)) {
itemGroups.set(item.name, []);
}
itemGroups.get(item.name)!.push(item);
});
// Stack items together
for (const [itemName, itemList] of itemGroups) {
if (itemList.length > 1) {
const firstItem = itemList[0];
for (let i = 1; i < itemList.length; i++) {
if (firstItem.count < firstItem.stackSize) {
await bot.moveSlotItem(itemList[i].slot, firstItem.slot);
}
}
}
}
}
// Keep essential items in hotbar
async function maintainHotbar() {
const essentialItems = ["sword", "pickaxe", "axe", "shovel", "food"];
for (let slot = 0; slot < 9; slot++) {
const currentItem = bot.inventory.slot(slot);
if (!currentItem) {
// Find essential item to put in empty slot
for (const essential of essentialItems) {
const item = bot.inventory.items().find(item =>
item.name.includes(essential) && item.slot >= 9
);
if (item) {
await bot.moveSlotItem(item.slot, slot);
break;
}
}
}
}
}
// Auto-eat when hungry
bot.on("health", () => {
if (bot.food < 16) {
const food = bot.inventory.items().find(item =>
item.name.includes("bread") ||
item.name.includes("apple") ||
item.name.includes("cooked")
);
if (food) {
bot.equip(food, "hand").then(() => {
return bot.consume();
}).catch(console.error);
}
}
});