Re: [Mod 0.17.54] Factorio Bitumen
Posted: Thu Aug 08, 2019 3:40 pm
Bobs mods compatibilities are qued up...
Did you figure out how to do this? I have a method that's worked well in my mods if you would like a code snippet.
Shenpen wrote: ↑Mon Aug 12, 2019 10:50 amNo. I can make it work with Bobs' installed, but it then errors when trying to load, while Bobs' is not present.
Code: Select all
if mods["modname"] then
-- use their recipe now.
end
Code: Select all
if game.active_mods["modname"] then
-- do something because mod is present
end
Ahh, thanks for the reminder that I meant to come back to this.
Code: Select all
if data.raw.recipe["other-mod-asphalt"] then
new_ingred_table = {{"bitumen-asphalt-name", number}, ...other ingredients... }
new_recipe_table = etc.
data,raw.recipe["other-mod-asphalt"].ingredients = new_ingred_table
data.raw.recipe["bitumen-asphalt-recipe"] = new_recipe_table
end
Code: Select all
replace_in_recipe_io = function(
recipe,
old_name,
new_name,
amount_mult
)
if type(recipe) == "string" then
recipe = data.raw.recipe[recipe]
end
if not recipe
or not (type(recipe) == "table")
or not recipe.type
or not (recipe.type == "recipe") then
return false
end
if amount_mult == nil
or type(amount_mult) ~= "number" then
amount_mult = 1
end
if recipe.result then
if recipe.result == old_name then
recipe.result = new_name
recipe.result_count = math.floor(
(recipe.result_count or 1)
* amount_mult
)
end
end
if recipe.normal and recipe.normal.result then
if recipe.normal.result == old_name then
recipe.normal.result = new_name
recipe.normal.result_count = math.floor(
(recipe.normal.result_count or 1)
* amount_mult
)
end
end
if recipe.expensive and recipe.expensive.result then
if recipe.expensive.result == old_name then
recipe.expensive.result = new_name
recipe.expensive.result_count = math.floor(
(recipe.expensive.result_count or 1)
* amount_mult
)
end
end
for _,ingredient in pairs(recipe.ingredients or {}) do
if ingredient.name == old_name then
ingredient.name = new_name
ingredient.amount = math.ceil(
(ingredient.amount or ingredient[2] or 1)
* amount_mult
)
ingredient[2] = nil
end
if ingredient[1] == old_name then
ingredient[1] = new_name
ingredient[2] = math.ceil(
(ingredient[2] or ingredient.amount or 1)
* amount_mult
)
ingredient.amount = nil
end
if ingredient.name == nil
and ingredient[1] == nil then
ingredient = nil
end
end
if recipe.normal then
for _,ingredient
in pairs(recipe.normal.ingredients or {}) do
if ingredient.name == old_name then
ingredient.name = new_name
ingredient.amount = math.ceil(
(ingredient.amount or ingredient[2] or 1)
* amount_mult
)
ingredient[2] = nil
end
if ingredient[1] == old_name then
ingredient[1] = new_name
ingredient[2] = math.ceil(
(ingredient[2] or ingredient.amount or 1)
* amount_mult
)
ingredient.amount = nil
end
if ingredient.name == nil
and ingredient[1] == nil then
ingredient = nil
end
end
end
if recipe.expensive then
for _,ingredient
in pairs(recipe.expensive.ingredients or {}) do
if ingredient.name == old_name then
ingredient.name = new_name
ingredient.amount = math.ceil(
(ingredient.amount or ingredient[2] or 1)
* amount_mult
)
ingredient[2] = nil
end
if ingredient[1] == old_name then
ingredient[1] = new_name
ingredient[2] = math.ceil(
(ingredient[2] or ingredient.amount or 1)
* amount_mult
)
ingredient.amount = nil
end
if ingredient.name == nil
and ingredient[1] == nil then
ingredient = nil
end
end
end
for _,result in pairs(recipe.results or {}) do
if result.name == old_name then
result.name = new_name
result.amount = math.floor(
(result.amount or result[2] or 1)
* amount_mult
)
end
if result[1] == old_name then
result[1] = new_name
result[2] = math.floor(
(result[2] or result.amount or 1)
* amount_mult
)
result.amount = nil
end
if result.name == nil
and result[1] == nil then
result = nil
end
end
if recipe.normal then
for _,result in pairs(recipe.normal.results or {}) do
if result.name == old_name then
result.name = new_name
result.amount = math.floor(
(result.amount or result[2] or 1)
* amount_mult
)
end
if result[1] == old_name then
result[1] = new_name
result[2] = math.floor(
(result[2] or result.amount or 1)
* amount_mult
)
result.amount = nil
end
if result.name == nil
and result[1] == nil then
result = nil
end
end
end
if recipe.expensive then
for _,result
in pairs(recipe.expensive.results or {}) do
if result.name == old_name then
result.name = new_name
result.amount = math.floor(
(result.amount or result[2] or 1)
* amount_mult
)
end
if result[1] == old_name then
result[1] = new_name
result[2] = math.floor(
(result[2] or result.amount or 1)
* amount_mult
)
result.amount = nil
end
if result.name == nil
and result[1] == nil then
result = nil
end
end
end
end
Code: Select all
if data.raw.recipe["other-mod-asphalt"] then
replace_in_recipe_io(data.raw.recipe["other-mod-asphalt"],"other-mod-asphalt-item","bitumen-asphalt",0.5)
end
Code: Select all
if data.raw.item["other-mod-asphalt-precusor-item"] then
replace_in_recipe_io(data.raw.recipe["bitumen-asphalt"],"bitumen-asphalt-precursor-item","other-mod-asphalt-precursor-item")
end
Code: Select all
if mods["angelspetrochem"] then -- detected angels petrochem
update_recipes("my-ethylene", "angles-ethylene")
end
Create a file called utils.lua with contents somthing like this
code:
local Util = {}
function Util.update_recipes(original_item, replacement_item)
-- code
end
return Util
Then in your data-updates.lua
[3:28 PM]
local Util = require("utils")
data.raw.recipe["ethylene-dl"].results[2].name = "angles-ethylene-gas"
data.raw.recipe["ethylene-dl"].main_product = "angles-ethylene-gas"