I managed to frankenstein this code and it works.
Code: Select all
-- Add byproducts
data.raw.recipe["edrill-0to1"].main_product="electric-mining-drill"
data.raw.recipe["edrill-0to1"].results={{name="electric-mining-drill",probability=1,amount=1},{name="iron-dust",probability=0.4,amount=1}}
local recipes =
{
-- {<item_name>, <probability_1>, <amount_1>, <dust_name_1>, <dust_probability_1>, <dust_amount_1>, <dust_name_2>, <dust_probability_2>, <dust_amount_2>}
-- Logistics
{"iron-chest" , 1, 1, "iron-dust", 0.8, 1},
{"transport-belt" , 1, 2, "iron-dust", 0.1, 1},
{"chute-miniloader" , 1, 1, "iron-dust", 0.1, 1},--modded
{"burner-inserter" , 1, 1, "iron-dust", 0.1, 1},
{"burner-long-handed-inserter", 1, 1, "iron-dust", 0.1, 1},
{"fast-inserter" , 1, 1, "iron-dust", 0.2, 1},
{"pipe" , 1, 1, "iron-dust", 0.1, 1},
{"pipe-to-ground" , 1, 1, "iron-dust", 0.5, 1},
{"underground-belt" , 1, 1, "iron-dust", 1, 1},
{"splitter" , 1, 1, "iron-dust", 0.5, 1},
{"aai-loader" , 1, 1, "iron-dust", 0.6, 1},--modded
-- Production
{"steam-engine" , 1, 1, "iron-dust", 1.0, 1},
{"burner-mining-drill" , 1, 1, "iron-dust", 0.3, 1},
{"electric-mining-drill" , 1, 1, "iron-dust", 1.0, 1},
--{"edrill-0to1" , 1, 1, "iron-dust", 0.4, 1}, recipe name doesnt match with item name
{"assembling-machine-1" , 1, 1, "iron-dust", 0.9, 1},
-- Intermediate products
{"copper-cable" , 1, 2, "copper-dust", 0.1, 1},
{"iron-stick" , 1, 2, "iron-dust", 0.1, 1},
{"iron-gear-wheel" , 1, 1, "iron-dust", 0.2, 1},
{"electronic-circuit" , 1, 1, "iron-dust", 0.1, 1},
{"automation-science-pack" , 1, 1, "copper-dust", 0.1, 1},
{"rp-steam-calculator" , 1, 1, "copper-dust", 0.5, 1},--modded
-- Combat
{"pistol" , 1, 1, "iron-dust", 0.5, 1, "copper-dust", 0.5, 1},
{"firearm-magazine" , 1, 1, "iron-dust", 0.4, 1},
{"light-armor" , 1, 1, "iron-dust", 1.0, 4},
{"radar" , 1, 1, "iron-dust", 1.0, 1}
}
for _, recipe in ipairs(recipes) do
local mainRecipe, prob1, amt1, dust1, dProb1, amt2, dust2, dProb2, amt3 = unpack(recipe)
if data.raw.recipe[mainRecipe] then
if data.raw.recipe[mainRecipe].normal then
data.raw.recipe[mainRecipe].normal.main_product = mainRecipe
data.raw.recipe[mainRecipe].normal.results = {{name = mainRecipe, probability = prob1, amount = amt1}}
if dust1 then
table.insert(data.raw.recipe[mainRecipe].normal.results, {name = dust1, probability = dProb1, amount = amt2})
end
if dust2 then
table.insert(data.raw.recipe[mainRecipe].normal.results, {name = dust2, probability = dProb2, amount = amt3})
end
end
if data.raw.recipe[mainRecipe].expensive then
data.raw.recipe[mainRecipe].expensive.main_product = mainRecipe
data.raw.recipe[mainRecipe].expensive.results = {{name = mainRecipe, probability = prob1, amount = amt1}}
if dust1 then
table.insert(data.raw.recipe[mainRecipe].expensive.results, {name = dust1, probability = dProb1, amount = amt2})
end
if dust2 then
table.insert(data.raw.recipe[mainRecipe].expensive.results, {name = dust2, probability = dProb2, amount = amt3})
end
else
data.raw.recipe[mainRecipe].main_product = mainRecipe
data.raw.recipe[mainRecipe].results = {{name = mainRecipe, probability = prob1, amount = amt1}}
if dust1 then
table.insert(data.raw.recipe[mainRecipe].results, {name = dust1, probability = dProb1, amount = amt2})
end
if dust2 then
table.insert(data.raw.recipe[mainRecipe].results, {name = dust2, probability = dProb2, amount = amt3})
end
end
else
end
end
But now, I'd like to try adding the byproducts automatically, based on how much each recipe has of a certain ingredient.
Please help, I'm a total noob at programming and modding. Thanks.