Fix Quick Crafting bugs

This commit is contained in:
Jean-Patrick Guerrero 2023-01-20 14:39:34 +01:00
parent 187b0339bd
commit 889259ac5e
3 changed files with 26 additions and 19 deletions

View File

@ -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

View File

@ -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

View File

@ -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]