From 8a88df815ffaefd7a5082bc0eb8176e2aa1d0e56 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Thu, 20 Jun 2019 10:02:40 -0400 Subject: [PATCH] milo: crafting fixes --- milo/apis/craft2.lua | 14 +++++++++++--- milo/plugins/item/recipeTab.lua | 4 +--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/milo/apis/craft2.lua b/milo/apis/craft2.lua index 13891c7..b2d3e8c 100644 --- a/milo/apis/craft2.lua +++ b/milo/apis/craft2.lua @@ -56,7 +56,7 @@ local function getCraftingTool(storage, item) return item end -function Craft.ingedients(recipe) +function Craft.ingredients(recipe) local i = 0 local keys = Util.keys(recipe.ingredients) return function() @@ -297,7 +297,16 @@ function Craft.craftRecipeInternal(recipe, count, storage, origItem, path) count = canCraft end + local function maxBatch() + local max = 64 + for _, i in Craft.ingredients(recipe) do + max = math.min(max, math.floor(64 / i.count)) + end + return max + end + local maxCount = recipe.maxCount or math.floor(64 / recipe.count) + maxCount = math.min(maxCount, maxBatch()) repeat local craftedIngredient @@ -463,8 +472,7 @@ function Craft.getCraftableAmount(inRecipe, inCount, items, missing) local canCraft = 0 for _ = 1, count do - for _,entry in pairs(recipe.ingredients) do - local item = convert(entry) + for _, item in Craft.ingredients(recipe) do local summedItem = summedItems[item.key] or Craft.getItemCount(items, item.key) local irecipe = findValidRecipe(item.key, path) diff --git a/milo/plugins/item/recipeTab.lua b/milo/plugins/item/recipeTab.lua index 4f4edc2..458050f 100644 --- a/milo/plugins/item/recipeTab.lua +++ b/milo/plugins/item/recipeTab.lua @@ -37,9 +37,7 @@ function recipeTab:setItem(item) local t = { } if self.recipe then - for k, v in Craft.ingedients(self.recipe) do -_syslog(k) -_syslog(v) + for k, v in Craft.ingredients(self.recipe) do table.insert(t, { slot = k, key = v.key,