Need some advice/tips for making my first mod

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

Need some advice/tips for making my first mod

Post by Alphys_Hedge »

I'm making a battery mod as my first mod, just to get used to modding. I want entities that use electricity (such as electric mining drills) to be able use batteries, like burner items use fuel/coal/wood. The general idea is to have a 1x1 machine that you put batteries in which would have tiers like assembling machines, like a Power Generator/Supplier (haven't decided on the name yet) 1 which would have 2 battery slots, 2 which would have 4, and 3 which would have 6 battery slots. You would then connect copper wire to the generator, and then to a pole to supply it with electricity, which you would then place an electric object within range of the pole. So basically, an alternative to steam/solar electricity. There would be different tiers of batteries measured in watts, such as a 50 kW battery, 75 kW battery, 100 kW, 200 kW, and so on, with the top tier likely being 500 kW.

The only problem with it is that I have no clue how I would make the generator entity or make it generate electricity. Can anyone help me with making something like this? I can provide extra info if needed.
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3749
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Need some advice/tips for making my first mod

Post by DaveMcW »

Custom power sources are complicated. There is no simple way to define them, you need to do most of the work in a Lua script.

data.lua:
Define 2 entities. One with type="accumulator", one with type="container".

control.lua:
on_built_entity, on_robot_built_entity: If the item is your custom accumulator, create your custom container too.
on_tick: Read the contents of the container, destroy any batteries you find, and increase the energy level of the accumulator.
Rseding91
Factorio Staff
Factorio Staff
Posts: 15883
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Need some advice/tips for making my first mod

Post by Rseding91 »

The "electric-energy-interface" type entity can produce or consume power at demand with any of it's energy properties being adjustable runtime through the Lua API: http://lua-api.factorio.com/latest/LuaE ... production
If you want to get ahold of me I'm almost always on Discord.
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Need some advice/tips for making my first mod

Post by Adil »

Rseding91 wrote:The "electric-energy-interface" type entity can produce or consume power at demand with any of it's energy properties being adjustable runtime through the Lua API: http://lua-api.factorio.com/latest/LuaE ... production
So, where's any documentation on that type? Which fields are required in prototypes and such.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5405
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Need some advice/tips for making my first mod

Post by Klonan »

Adil wrote:
Rseding91 wrote:The "electric-energy-interface" type entity can produce or consume power at demand with any of it's energy properties being adjustable runtime through the Lua API: http://lua-api.factorio.com/latest/LuaE ... production
So, where's any documentation on that type? Which fields are required in prototypes and such.
Theres an electric-energy-interface defined in the base mod, and the api for it is in LuaEntity
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Need some advice/tips for making my first mod

Post by Adil »

Oh, okay, I did search wrong name first.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
Alphys_Hedge
Burner Inserter
Burner Inserter
Posts: 16
Joined: Mon Jan 02, 2017 12:09 pm
Contact:

Re: Need some advice/tips for making my first mod

Post by Alphys_Hedge »

Rseding91 wrote:The "electric-energy-interface" type entity can produce or consume power at demand with any of it's energy properties being adjustable runtime through the Lua API: http://lua-api.factorio.com/latest/LuaE ... production
Thanks for the link! I'm understanding it a bit better now, thankfully. To add the slots, would I have to look at code for, say, a furnace, and then base it off of that (combined with the accumulator code)?
Alphys_Hedge
Burner Inserter
Burner Inserter
Posts: 16
Joined: Mon Jan 02, 2017 12:09 pm
Contact:

Re: Need some advice/tips for making my first mod

Post by Alphys_Hedge »

DaveMcW wrote:Custom power sources are complicated. There is no simple way to define them, you need to do most of the work in a Lua script.

data.lua:
Define 2 entities. One with type="accumulator", one with type="container".

control.lua:
on_built_entity, on_robot_built_entity: If the item is your custom accumulator, create your custom container too.
on_tick: Read the contents of the container, destroy any batteries you find, and increase the energy level of the accumulator.
I hope you don't mind me asking, but could you explain this a bit more? I'm not sure how to define entities inside of the data.lua, so far it just has the require functions in it.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Need some advice/tips for making my first mod

Post by aubergine18 »

Look at any of the mods in the portal - most define entities (often they will have several files in a /prototypes folder, and then the data.lua includes those files). You will often need recipes and items as well.

Also, it's worth reading this to get an idea of how everything fits together: http://lua-api.factorio.com/latest/Data-Lifecycle.html
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Post Reply

Return to “Modding help”