Page 1 of 1
Replace liquid with solid in recipe dynamic. (Resolved)
Posted: Sat Jul 02, 2016 5:15 pm
by Ranakastrasz
I want to loop through all recipes and replace lubricant with an item equivalent. How can I remove the liquid type entry and crafting category?
Needs to support mods, so I can't just overwrite them all manually.
Re: Replace liquid with solid in recipe dynamic.
Posted: Sun Jul 03, 2016 8:32 pm
by DRY411S
You cannot do this dynamically. Recipes are read-only after the data stage in a mod.
Re: Replace liquid with solid in recipe dynamic.
Posted: Sun Jul 03, 2016 9:39 pm
by Ranakastrasz
I meant something more like this
Code: Select all
for name, capsule in pairs(data.raw.capsule) do
if capsule.capsule_action.attack_parameters then
data:extend({
{
type = "recipe",
name = "dispensable-" .. capsule.name,
enabled = false,
category = "advanced-crafting",
ingredients = {{capsule.name,1}},
result = "dispensable-" .. capsule.name,
},
})
end
end
From Combat Variations.
Instead, find all recipes with Liquid lubricant in them, replace it with solid lubricant item, and make it a normal recipe if it no longer uses liquid.
Re: Replace liquid with solid in recipe dynamic.
Posted: Sun Jul 03, 2016 10:37 pm
by DRY411S
That code is creating new recipes. You sound as though you need to change existing ones.
You need something like this
(UNTESTED):
Code: Select all
for name,recipe in pairs(data.raw.recipe) do
for k, v in pairs(recipe.ingredients) do
-- Examples of different ingredient formats
-- {"engine-unit", 1},
-- {type="fluid", name= "lubricant", amount = 2},
-- bobs-mod replacements are like
-- {amount = 3, name = "basic-circuit-board", type = "item" }
-- YOU CODE here to test for lubricant and change it something else
end
end
Re: Replace liquid with solid in recipe dynamic.
Posted: Sun Jul 03, 2016 10:50 pm
by Ranakastrasz
DRY411S wrote:That code is creating new recipes. You sound as though you need to change existing ones.
You need something like this
(UNTESTED):
Code: Select all
for name,recipe in pairs(data.raw.recipe) do
for k, v in pairs(recipe.ingredients) do
-- Examples of different ingredient formats
-- {"engine-unit", 1},
-- {type="fluid", name= "lubricant", amount = 2},
-- bobs-mod replacements are like
-- {amount = 3, name = "basic-circuit-board", type = "item" }
-- YOU CODE here to test for lubricant and change it something else
end
end
Yes, like that. That was just the closest example that I could find at the time.
Main issue was that I couldn't figure out how to remove the type="fluid"
Apperently however, you can set that to "item", and it works fine.
Code: Select all
function round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
function process(recipe)
for _, ingredient in pairs (recipe.ingredients) do
if ingredient.type == "fluid" then
if ingredient.name == "lubricant" then
ingredient.type = "item"
ingredient.name = "solid-lubricant"
ingredient.amount = round(ingredient.amount * 2.0)
end
end
end
end
for i, recipe in pairs (data.raw["recipe"]) do
if (recipe.category == nil) or (recipe.category == "crafting-with-fluid") then
process(recipe)
end
end
Works so far as I can tell.
Re: Replace liquid with solid in recipe dynamic. (Resolved)
Posted: Tue Jul 05, 2016 9:08 am
by bobingabout
If you don't mind using my library mod (or look at it to see how I did it in the library)
https://mods.factorio.com/mods/Bobingabout/boblibrary
Code: Select all
bobmods.lib.recipe.replace_ingredient_in_all(old, new)
in this case, old is "lubricant", and new is, whatever you want. EG
Code: Select all
bobmods.lib.recipe.replace_ingredient_in_all("lubricant", "coal")
It does not take the crafting category into account though, but since it's fluid to solid, shouldn't be a problem.
though, amount will likely be an issue