mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-04-21 21:52:07 +02:00
No longer throws error when quantity of ingredients insufficient.
This commit is contained in:
parent
ce5bfbc3bc
commit
58fb27cd66
1 changed files with 15 additions and 2 deletions
|
@ -91,8 +91,21 @@ export async function craftRecipe(bot, itemName, num=1) {
|
||||||
|
|
||||||
const recipe = recipes[0];
|
const recipe = recipes[0];
|
||||||
console.log('crafting...');
|
console.log('crafting...');
|
||||||
await bot.craft(recipe, num, craftingTable);
|
//Check that the agent has sufficient items to use the recipe `num` times.
|
||||||
log(bot, `Successfully crafted ${itemName}, you now have ${world.getInventoryCounts(bot)[itemName]} ${itemName}.`);
|
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<num) log(bot, `Not enough ${limitingItem} to craft ${num}, crafted ${maxNum}. You now have ${world.getInventoryCounts(bot)[itemName]} ${itemName}.`);
|
||||||
|
else log(bot, `Successfully crafted ${itemName}, you now have ${world.getInventoryCounts(bot)[itemName]} ${itemName}.`);
|
||||||
if (placedTable) {
|
if (placedTable) {
|
||||||
await collectBlock(bot, 'crafting_table', 1);
|
await collectBlock(bot, 'crafting_table', 1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue