Move a recipe to a different technology

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
Neomore
Inserter
Inserter
Posts: 47
Joined: Sun Jun 21, 2015 5:42 pm
Contact:

Move a recipe to a different technology

Post by Neomore »

Good evening.

I'm currently making a mod that adds a modified roboport. I am wanting to tech this roboport behind the vanilla roboport, but I want the player to have to use this modified roboport before using the vanilla one.

In order to do that, I'm wanting to move the vanilla roboport to the logistics system, and then remove the recipe unlock from both Logistics and Construction robotics and add in the new recipe. Unfortunately, I can't figure out how to do this, and I can't seem to find any guide that illustrates a good way to do this.

Any help would be appreciated
Author of Advanced Factorio, a set of mods that add small bits of Advanced functionality to your gameplay

Check it out here: https://mods.factorio.com/user/neomore

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Move a recipe to a different technology

Post by bobingabout »

Well, adding to an existing technology is fairly easy.

this example is from my library, so has a fair bit of safety adding to it, to make sure other mods didn't outright delete the technology or something.
instead of technology, you'd use... "logistic-robots" or whatever your technology is, and likewise recipe would be "roboport".
The first few lines in this are just to make sure the recipe and technology exist, and if the technology doesn't have an effects table, add it, the final line (before the last end) is the one doing the actual job.

Code: Select all

  if data.raw.technology[technology] and data.raw.recipe[recipe] then
    if not data.raw.technology[technology].effects then
      data.raw.technology[technology].effects = {}
    end
    table.insert(data.raw.technology[technology].effects,{type = "unlock-recipe", recipe = recipe})
  end
To remove is a little harder, since you have to cycle through all the items in the list, then remove the right one.

Code: Select all

  if data.raw.technology[technology] and data.raw.technology[technology].effects then
    for i, effect in pairs(data.raw.technology[technology].effects) do
      if effect.type == "unlock-recipe" and effect.recipe == recipe then
        table.remove(data.raw.technology[technology].effects,i)
      end
    end
  end
again, since this is just from my library, the first line is checking to make sure that the technology exists, and that it has an effects table.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Neomore
Inserter
Inserter
Posts: 47
Joined: Sun Jun 21, 2015 5:42 pm
Contact:

Re: Move a recipe to a different technology

Post by Neomore »

bobingabout wrote:Well, adding to an existing technology is fairly easy.

this example is from my library, so has a fair bit of safety adding to it, to make sure other mods didn't outright delete the technology or something.
instead of technology, you'd use... "logistic-robots" or whatever your technology is, and likewise recipe would be "roboport".
The first few lines in this are just to make sure the recipe and technology exist, and if the technology doesn't have an effects table, add it, the final line (before the last end) is the one doing the actual job.

Code: Select all

  if data.raw.technology[technology] and data.raw.recipe[recipe] then
    if not data.raw.technology[technology].effects then
      data.raw.technology[technology].effects = {}
    end
    table.insert(data.raw.technology[technology].effects,{type = "unlock-recipe", recipe = recipe})
  end
To remove is a little harder, since you have to cycle through all the items in the list, then remove the right one.

Code: Select all

  if data.raw.technology[technology] and data.raw.technology[technology].effects then
    for i, effect in pairs(data.raw.technology[technology].effects) do
      if effect.type == "unlock-recipe" and effect.recipe == recipe then
        table.remove(data.raw.technology[technology].effects,i)
      end
    end
  end
again, since this is just from my library, the first line is checking to make sure that the technology exists, and that it has an effects table.
For whatever reason, I wasn't able to get this to work. I was able to get it to work by making your library a dependency and using

Code: Select all

 bobmods.lib.tech.remove_recipe_unlock 
Not sure why that works, and yet using just the small bit of code you provided from the library didn't.... :?

I'm still having issues with add_recipe_unlock, but i think that's on my code's end and not yours.
Author of Advanced Factorio, a set of mods that add small bits of Advanced functionality to your gameplay

Check it out here: https://mods.factorio.com/user/neomore

Neomore
Inserter
Inserter
Posts: 47
Joined: Sun Jun 21, 2015 5:42 pm
Contact:

Re: Move a recipe to a different technology

Post by Neomore »

I managed to get the everything working finally. however, I found another issue that needs a workaround.

Is there some way to reload recipes after the technology has already been completed. I know that "migrations" can do this, but as far as I am aware, migrations doesn't work when going from "no mod -> mod".

Also, I should mention that I am making this mod for 0.15 and then upgrading it to 0.16 afterward, since i forgot to post that initially.
Author of Advanced Factorio, a set of mods that add small bits of Advanced functionality to your gameplay

Check it out here: https://mods.factorio.com/user/neomore

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Move a recipe to a different technology

Post by darkfrei »

Neomore wrote:Is there some way to reload recipes after the technology has already been completed. I know that "migrations" can do this, but as far as I am aware, migrations doesn't work when going from "no mod -> mod".
We have on_configuration_changed http://lua-api.factorio.com/latest/LuaB ... on_changed and can be useful reset_recipes http://lua-api.factorio.com/latest/LuaF ... et_recipes

Also
force.reset_technologies()
Load the original versions of technologies from prototypes. Preserves research state of technologies.
force.reset_technology_effects()
Reapplies all possible research effects, including unlocked recipes. Any custom changes are lost. Preserves research state of technologies.

Post Reply

Return to “Modding discussion”