Requiring items/fluid from another mod?

Place to get help with not working mods / modding interface.
Post Reply
Alphys_Hedge
Burner Inserter
Burner Inserter
Posts: 16
Joined: Mon Jan 02, 2017 12:09 pm
Contact:

Requiring items/fluid from another mod?

Post 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.

User avatar
steinio
Smart Inserter
Smart Inserter
Posts: 2634
Joined: Sat Mar 12, 2016 4:19 pm
Contact:

Re: Requiring items/fluid from another mod?

Post by steinio »

Bob"s has glas already implemented.
Image

Transport Belt Repair Man

View unread Posts

Alphys_Hedge
Burner Inserter
Burner Inserter
Posts: 16
Joined: Mon Jan 02, 2017 12:09 pm
Contact:

Re: Requiring items/fluid from another mod?

Post 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.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2919
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: Requiring items/fluid from another mod?

Post 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.

Alphys_Hedge
Burner Inserter
Burner Inserter
Posts: 16
Joined: Mon Jan 02, 2017 12:09 pm
Contact:

Re: Requiring items/fluid from another mod?

Post 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

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Requiring items/fluid from another mod?

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Post Reply

Return to “Modding help”