find-block
Locate the nearest block of a specified type within a defined distance in Minecraft, enabling precise navigation and interaction for AI-controlled characters.
Instructions
Find the nearest block of a specific type
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| blockType | Yes | Type of block to find | |
| maxDistance | No | Maximum search distance (default: 16) |
Implementation Reference
- src/bot.ts:462-494 (registration)Registration of the 'find-block' tool, including description, input schema using Zod, and inline async handler function.server.tool( "find-block", "Find the nearest block of a specific type", { blockType: z.string().describe("Type of block to find"), maxDistance: z.number().optional().describe("Maximum search distance (default: 16)") }, async ({ blockType, maxDistance = 16 }): Promise<McpResponse> => { try { const mcData = minecraftData(bot.version); const blocksByName = mcData.blocksByName; if (!blocksByName[blockType]) { return createResponse(`Unknown block type: ${blockType}`); } const blockId = blocksByName[blockType].id; const block = bot.findBlock({ matching: blockId, maxDistance: maxDistance }); if (!block) { return createResponse(`No ${blockType} found within ${maxDistance} blocks`); } return createResponse(`Found ${blockType} at position (${block.position.x}, ${block.position.y}, ${block.position.z})`); } catch (error) { return createErrorResponse(error as Error); } } );
- src/bot.ts:469-493 (handler)The handler function that implements the core logic: resolves block type to ID using minecraftData, finds nearest block using bot.findBlock, and returns position or error.async ({ blockType, maxDistance = 16 }): Promise<McpResponse> => { try { const mcData = minecraftData(bot.version); const blocksByName = mcData.blocksByName; if (!blocksByName[blockType]) { return createResponse(`Unknown block type: ${blockType}`); } const blockId = blocksByName[blockType].id; const block = bot.findBlock({ matching: blockId, maxDistance: maxDistance }); if (!block) { return createResponse(`No ${blockType} found within ${maxDistance} blocks`); } return createResponse(`Found ${blockType} at position (${block.position.x}, ${block.position.y}, ${block.position.z})`); } catch (error) { return createErrorResponse(error as Error); } }
- src/bot.ts:465-468 (schema)Zod schema defining input parameters: required blockType (string) and optional maxDistance (number, default 16).{ blockType: z.string().describe("Type of block to find"), maxDistance: z.number().optional().describe("Maximum search distance (default: 16)") },