Furthermore, I wanted to add my new item to the existing tech tree, again without wanting to copy/paste the existing tech tree item definition just to make my change.
Code: Select all
function extendproto(kind, baseclass, t)
local kinds = data.raw[kind]
-- table.deepcopy provided by Factorio
local derived = table.deepcopy(kinds[baseclass])
for k,v in pairs(t) do
derived[k] = v
end
kinds[derived.name] = derived
end
function extendprotolist(typename, classname, field, value)
local l = data.raw[typename][classname][field]
-- TODO: This only handles a single value
table.insert(l, value)
end
Example usage:
Code: Select all
extendproto("constant-combinator", "constant-combinator", {
name = "test-combinator",
})
extendproto("recipe", "constant-combinator", {
name = "test-combinator",
result = "test-combinator"
})
extendproto("item", "constant-combinator", {
name = "test-combinator",
place_result="test-combinator",
order = "b[combinators]-c[test-combinator]",
})
extendprotolist("technology", "circuit-network", "effects", {
type = "unlock-recipe",
recipe = "test-combinator"
})