followEntity
Track and follow a specific entity in Minecraft by its ID, maintaining a desired distance. Ideal for AI-controlled players on remote servers.
Instructions
Follow a specific entity
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| distance | No | Distance to maintain while following | |
| entityId | Yes | ID of the entity to follow |
Implementation Reference
- src/tools/entityInteraction.ts:160-193 (handler)The asynchronous handler function that implements the logic for the followEntity tool. It checks connection, finds the entity, sets a pathfinder GoalFollow goal, and returns a success response.async ({ entityId, distance }) => { if (!botState.isConnected || !botState.bot) { return createNotConnectedResponse() } try { // Find the entity by ID const entity = botState.bot.entities[entityId] if (!entity) { return createSuccessResponse(`Entity with ID ${entityId} not found.`) } // Start following the entity return new Promise<ToolResponse>((resolve) => { // Import pathfinder goals const { goals } = require('mineflayer-pathfinder') // Start following the entity botState.bot!.pathfinder.setGoal( new goals.GoalFollow(entity, distance) ) resolve( createSuccessResponse( `Following entity: ${ entity.name || entity.username || 'Unknown entity' } (ID: ${entityId}) with distance of ${distance} blocks` ) ) }) } catch (error) { return createErrorResponse(error) } }
- src/tools/entityInteraction.ts:149-194 (registration)The server.tool registration call that defines the followEntity tool, including name, description, input schema, and handler.server.tool( 'followEntity', 'Follow a specific entity', { entityId: z.number().describe('ID of the entity to follow'), distance: z .number() .optional() .default(2) .describe('Distance to maintain while following'), }, async ({ entityId, distance }) => { if (!botState.isConnected || !botState.bot) { return createNotConnectedResponse() } try { // Find the entity by ID const entity = botState.bot.entities[entityId] if (!entity) { return createSuccessResponse(`Entity with ID ${entityId} not found.`) } // Start following the entity return new Promise<ToolResponse>((resolve) => { // Import pathfinder goals const { goals } = require('mineflayer-pathfinder') // Start following the entity botState.bot!.pathfinder.setGoal( new goals.GoalFollow(entity, distance) ) resolve( createSuccessResponse( `Following entity: ${ entity.name || entity.username || 'Unknown entity' } (ID: ${entityId}) with distance of ${distance} blocks` ) ) }) } catch (error) { return createErrorResponse(error) } } )
- Zod schema defining the input parameters for the followEntity tool: entityId (required number) and distance (optional number, default 2).entityId: z.number().describe('ID of the entity to follow'), distance: z .number() .optional() .default(2) .describe('Distance to maintain while following'),