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.
Replace liquid with solid in recipe dynamic. (Resolved)
- Ranakastrasz
- Smart Inserter
- Posts: 2179
- Joined: Thu Jun 12, 2014 3:05 am
- Contact:
Replace liquid with solid in recipe dynamic. (Resolved)
Last edited by Ranakastrasz on Sun Jul 03, 2016 11:01 pm, edited 1 time in total.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Re: Replace liquid with solid in recipe dynamic.
You cannot do this dynamically. Recipes are read-only after the data stage in a mod.
- Ranakastrasz
- Smart Inserter
- Posts: 2179
- Joined: Thu Jun 12, 2014 3:05 am
- Contact:
Re: Replace liquid with solid in recipe dynamic.
I meant something more like this
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.
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
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.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Re: Replace liquid with solid in recipe dynamic.
That code is creating new recipes. You sound as though you need to change existing ones.
You need something like this (UNTESTED):
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
- Ranakastrasz
- Smart Inserter
- Posts: 2179
- Joined: Thu Jun 12, 2014 3:05 am
- Contact:
Re: Replace liquid with solid in recipe dynamic.
Yes, like that. That was just the closest example that I could find at the time.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
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
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: Replace liquid with solid in recipe dynamic. (Resolved)
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
in this case, old is "lubricant", and new is, whatever you want. EG
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
Code: Select all
bobmods.lib.recipe.replace_ingredient_in_all(old, new)
Code: Select all
bobmods.lib.recipe.replace_ingredient_in_all("lubricant", "coal")
though, amount will likely be an issue