Page 1 of 1

How to add lubricant as a required liquid to function?

Posted: Thu Oct 27, 2016 3:58 pm
by StingerSharp
Hi. Today I decided to sit down and attempt to create my first moded item in factorio.
I want to create: Assembling machine 4

The idea is to create faster assembling machine that is even faster but requires lubricant piped in to it to function.
I am following the tutorial made by Klonan.tv Factorio - Basic Modding Tutorial
It is lacking few things that would help me complete my first mod.
How to make it that assembler would require electricity and lubricant to function?
Would it require to copy and rewrite all the recipes to make it run?
Or it is as easy as just adding additional "energy" source - lubricant?
And how to set the liquid consumed/time in manufacturing?

Or I will require to create a totally new branch that will require massive amount of scripting and I should drop the idea? :D

Links to forums posts and videos that could answer me are appreciated!

Thank you for helping out in advance!

Re: How to add lubricant as a required liquid to function?

Posted: Thu Oct 27, 2016 5:52 pm
by aubergine18
It's not possible to specify lubricant as an alternate or additional form of energy for assembling machines as far as I know.

You can, however, iterate all applicable recipes to:

* Add lubricant as a required ingredient
* Set which assembling machine they can be made in

Make sure you use a decent Lua editor - there's several listed here.

I'd suggest developing it in a few iterations:

1. First, add the new assembling machine and get it working with normal recipes, but with faster speed
2. Iterate recipes that will use the machine, and create new recipes that include lubricant as required ingredient.

All of this can be done from prototypes via data.lua.

There are several mods already that add additional assembling machines so step 1 should be relatively trivial. Examples:

* https://mods.factorio.com/mods/Klonan/R ... ng_Machine
* https://mods.factorio.com/mods/funnysun ... semblyZero

To create clones of recipes, it should only take a few lines of code. You'll need to iterate data.raw.recipe (here's a dump of what data.raw looks like, search the page for `type = "recipe"` to get to the relevant section).

Here's the iteration part of the code:

Code: Select all

local lubricant, recipe

lubricant = {
  type = "fluid",
  name = "lubricant",
  amount = 1 -- or however much is required
}

for recipe_name, settings in pairs( data.raw.recipe ) do
  -- this will go through each recipe in turn
  -- recipe_name = recipe name (string)
  -- settings = the table describing all aspects of the recipe

  -- make a copy of the recipe settings
  recipe = table.deepcopy( settings )

  -- give it a new name
  recipe.name = "lubricated-" .. recipe_name

  -- settings.ingredients is an array of the ingredients, so need to add lubricant
  -- note: some already have lubricant in them, I'll leave you to work out how to deal with that
  table.insert( settings.ingredients, lubricant )

  -- now set the category to force it to use the new assembling machine
  recipe.category = "crafting-with-lubricant"

  -- now add the new recipe to the game
  data:extend { recipe }

end
There's probably bugs in the above, but it should be enough to get you started.

You might want to change the recipe icon to include lubricant - an example of how to do that can probably be found in one or more of the following mods:

* https://mods.factorio.com/mods/GotLag/Omnibarrels
* https://mods.factorio.com/mods/jockeril/fluid-barrel
* https://mods.factorio.com/mods/amdewstow/barrels
* https://mods.factorio.com/mods/Delus/AllFluids

That should be enough to get you started :)

Re: How to add lubricant as a required liquid to function?

Posted: Thu Oct 27, 2016 8:42 pm
by StingerSharp
Thanks aubergine18 that gives me allot work with. :D