useOnEntity
Interact with a specific Minecraft entity by using the held item, enabling precise control for inventory management and gameplay actions through remote server commands.
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)The handler function that implements the core logic of the 'useOnEntity' tool. It verifies bot connection, locates the entity by ID, performs bot.useOn(entity), determines the held item, and returns a formatted success response or error.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 defining the required 'entityId' parameter as a number for the 'useOnEntity' tool.{ entityId: z.number().describe('ID of the entity to use item on'), },
- src/tools/entityInteraction.ts:113-146 (registration)Direct registration of the 'useOnEntity' tool using server.tool(), including name, description, 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)Invocation of registerEntityInteractionTools() within registerAllTools(), which registers the 'useOnEntity' tool among entity interaction tools.registerEntityInteractionTools()