1) need to add items for each inserterdarkfrei wrote: ↑Tue Jan 28, 2020 6:54 pmThe code wasn't tested, but must be clear. We made the technology and then going through all inserters. If the inserter is not leech, then we made new leech inserter, new recipe to convert old inserter into the new one, then adding this recipe to the technology effects.
Code: Select all
local prototypes = {} local new_technology = { type = "technology", name = "leech-inserters", icon_size = 128, icon = "__new_mod_name__/graphics/technology/leech-inserters.png", -- picture 128x128 enabled = false, effects = {}, unit.count = 8, unit.ingredients = {{"automation-science-pack", 1}}, unit.time = 1, order = "li-a", } for inserter_name, inserter_prototype in pairs (data.raw.inserter) do if not (inserter_prototype.allow_burner_leech) then --create new prototype! local new_inserter_prototype = table.deepcopy (inserter_prototype) local new_inserter_name = 'leech-' .. inserter_name new_inserter_prototype.name = new_inserter_name new_inserter_prototype.minable = {mining_time = 0.1, result = new_inserter_name} new_inserter_prototype.allow_burner_leech = true table.insert (prototypes, new_inserter_prototype) -- recipe for it local new_recipe = { type = 'recipe', name = new_inserter_name, ingredients = {{inserter_name, 1}}, result = new_inserter_name } table.insert (prototypes, new_recipe) -- add them to the technology effect table.insert(new_technology.effects, {type = "unlock-recipe", recipe = new_inserter_name}) end end if #prototypes > 1 then -- vanilla cannot be extended with empty table; you don't need the technology without effects table.insert (prototypes, new_technology) data:extend (prototypes) end
2) stuff needs to be added to proper sections (data.raw.inserter, item, recipe).
I'd probably do some minor style changes: directly do data.raw.inserter["leeching-" .. other_inserter.name] = table.deepcopy(other_inserter), inserter = data.raw.inserter["leeching-" .. other_inserter.name] and continue to edit that way, unless there's additional modifications you want to do after. You can always do the deepcopy, and then store the table into an "our" table, or vice-versa, store into "our" table, and then a for name, inserter in pairs(leeching_prototypes) do data.raw.inserter[name] = inserter
I think table.deepcopy requires "util" from base or core.
Edit: don't forget to add the technology itself!