useOnEntity
Apply a held item to a specific entity in Minecraft by providing its entity ID, enabling targeted interactions like feeding animals or activating mechanisms.
Instructions
Use held item on a specific entity
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| entityId | Yes | ID of the entity to use item on |
Implementation Reference
- src/tools/entityInteraction.ts:119-146 (handler)Executes the 'useOnEntity' tool: validates connection, retrieves entity by ID, uses the bot's held item on the entity via bot.useOn(entity), and returns success or error response.async ({ entityId }) => { 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.`) } // Use current item on the entity await botState.bot.useOn(entity) const heldItem = botState.bot.heldItem ? botState.bot.heldItem.name : 'hand' return createSuccessResponse( `Used ${heldItem} on entity: ${ entity.name || entity.username || 'Unknown entity' } (ID: ${entityId})` ) } catch (error) { return createErrorResponse(error) } } )
- Zod input schema for 'useOnEntity' tool defining the required entityId parameter.{ entityId: z.number().describe('ID of the entity to use item on'), },
- src/tools/entityInteraction.ts:113-146 (registration)Registers the 'useOnEntity' MCP tool with server.tool, providing name, description, input schema, and handler function.server.tool( 'useOnEntity', 'Use held item on a specific entity', { entityId: z.number().describe('ID of the entity to use item on'), }, async ({ entityId }) => { 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.`) } // Use current item on the entity await botState.bot.useOn(entity) const heldItem = botState.bot.heldItem ? botState.bot.heldItem.name : 'hand' return createSuccessResponse( `Used ${heldItem} on entity: ${ entity.name || entity.username || 'Unknown entity' } (ID: ${entityId})` ) } catch (error) { return createErrorResponse(error) } } )
- src/tools/index.ts:35-35 (registration)Top-level registration call within registerAllTools() that invokes the entity interaction tools registration, including 'useOnEntity'.registerEntityInteractionTools()
- src/index.ts:7-7 (registration)Ultimate registration point calling registerAllTools(), which chains to 'useOnEntity' tool registration.registerAllTools()