followEntity
Track and maintain a set distance from a specific entity in Minecraft by providing its ID, enabling continuous monitoring or following behavior for remote gameplay control.
Instructions
Follow a specific entity
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| entityId | Yes | ID of the entity to follow | |
| distance | No | Distance to maintain while following |
Implementation Reference
- src/tools/entityInteraction.ts:160-193 (handler)Executes the followEntity tool by finding the target entity and setting a Mineflayer pathfinder GoalFollow to track it at the specified distance.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'), },
- src/tools/entityInteraction.ts:149-194 (registration)Registers the followEntity tool on the MCP server with name, description, input schema, and handler function.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) } } )
- src/tools/index.ts:35-35 (registration)Calls the function that registers the entityInteraction tools, including followEntity.registerEntityInteractionTools()