Skip to main content
Glama

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
NameRequiredDescriptionDefault
entityIdYesID of the entity to follow
distanceNoDistance to maintain while following

Implementation Reference

  • 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'),
    },
  • 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)
        }
      }
    )
  • Calls the function that registers the entityInteraction tools, including followEntity.
    registerEntityInteractionTools()

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/nacal/mcp-minecraft-remote'

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