From 58fb27cd66a021e7e0a6694dd208853f93b14b5c Mon Sep 17 00:00:00 2001 From: BF5258 <@gmail.com> Date: Wed, 25 Sep 2024 11:43:31 +1000 Subject: [PATCH] No longer throws error when quantity of ingredients insufficient. --- src/agent/library/skills.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/agent/library/skills.js b/src/agent/library/skills.js index ec887a2..cffd54b 100644 --- a/src/agent/library/skills.js +++ b/src/agent/library/skills.js @@ -91,8 +91,21 @@ export async function craftRecipe(bot, itemName, num=1) { const recipe = recipes[0]; console.log('crafting...'); - await bot.craft(recipe, num, craftingTable); - log(bot, `Successfully crafted ${itemName}, you now have ${world.getInventoryCounts(bot)[itemName]} ${itemName}.`); + //Check that the agent has sufficient items to use the recipe `num` times. + const inventory = world.getInventoryCounts(bot); + let limitingItem; + let maxNum = num; + for (const ingredient of recipe.ingredients) { + const ingredientName = mc.getItemName(ingredient.id); + const itemsRemaining = inventory[ingredientName] + ingredient.count * maxNum; + if (itemsRemaining < 0) { + limitingItem = ingredientName; + maxNum -= Math.ceil(itemsRemaining / ingredient.count); + } + } + await bot.craft(recipe, maxNum, craftingTable); + if(maxNum