Skip to main content
Glama

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
NameRequiredDescriptionDefault
blockTypeYesType of block to find
maxDistanceNoMaximum search distance (default: 16)

Implementation Reference

  • 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})`);
    }
  • 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)")
    },
  • 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})`);
      }
    );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/yuniko-software/minecraft-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server