Replace liquid with solid in recipe dynamic. (Resolved)

Place to get help with not working mods / modding interface.
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Replace liquid with solid in recipe dynamic. (Resolved)

Post 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.
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
User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 736
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: Replace liquid with solid in recipe dynamic.

Post by DRY411S »

You cannot do this dynamically. Recipes are read-only after the data stage in a mod.
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Replace liquid with solid in recipe dynamic.

Post 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.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 736
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: Replace liquid with solid in recipe dynamic.

Post 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
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Replace liquid with solid in recipe dynamic.

Post 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.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Replace liquid with solid in recipe dynamic. (Resolved)

Post 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
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
Post Reply

Return to “Modding help”