Optional mod requirements
- Ranakastrasz
- Smart Inserter
- Posts: 2173
- Joined: Thu Jun 12, 2014 3:05 am
- Contact:
Optional mod requirements
I've seen mods that can require other mods, and implement things, like recipes or techs differently depending on what mods are enabled. How is this done?
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Re: Optional mod requirements
This is done in the info.json
example
From: https://forums.factorio.com/wiki/index.ph ... nformation
example
Code: Select all
{
"name": "foo-mod",
"version": "0.1.0",
"title": "Foo Mod",
"author": "Factorio team",
"contact": "dev@factorio.com",
"homepage": "http://factorio.com",
"description": "Basic mod with all the default game data and standard campaign.",
"dependencies": ["base >= 0.4.1", "scenario-pack", "? bar = 0.3"]
}
- Ranakastrasz
- Smart Inserter
- Posts: 2173
- Joined: Thu Jun 12, 2014 3:05 am
- Contact:
Re: Optional mod requirements
Ok. That covers half of it. How do I set different recipes depending on those criteria?
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Re: Optional mod requirements
That depends on the mod you are looking for.Ranakastrasz wrote:Ok. That covers half of it. How do I set different recipes depending on those criteria?
I'd recommend looking at bob's mods and his config mod integration in other mods.
- Arch666Angel
- Smart Inserter
- Posts: 1636
- Joined: Sun Oct 18, 2015 11:52 am
- Contact:
Re: Optional mod requirements
It depends if you are doing several mods and want to link them, then go with what orzelek said, cause bob did a really good Job and with some longer staring his methods are really good.
Otherwise it depends, first you have to find something unique withhin the other mod you want to detect, for example an entity or item and then run a check for it. But that can be more complicated than it sounds, depending on where the entity is defined and where you want to check for it.
Otherwise it depends, first you have to find something unique withhin the other mod you want to detect, for example an entity or item and then run a check for it. But that can be more complicated than it sounds, depending on where the entity is defined and where you want to check for it.
Angels Mods
I. Angel's Mods Subforum
II. Development and Discussion
III. Bugs & FAQ
"should be fixed"
I. Angel's Mods Subforum
II. Development and Discussion
III. Bugs & FAQ
"should be fixed"
-
- Filter Inserter
- Posts: 841
- Joined: Mon Sep 14, 2015 7:40 am
- Contact:
Re: Optional mod requirements
Generally speaking, after adding the optional dependency in info.json, you'll want to run an if check to test if a certain item/entity/tech/etc. from the other mod exists, and if it does, then adjust your mod accordingly.
From my Satellite Uplink Station, a data.lua example:
Here (although I don't remember why) I even had the test based off the existence of one item from bob's electronics but changed the recipe to use a different item. The "enableBobUpdates" is just a config.lua variable that can be manually set to true or false.
Similar tests exist for control.lua, where you don't use data.raw but rather:
From my Satellite Uplink Station, a data.lua example:
Code: Select all
if data.raw["item"]["gilded-copper-cable"] and enableBobUpdates then
data.raw["recipe"]["uplink-station"].ingredients[5] = {"insulated-cable", 100}
end
Similar tests exist for control.lua, where you don't use data.raw but rather:
Code: Select all
if game.item_prototypes["upgrade-planner"] then
player.insert({name="upgrade-planner", count=1})
end
Re: Optional mod requirements
Note that you chekc with the data.lua, but if your mod loads first, then that item might not be loaded into the data yet, and thus it works too to use a data-updates.lua, which is only loaded after all the other mods data.lua files.
-
- Filter Inserter
- Posts: 841
- Joined: Mon Sep 14, 2015 7:40 am
- Contact:
Re: Optional mod requirements
I thought that was the entire purpose of the optional dependency, to ensure that the mod you declared in info.json to look out for is loaded before yours.Klonan wrote:Note that you chekc with the data.lua, but if your mod loads first, then that item might not be loaded into the data yet, and thus it works too to use a data-updates.lua, which is only loaded after all the other mods data.lua files.
Re: Optional mod requirements
Oh yea that might be right...Supercheese wrote:I thought that was the entire purpose of the optional dependency, to ensure that the mod you declared in info.json to look out for is loaded before yours.Klonan wrote:Note that you chekc with the data.lua, but if your mod loads first, then that item might not be loaded into the data yet, and thus it works too to use a data-updates.lua, which is only loaded after all the other mods data.lua files.
- Ranakastrasz
- Smart Inserter
- Posts: 2173
- Joined: Thu Jun 12, 2014 3:05 am
- Contact:
Re: Optional mod requirements
I can't figure out how to get this data in my control file. data doesn't exist apperently. (Presumably because data.raw only exists when game is first loading)
game doesn't exist for some reason, even though It only runs when I start a game.
Any suggestions on what else I might try?
game doesn't exist for some reason, even though It only runs when I start a game.
Any suggestions on what else I might try?
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
- Ranakastrasz
- Smart Inserter
- Posts: 2173
- Joined: Thu Jun 12, 2014 3:05 am
- Contact:
Re: Optional mod requirements
Got it to work. Thanks.
Still really awkward... Why can't you just validate mods like the dependency part?
Still really awkward... Why can't you just validate mods like the dependency part?
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16