find-block
Locate the nearest block of a specified type within a defined search radius in Minecraft.
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/tools/block-tools.ts:133-154 (handler)The handler function for the 'find-block' tool. It resolves the block type ID from minecraft-data, uses bot.findBlock to locate the nearest matching block within maxDistance, and returns the position if found.async ({ blockType, maxDistance = 16 }) => { const bot = getBot(); const mcData = minecraftData(bot.version); const blocksByName = mcData.blocksByName; if (!blocksByName[blockType]) { return factory.createResponse(`Unknown block type: ${blockType}`); } const blockId = blocksByName[blockType].id; const block = bot.findBlock({ matching: blockId, maxDistance: maxDistance }); if (!block) { return factory.createResponse(`No ${blockType} found within ${maxDistance} blocks`); } return factory.createResponse(`Found ${blockType} at position (${block.position.x}, ${block.position.y}, ${block.position.z})`); }
- src/tools/block-tools.ts:129-132 (schema)Zod schema for 'find-block' tool inputs: required blockType (string) and optional maxDistance (number).{ blockType: z.string().describe("Type of block to find"), maxDistance: z.number().optional().describe("Maximum search distance (default: 16)") },
- src/tools/block-tools.ts:126-155 (registration)Registration of the 'find-block' tool in the ToolFactory, including name, description, schema, and handler.factory.registerTool( "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 }) => { const bot = getBot(); const mcData = minecraftData(bot.version); const blocksByName = mcData.blocksByName; if (!blocksByName[blockType]) { return factory.createResponse(`Unknown block type: ${blockType}`); } const blockId = blocksByName[blockType].id; const block = bot.findBlock({ matching: blockId, maxDistance: maxDistance }); if (!block) { return factory.createResponse(`No ${blockType} found within ${maxDistance} blocks`); } return factory.createResponse(`Found ${blockType} at position (${block.position.x}, ${block.position.y}, ${block.position.z})`); } );