Auto-generate barrel recipes for existing savefiles

Place to get help with not working mods / modding interface.
territrades
Burner Inserter
Burner Inserter
Posts: 11
Joined: Sat Jul 20, 2024 2:08 pm
Contact:

Auto-generate barrel recipes for existing savefiles

Post by territrades »

Hi,

I work on a mod that adds a bunch of fluids. When I start a new game with the my mod active, the game automatically generates barrel filling and emptying recipes for each of my fluids correctly (this is defined in __base__/data-updates.lua). Everything works as intended.

However, when I load an existing save file with my mod, those barreling recipes are not generated. The rest of the mod is there, just the barreling recipes are missing. And without them the mod is barely playable to be honest.

I already tried

Code: Select all

/c game.player.force.reset_recipes()
but that did nothing for me. Any ideas?
Bilka
Factorio Staff
Factorio Staff
Posts: 3309
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Auto-generate barrel recipes for existing savefiles

Post by Bilka »

The standard way would be to write a Lua migration that checks whether the fluid-processing technology is unlocked and then unlocks the specific recipes. See https://lua-api.factorio.com/latest/aux ... migrations for an example.

Or the lazy way that may break other mods:

Code: Select all

/c game.player.force.reset_technology_effects()
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
territrades
Burner Inserter
Burner Inserter
Posts: 11
Joined: Sat Jul 20, 2024 2:08 pm
Contact:

Re: Auto-generate barrel recipes for existing savefiles

Post by territrades »

Hi Bilka,

thanks for your reply. I have now figured it out :D

Just to document my findings here: For every fluid in the game, the barreling recipes are added to the 'fluid-handling' research. So in the migration script one needs to check for this technology and then enable the barreling recipes manually. For that one needs to know how the automatic names are formed, which I found in the data.raw.

Since I need a manual way anyway, I decided to make an additional technology. Just that the player is not bombarded with a bunch of fluids he will not use for many hours.

Here is a fluid I define:

Code: Select all

local nitrogen = {
	name = "mfa-nitrogen",
	type = "fluid",

	icon = "__fluid-test-mod__/graphics/icons/drop_N2.png",
	icon_size = 64, icon_mipmaps = 4,

	default_temperature = 20,

	base_color = {r = 1, g = 1, b = 1},
	flow_color = {r = 1, g = 1, b = 1},
}
then I make a technology that unlocks the corresponding barreling recipes:

Code: Select all

  {
    type = "technology",
    name = "dummy",
    icon_size = 256, icon_mipmaps = 4,
    icon = "__base__/graphics/technology/fluid-handling.png",
    prerequisites = {"automation-2", "engine"},
    effects =
    {
      {
        type = "unlock-recipe",
        recipe = "empty-mfa-nitrogen-barrel"
      },
      {
        type = "unlock-recipe",
        recipe = "fill-mfa-nitrogen-barrel"
      },
    },
    unit =
    {
      count = 50,
      ingredients = {{"automation-science-pack", 1}, {"logistic-science-pack", 1}},
      time = 15
    },
    order = "d-a-a"
  },
The fill-NAME-barrel and empty-NAME-barrel recipes are auto-generated by the game.
Post Reply

Return to “Modding help”