From 889259ac5eda45e89973e6b2cecd3e7bf3066267 Mon Sep 17 00:00:00 2001 From: Jean-Patrick Guerrero Date: Fri, 20 Jan 2023 14:39:34 +0100 Subject: [PATCH] Fix Quick Crafting bugs --- src/caches.lua | 2 +- src/common.lua | 34 +++++++++++++++++++--------------- src/gui.lua | 9 ++++++--- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/caches.lua b/src/caches.lua index 5fb9a90..a3c94f2 100644 --- a/src/caches.lua +++ b/src/caches.lua @@ -178,7 +178,7 @@ local function cache_recipes(item) _recipes[#recipes + 1 - k] = v end - local shift = 0 + local shift = 1 local size_rpl = maxn(replacements[item]) local size_rcp = #_recipes diff --git a/src/common.lua b/src/common.lua index 31a7952..a551a4e 100644 --- a/src/common.lua +++ b/src/common.lua @@ -428,26 +428,30 @@ local function craft_stack(player, data, craft_rcp) local remaining = count for _, item in ipairs(item_groups) do - for _name, _count in pairs(data.crafting_counts[rcp_usg].inv) do - if item == _name and remaining > 0 then - local c = min(remaining, _count) - items[item] = c - remaining -= c + for _name, _count in pairs(data.crafting_counts[rcp_usg].inv) do + if item == _name and remaining > 0 then + local c = min(remaining, _count) + items[item] = c + remaining -= c + end + + if remaining == 0 then break end end - - if remaining == 0 then break end - end end end - for k, v in pairs(items) do - inv:remove_item("main", fmt("%s %s", k, v * scrbar_val)) - end - end + for item, v in pairs(items) do + for _ = 1, v * scrbar_val do + inv:remove_item("main", item) - if rcp_def.replacements then - for _, pair in ipairs(rcp_def.replacements) do - get_stack(player, ItemStack(pair[2])) + if rcp_def.replacements then + for _, pair in ipairs(rcp_def.replacements) do + if item == pair[1] then + get_stack(player, ItemStack(pair[2])) + end + end + end + end end end diff --git a/src/gui.lua b/src/gui.lua index 9bba00b..96df8cc 100644 --- a/src/gui.lua +++ b/src/gui.lua @@ -1044,11 +1044,9 @@ local function get_grid_fs(fs, data, rcp, is_recipe, is_usage) local label = groups and "\nG" or "" local replace - for j = 1, #(rcp.replacements or {}) do - local replacement = rcp.replacements[j] + for _, replacement in ipairs(rcp.replacements or {}) do if replacement[1] == name then replace = replace or {type = rcp.type, items = {}} - local added for _, v in ipairs(replace.items) do @@ -1087,7 +1085,12 @@ local function get_grid_fs(fs, data, rcp, is_recipe, is_usage) item:set_name(name) item:set_count(count) local itemstr = ESC(item:to_string()) + item_image_button(X, Y, btn_size, btn_size, itemstr, btn_name, label) + + if item:get_stack_max() < count then + label(X + 0.95, Y + 0.95, count) + end end local def = reg_items[name]