first part gets the list of recipes and second section loops thru and replaces the items
Code: Select all
local test_list = {}
local n_e_recipes = {}
for i, recipe in pairs(data.raw.recipe) do
if recipe.ingredients then
table.insert(test_list,recipe.name)
elseif recipe.normal.ingredients then
table.insert(n_e_recipes,recipe.name)
end
end
for i, recipe_name in ipairs(test_list) do
local ingredients = table.deepcopy(data.raw.recipe[recipe_name].ingredients)
for k, ingredient in ipairs(ingredients) do
for j,l in pairs(items_dict) do
if ingredient.name == j then
local recipeingredamount = (table.deepcopy(data.raw.recipe[recipe_name].ingredients[k].amount))
data.raw.recipe[recipe_name].ingredients[k] = {l, recipeingredamount}
end
end
end
end
Code: Select all
for i, recipe_name in ipairs(n_e_recipes) do
local ingredients = table.deepcopy(data.raw.recipe[recipe_name].normal.ingredients)
for k, ingredient in ipairs(ingredients) do
for j, item_name in ipairs(items_list) do
if ingredient.name == item_name then
local recipeingredamount = (table.deepcopy(data.raw.recipe[recipe_name].normal.ingredients[k].amount))
data.raw.recipe[recipe_name].normal.ingredients[k] = {replacement_item, recipeingredamount}
end
end
end
end