Return early when there's not enough items for craft

This commit is contained in:
Andrey Kozlovskiy 2019-08-24 03:56:38 +03:00
parent 573048520a
commit f42bfaf880
1 changed files with 14 additions and 0 deletions

View File

@ -213,6 +213,11 @@ function unified_inventory.match_items(m, craft_index, item_index)
local times_used = #item.craft_positions
local cell_count = math.floor(index.total_count / times_used)
if cell_count == 0 then
m.count = 0
return
end
index.times_matched = times_used
m.count = math.min(m.count, cell_count)
@ -241,6 +246,11 @@ function unified_inventory.match_groups(m, craft_index, item_index)
end
end
if cell_count == 0 then
m.count = 0
return
end
m.count = math.min(m.count, cell_count)
m.items[craft_pos] = matched_item.name
@ -261,6 +271,10 @@ function unified_inventory.get_match_table(craft_index, item_index)
unified_inventory.match_items(match_table, craft_index, item_index)
unified_inventory.match_groups(match_table, craft_index, item_index)
if match_table.count == 0 then
return
end
return match_table
end