Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions autocrafter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,11 @@ end

local function get_ingredients(src, recipe)
local items = {}
for i, stack in ipairs(src) do
-- Work backwards to avoid creating gaps or partial stacks
for i=#src, 1, -1 do
Comment thread
OgelGames marked this conversation as resolved.
Outdated
local stack = src[i]
if not stack:is_empty() then
items[i] = stack:get_name()
items[#items+1] = {stack = stack, name = stack:get_name()}
Comment thread
OgelGames marked this conversation as resolved.
Outdated
end
end
local ingredients = {}
Expand All @@ -255,11 +257,12 @@ local function get_ingredients(src, recipe)
if group and group_index[group] then
match_items = group_index[group].items
end
for j, name in pairs(items) do
if match_items[name] then
ingredients[i] = src[j]:take_item()
if src[j]:is_empty() then
items[j] = nil
for j, item in ipairs(items) do
if match_items[item.name] then
ingredients[i] = item.stack:take_item()
if item.stack:is_empty() then
-- Need to use `table.remove` to not break subsequent iterations
table.remove(items, j)
end
found = true ; break
end
Expand Down