Page 1 of 1

Requiring items/fluid from another mod?

Posted: Mon Jan 23, 2017 4:32 am
by Alphys_Hedge
I wanted to make a simple mod that would add glass, and then another mod that would add beakers, so that beakers would be used in science packs. I'm making it just so I can kind of get used to making mods.

I decided I would use the silicone and oxygen items from the Bob's Intermediates mod so it would be a bit more interesting making it instead of just adding sand to the game. However, I don't know how to go about requiring (or using, for that matter) those items for my mod.

What I want to do is have 2 Oxygen + 1 Silicon plate = 5 Glass plates, and then 5 Glass plates = 1 Beaker. It would replace the original science pack recipes, the items would mostly be the same, but a beaker would be added to all of them. Of course, this means an item would have to be removed from the science pack 3 recipe.

Does anyone know how to do this? I can give more info if needed.

Re: Requiring items/fluid from another mod?

Posted: Mon Jan 23, 2017 5:49 am
by steinio
Bob"s has glas already implemented.

Re: Requiring items/fluid from another mod?

Posted: Mon Jan 23, 2017 7:35 am
by Alphys_Hedge
steinio wrote:Bob"s has glas already implemented.
Even so, I want still to make beakers, so I'd still like to know if there's a way to use items from other mods.

Re: Requiring items/fluid from another mod?

Posted: Mon Jan 23, 2017 9:41 am
by Optera
In info.json add the line

Code: Select all

"dependencies": ["RequiredMod >= 1.2.3"]
After that you can refer to any item in the mod as if it was in base mod.

Re: Requiring items/fluid from another mod?

Posted: Mon Jan 23, 2017 8:02 pm
by Alphys_Hedge
Optera wrote:In info.json add the line

Code: Select all

"dependencies": ["RequiredMod >= 1.2.3"]
After that you can refer to any item in the mod as if it was in base mod.
I've put this in the info.json, so it looks like this now:

Code: Select all

{
"name": "BeakerMod",
"version": "0.1.0",
"factorio_version" : "0.14",
"title": "Beaker Mod",
"author": "Alphys_Hedge",
"contact": "",
"homepage": "",
"description": "Simply adds a beaker to factorio, which is used in science packs. Also removes advanced circuits from Science Pack 3 production."
"dependencies": ["bobplates >= 0.14.0"]
}
However, when I start factorio I get this error message:
Image

I'm not sure what could be causing this, since I pasted exactly what you said (with RequiredMod replaced with bobplates, of course). Do you know what could be causing this?

EDIT: Turns out it was just a comma after the description. Thank you for helping me, by the way! :D

Re: Requiring items/fluid from another mod?

Posted: Tue Jan 24, 2017 8:09 am
by bobingabout
Yeah. A dependancy will not only require the mod to be installed, but force it to load first so you can access things defined in that mod's data files.

if you put a ? in front of the name, it means it's optional, it isn't needed, but if it's there it loads before your mod.

You can then do checks to see if an item exists, and do a thing if it does, for example:

Code: Select all

if data.raw.item["glass"] then
table.insert(data.raw.recipe["beaker"].ingredient, {"glass", 1})
else
table.insert(data.raw.recipe["beaker"].ingredient, {"plastic-bar", 1})
end
if glass exists, add it as an ingredient to beaker, otherwise add plasic bar instead.

I use this sort of thing quite a lot in my mods, to make them modular, except I do it a bit differently now. I add the "else" stage first, then if the checked item exists, replace the old item with the new one. However, it's a lot harder to actually do, so if you're just learning, this is a good place to start.

Also, this is all off the top of my head without looking anything up, so, if it doesn't work, blame me for that.