[16]Two recipes for same item?

Place to get help with not working mods / modding interface.
Balthazar
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Dec 10, 2013 10:58 am
Contact:

[16]Two recipes for same item?

Post by Balthazar »

Trying to add a second recipe for electronic circuits that uses plastic instead of iron, but can't get it to work. I'm a modding n00b so its entirely possible i just messed up something simple, like directory structure, although the mod is available in the mod list and does not produce errors when loaded.

info.json:

Code: Select all

{
	"name": "plastronics",
	"version": "1.0",
	"title": "Plastronics",
	"author": "Raisinbat",	
	"factorio_version": "0.16",
	"description": "Adds a second recipe for making electronics with plastic instead of iron."
}
data.lua is empty, this could easily be the problem but from what i read its just for dependencies

in same folder is prototypes/recipes.lua:

Code: Select all

data:extend(
{
    {
    type = "recipe",
    name = "plastic-electronic-circuit",
    normal =
    {
      ingredients =
      {
        {"plastic-bar", 1},
        {"copper-cable", 3}
      },
      result = "electronic-circuit",
    },
    expensive =
    {
      ingredients =
      {
        {"plastic-bar", 2},
        {"copper-cable", 10}
      },
      result = "electronic-circuit",
    }
  }
 }
Thats everything i have so maybe something simple is just missing, or maybe its impossible to do, idk.
User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2529
Joined: Fri Nov 06, 2015 7:41 pm

Re: [16]Two recipes for same item?

Post by Deadlock989 »

Balthazar wrote: Mon Apr 22, 2019 12:52 pmdata.lua is empty, this could easily be the problem but from what i read its just for dependencies
No, data.lua, data-updates.lua and data-final-fixes.lua are automatically run by Factorio. Anything you put in a subfolder isn't automatically run. If you have any other Lua files you want executed in the data phase, they need to be called by one of those. Use require("prototypes.recipes") in data.lua to call your recipe prototype code.
Balthazar
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Dec 10, 2013 10:58 am
Contact:

Re: [16]Two recipes for same item?

Post by Balthazar »

Deadlock989 wrote: Mon Apr 22, 2019 12:54 pm
Balthazar wrote: Mon Apr 22, 2019 12:52 pmdata.lua is empty, this could easily be the problem but from what i read its just for dependencies
No, data.lua, data-updates.lua and data-final-fixes.lua are automatically run by Factorio. Anything you put in a subfolder isn't automatically run. If you have any other Lua files you want executed in the data phase, they need to be called by one of those. Use require("prototypes.recipes") in data.lua to call your recipe prototype code.
It's working now, thanks a ton man!
Balthazar
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Dec 10, 2013 10:58 am
Contact:

Re: [16]Two recipes for same item?

Post by Balthazar »

Didnt want to start a new topic but just realized the recipe is not compatible with productivity modules, how do i enable that?
User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2529
Joined: Fri Nov 06, 2015 7:41 pm

Re: [16]Two recipes for same item?

Post by Deadlock989 »

The productivity modules have a property called limitation which is a list of recipes that it is allowed to work with.

https://wiki.factorio.com/Prototype/Module#limitation

For example, here's prod module 2 from data.raw:

Code: Select all

["productivity-module-2"] = {
      category = "productivity",
      effect = {
        consumption = {
          bonus = 0.6
        },
        pollution = {
          bonus = 0.070000000000000009
        },
        productivity = {
          bonus = 0.06
        },
        speed = {
          bonus = -0.15
        }
      },
      icon = "__base__/graphics/icons/productivity-module-2.png",
      icon_size = 32,
      limitation = {
        "sulfuric-acid",
        "basic-oil-processing",
        "advanced-oil-processing",
        "coal-liquefaction",
        "heavy-oil-cracking",
        "light-oil-cracking",
        "solid-fuel-from-light-oil",
        "solid-fuel-from-heavy-oil",
        "solid-fuel-from-petroleum-gas",
        "lubricant",
        "iron-plate",
        "copper-plate",
        "steel-plate",
        "stone-brick",
        "sulfur",
        "plastic-bar",
        "empty-barrel",
        "uranium-processing",
        "copper-cable",
        "iron-stick",
        "iron-gear-wheel",
        "electronic-circuit",
        "advanced-circuit",
        "processing-unit",
        "engine-unit",
        "electric-engine-unit",
        "uranium-fuel-cell",
        "explosives",
        "battery",
        "flying-robot-frame",
        "low-density-structure",
        "rocket-fuel",
        "rocket-control-unit",
        "rocket-part",
        "automation-science-pack",
        "logistic-science-pack",
        "chemical-science-pack",
        "military-science-pack",
        "production-science-pack",
        "utility-science-pack",
        "kovarex-enrichment-process"
      },
      limitation_message_key = "production-module-usable-only-on-intermediates",
      localised_description = {
        "item-description.productivity-module"
      },
      name = "productivity-module-2",
      order = "c[productivity]-b[productivity-module-2]",
      stack_size = 50,
      subgroup = "module",
      tier = 2,
      type = "module"
    },
You have to append your recipe name to the list in all three modules, and any other modules that may randomly exist from any other mod that you have no way of knowing about. In vanilla, though, only productivity modules use limitation.
Balthazar
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Dec 10, 2013 10:58 am
Contact:

Re: [16]Two recipes for same item?

Post by Balthazar »

Thanks deadlock, is there by any chance a smarter way of doing this than editing data.raw?
slippycheeze
Filter Inserter
Filter Inserter
Posts: 587
Joined: Sun Jun 09, 2019 10:40 pm
Contact:

Re: [16]Two recipes for same item?

Post by slippycheeze »

Balthazar wrote: Fri Aug 23, 2019 7:36 pm Thanks deadlock, is there by any chance a smarter way of doing this than editing data.raw?
There is no way to do this other than *modifying* the prototypes during the data phase, no. That is how Factorio works.
User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2529
Joined: Fri Nov 06, 2015 7:41 pm

Re: [16]Two recipes for same item?

Post by Deadlock989 »

Balthazar wrote: Fri Aug 23, 2019 7:36 pm Thanks deadlock, is there by any chance a smarter way of doing this than editing data.raw?
No. Making changes to data.raw is literally what the entire data phase of modding is.

Limitations are read-only at runtime so you can't change them in the control phase.
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3729
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: [16]Two recipes for same item?

Post by DaveMcW »

Code: Select all

for _, module in pairs(data.raw.module) do
  if module.category == "productivity" then
    table.insert(module.limitation, "plastic-electronic-circuit")
  end
end
This should be done in data-updates.lua to be sure you catch all modded productivity modules.
Balthazar
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Dec 10, 2013 10:58 am
Contact:

Re: [16]Two recipes for same item?

Post by Balthazar »

Thanks a lot, its working now :)
Post Reply

Return to “Modding help”