diff --git a/README.md b/README.md index 812aed0..e0bb67a 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,8 @@ Once connected to a Minecraft server, Claude can use these commands: - `list-inventory` - List all items in the bot's inventory - `find-item` - Find a specific item in inventory - `equip-item` - Equip a specific item +- `open-container` - Open a block container or chest at specified coordinates +- `close-window` - Close the window or inventory that the bot currently has open ### Block Interaction - `place-block` - Place a block at specified coordinates diff --git a/src/tools/inventory-tools.ts b/src/tools/inventory-tools.ts index 736bbd7..0d99653 100644 --- a/src/tools/inventory-tools.ts +++ b/src/tools/inventory-tools.ts @@ -1,6 +1,8 @@ import { z } from "zod"; import mineflayer from 'mineflayer'; import { ToolFactory } from '../tool-factory.js'; +import { coerceCoordinates } from "./coordinate-utils.js"; +import { Vec3 } from "vec3"; interface InventoryItem { name: string; @@ -78,4 +80,48 @@ export function registerInventoryTools(factory: ToolFactory, getBot: () => minef return factory.createResponse(`Equipped ${item.name} to ${destination}`); } ); + + factory.registerTool( + "open-container", + "Open a block container or chest at the specified position.", + { + x: z.coerce.number().describe("X coordinate"), + y: z.coerce.number().describe("Y coordinate"), + z: z.coerce.number().describe("Z coordinate"), + }, + async ({ x, y, z }) => { + ({ x, y, z } = coerceCoordinates(x, y, z)); + + const bot = getBot(); + const blockPos = new Vec3(x, y, z); + const block = bot.blockAt(blockPos); + + if (!block) { + return factory.createResponse(`No block information found at position (${x}, ${y}, ${z})`); + } + + const container = await bot.openContainer(block); + + return factory.createResponse(`Opened container (type: ${container.type}) at position (${block.position.x}, ${block.position.y}, ${block.position.z})`); + } + ); + + factory.registerTool( + "close-window", + "Close the window or inventory that the bot currently has open.", + { + }, + async () => { + const bot = getBot(); + const currentBotWindow = bot.currentWindow; + + if (!currentBotWindow) { + return factory.createResponse('The bot does not have a window currently open.'); + } + + bot.closeWindow(currentBotWindow); + + return factory.createResponse(`Closed bot window (type: ${currentBotWindow.type})`); + } + ); }