Page 1 of 1

Move a recipe to a different technology

Posted: Wed Apr 11, 2018 3:29 am
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

Re: Move a recipe to a different technology

Posted: Wed Apr 11, 2018 7:52 am
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.

Re: Move a recipe to a different technology

Posted: Thu Apr 12, 2018 1:31 am
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.

Re: Move a recipe to a different technology

Posted: Fri Apr 13, 2018 2:24 am
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.

Re: Move a recipe to a different technology

Posted: Fri Apr 13, 2018 7:08 am
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.