Page 1 of 1
Need some advice/tips for making my first mod
Posted: Sun Jan 29, 2017 4:29 am
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.
Re: Need some advice/tips for making my first mod
Posted: Sun Jan 29, 2017 8:17 am
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.
Re: Need some advice/tips for making my first mod
Posted: Sun Jan 29, 2017 9:22 am
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
Re: Need some advice/tips for making my first mod
Posted: Sun Jan 29, 2017 2:25 pm
by Adil
So, where's any documentation on that type? Which fields are required in prototypes and such.
Re: Need some advice/tips for making my first mod
Posted: Sun Jan 29, 2017 2:29 pm
by Klonan
Adil wrote:
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
Re: Need some advice/tips for making my first mod
Posted: Sun Jan 29, 2017 5:11 pm
by Adil
Oh, okay, I did search wrong name first.
Re: Need some advice/tips for making my first mod
Posted: Sun Jan 29, 2017 11:38 pm
by Alphys_Hedge
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)?
Re: Need some advice/tips for making my first mod
Posted: Tue Jan 31, 2017 1:46 pm
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.
Re: Need some advice/tips for making my first mod
Posted: Wed Feb 01, 2017 11:56 pm
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