Skip to main content
Glama

fly-to

Control a Minecraft bot to navigate to specific coordinates (x, y, z) in the game world for precise movement and exploration.

Instructions

Make the bot fly to a specific position

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
xYesX coordinate
yYesY coordinate
zYesZ coordinate

Implementation Reference

  • The handler function that executes the fly-to tool. It validates creative mode, sets up a timeout and abort controller, creates a Vec3 destination, calls the helper flight operation, handles success/error/timeout responses.
    async ({ x, y, z }) => { const bot = getBot(); if (!bot.creative) { return factory.createResponse("Creative mode is not available. Cannot fly."); } const controller = new AbortController(); const FLIGHT_TIMEOUT_MS = 20000; const timeoutId = setTimeout(() => { if (!controller.signal.aborted) { controller.abort(); } }, FLIGHT_TIMEOUT_MS); try { const destination = new Vec3(x, y, z); await createCancellableFlightOperation(bot, destination, controller); return factory.createResponse(`Successfully flew to position (${x}, ${y}, ${z}).`); } catch (error) { if (controller.signal.aborted) { const currentPosAfterTimeout = bot.entity.position; return factory.createErrorResponse( `Flight timed out after ${FLIGHT_TIMEOUT_MS / 1000} seconds. The destination may be unreachable. ` + `Current position: (${Math.floor(currentPosAfterTimeout.x)}, ${Math.floor(currentPosAfterTimeout.y)}, ${Math.floor(currentPosAfterTimeout.z)})` ); } throw error; } finally { clearTimeout(timeoutId); bot.creative.stopFlying(); } }
  • Zod schema defining input parameters: x, y, z as numbers with descriptions.
    x: z.number().describe("X coordinate"), y: z.number().describe("Y coordinate"), z: z.number().describe("Z coordinate") },
  • Registration of the 'fly-to' tool using factory.registerTool, including name, description, schema, and handler.
    factory.registerTool( "fly-to", "Make the bot fly to a specific position", { x: z.number().describe("X coordinate"), y: z.number().describe("Y coordinate"), z: z.number().describe("Z coordinate") }, async ({ x, y, z }) => { const bot = getBot(); if (!bot.creative) { return factory.createResponse("Creative mode is not available. Cannot fly."); } const controller = new AbortController(); const FLIGHT_TIMEOUT_MS = 20000; const timeoutId = setTimeout(() => { if (!controller.signal.aborted) { controller.abort(); } }, FLIGHT_TIMEOUT_MS); try { const destination = new Vec3(x, y, z); await createCancellableFlightOperation(bot, destination, controller); return factory.createResponse(`Successfully flew to position (${x}, ${y}, ${z}).`); } catch (error) { if (controller.signal.aborted) { const currentPosAfterTimeout = bot.entity.position; return factory.createErrorResponse( `Flight timed out after ${FLIGHT_TIMEOUT_MS / 1000} seconds. The destination may be unreachable. ` + `Current position: (${Math.floor(currentPosAfterTimeout.x)}, ${Math.floor(currentPosAfterTimeout.y)}, ${Math.floor(currentPosAfterTimeout.z)})` ); } throw error; } finally { clearTimeout(timeoutId); bot.creative.stopFlying(); } } );
  • Helper function that wraps bot.creative.flyTo in a Promise with abort handling via AbortController for cancellable flight operations.
    function createCancellableFlightOperation( bot: mineflayer.Bot, destination: Vec3, controller: AbortController ): Promise<boolean> { return new Promise((resolve, reject) => { let aborted = false; controller.signal.addEventListener('abort', () => { aborted = true; bot.creative.stopFlying(); reject(new Error("Flight operation cancelled")); }); bot.creative.flyTo(destination) .then(() => { if (!aborted) { resolve(true); } }) .catch((err: Error) => { if (!aborted) { reject(err); } }); }); }

Other Tools

Related Tools

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