How do i make a recipe use a fluid/output a fluid?

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
Techfish3000
Burner Inserter
Burner Inserter
Posts: 14
Joined: Fri Mar 29, 2019 9:11 am
Contact:

How do i make a recipe use a fluid/output a fluid?

Post by Techfish3000 »

Just wondering if it is just as easy as something like this

Code: Select all

concreterecipe = {

type = "recipe",
name = "water-sediment",
ingredients =
   {
    {"water", 50}
   },
result = {"refined-concrete", 10}
energy_required = 5
}
or if it needs something extra.
thanks in advance!
Hey, I exist. Sometimes.

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

Re: How do i make a recipe use a fluid/output a fluid?

Post by bobingabout »

there are 2 methods for defining ingredients in a recipe.
the first one is the short method, which you've used there.

Code: Select all

{"item-name", amount}
however, as you can see, it wants an ITEM name, fluids aren't items.
There's a longer method as follows

Code: Select all

{type = "item", name = "item-name", amount = amount}
Type can be changed, your example would be:

Code: Select all

{type = "fluid", name = "water", amount = 50}
Ingredients, and results use the simple item type method, so the only valid types are item and fluid. so definitions such as type "tool" that you need to use to define items like science packs just come under the type "item" when used by a recipe.

Result (output) is different too. the result= tag is result="item-name", again, assumed item, also assumed amount is only 1. You can change the amount using result_count = 10 as an example, and then you'd get 10 of that item instead of just 1. so again, your example:

Code: Select all

result = "refined-concrete", 
result_count = 10,
however, this works for items, but not fluids. if you want a fluid, you'll need to use the complex results = tag instead.

Code: Select all

results =
{
  {type = "fluid", name = "crude-oil", amount = 50}
}
results can have additional entries on it, such as amount_min and amount_max, where a random amount between the 2 values is used. or probability = 0.5, the item will only appear 50% of the time.
you CAN use this method to define entries with more than 1 result, however, this will error. you need to define a few extra things like... icon, icon_size, order, etc, that you normally define on an item. you'll also need to define a locale entry for the recipe, as by default that too is taken from the item. when you use a single result, these are taken from the item definition.

I think if you can also use main_product = "item-name", then any of the mentioned data you require is taken from the item listed on this tag instead of having to be defined.
For more examples, take a look at the fluid-recipe.lua file in the base game, Oil processing uses this extended recipe system a lot.
Last edited by bobingabout on Thu Apr 04, 2019 8:19 am, edited 3 times in total.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: How do i make a recipe use a fluid/output a fluid?

Post by darkfrei »

But results is a table with array of tables:

Code: Select all

results = {
    {type = "fluid", name = "crude-oil", amount = 50}
  }
Or it can be used for items:

Code: Select all

results = {
    {type = "item", name = "refined-concrete", amount = 10}
  }
This format works, but makes crashing some mods:

Code: Select all

results = {
    {"refined-concrete", 10}
  }

Techfish3000
Burner Inserter
Burner Inserter
Posts: 14
Joined: Fri Mar 29, 2019 9:11 am
Contact:

Re: How do i make a recipe use a fluid/output a fluid?

Post by Techfish3000 »

darkfrei wrote:
Tue Apr 02, 2019 10:17 am

This format works, but makes crashing some mods:

Code: Select all

results = {
    {"refined-concrete", 10}
  }
That's what i used after a bit of messing around in the API. Will have to try the other methods as well!

Also, didn't expect the legendary bobingabout himself to reply, You make great mods!

Also Also, I have a work-in-progress mod called "BeltArmour" in the making, it will be my first published mod, maybe you can help me crash test it?

Also Also Also, the code I described is for another mod idea I had, but is kinda a scrapped idea. Thanks anyway!
Hey, I exist. Sometimes.

Post Reply

Return to “Modding discussion”