depositItem
Put items into an open container in Minecraft by specifying the item name and quantity to deposit.
Instructions
Put items into an open container
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| itemName | Yes | Name of the item to deposit | |
| amount | No | Amount of items to deposit |
Implementation Reference
- The handler function for the depositItem tool. It verifies connection and open container, locates items in inventory matching the itemName, and deposits up to the specified amount into the container using deposit method.async ({ itemName, amount }) => { if (!botState.isConnected || !botState.bot) { return createNotConnectedResponse() } try { // Check if a container is open if (!botState.currentContainer) { return createSuccessResponse( 'No container is currently open. Use openContainer first.' ) } // Find the item in inventory const matchingItems = botState.bot.inventory .items() .filter( (item) => item !== null && item.name && item.name.toLowerCase() === itemName.toLowerCase() ) if (matchingItems.length === 0) { return createSuccessResponse( `Item "${itemName}" not found in your inventory.` ) } // Calculate how many items to deposit let remainingAmount = amount let depositedAmount = 0 // Deposit items from each matching slot until we've deposited enough for (const item of matchingItems) { if (remainingAmount <= 0) break const amountFromThisItem = Math.min(remainingAmount, item.count) // Ensure item.type exists if (typeof item.type !== 'number') { continue // Skip this item if type is not available } await botState.currentContainer.deposit( item.type, null, amountFromThisItem ) remainingAmount -= amountFromThisItem depositedAmount += amountFromThisItem } return createSuccessResponse( `Deposited ${depositedAmount} x ${itemName} into the container.` ) } catch (error) { return createErrorResponse(error) } }
- Zod schema defining input parameters for depositItem: itemName (required string) and amount (optional number, defaults to 1).{ itemName: z.string().describe('Name of the item to deposit'), amount: z .number() .optional() .default(1) .describe('Amount of items to deposit'), },
- src/tools/containerInteraction.ts:161-233 (registration)Direct registration of the depositItem tool via server.tool call within registerContainerInteractionTools function, including schema and handler.server.tool( 'depositItem', 'Put items into an open container', { itemName: z.string().describe('Name of the item to deposit'), amount: z .number() .optional() .default(1) .describe('Amount of items to deposit'), }, async ({ itemName, amount }) => { if (!botState.isConnected || !botState.bot) { return createNotConnectedResponse() } try { // Check if a container is open if (!botState.currentContainer) { return createSuccessResponse( 'No container is currently open. Use openContainer first.' ) } // Find the item in inventory const matchingItems = botState.bot.inventory .items() .filter( (item) => item !== null && item.name && item.name.toLowerCase() === itemName.toLowerCase() ) if (matchingItems.length === 0) { return createSuccessResponse( `Item "${itemName}" not found in your inventory.` ) } // Calculate how many items to deposit let remainingAmount = amount let depositedAmount = 0 // Deposit items from each matching slot until we've deposited enough for (const item of matchingItems) { if (remainingAmount <= 0) break const amountFromThisItem = Math.min(remainingAmount, item.count) // Ensure item.type exists if (typeof item.type !== 'number') { continue // Skip this item if type is not available } await botState.currentContainer.deposit( item.type, null, amountFromThisItem ) remainingAmount -= amountFromThisItem depositedAmount += amountFromThisItem } return createSuccessResponse( `Deposited ${depositedAmount} x ${itemName} into the container.` ) } catch (error) { return createErrorResponse(error) } } )
- src/tools/index.ts:38-38 (registration)Top-level call to registerContainerInteractionTools() from within registerAllTools(), which triggers the registration of depositItem and other container tools.registerContainerInteractionTools()