Copying the ingredients from another recipe

Place to get help with not working mods / modding interface.
Post Reply
User avatar
DellAquila
Inserter
Inserter
Posts: 48
Joined: Fri Mar 16, 2018 2:54 pm
Contact:

Copying the ingredients from another recipe

Post by DellAquila »

Sorry to bother, I'm trying to copy a recipe with more "amounts" of the ingredients than the original, but I can't.

Can you help me?


Im copying the smelting recipes, that only has 1 ingredient.

Code: Select all

data:extend({
  {
    type = "recipe",
    name = "big-"..recipe.name,
    category = "big-smelting",
    energy_required = recipe.energy_required,
    ingredients = {{recipe.ingredients["name"],recipe.ingredients["amount"]*50}},
    result	= recipe.result,
    result_count = recipe.result_count*50
  }
  
THANKS!

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Copying the ingredients from another recipe

Post by DaveMcW »

There are 2 different ingredient formats. If you are copying unknown recipes, you will have to support both.

https://wiki.factorio.com/Types/ItemIngredientPrototype

Bilka
Factorio Staff
Factorio Staff
Posts: 3139
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Copying the ingredients from another recipe

Post by Bilka »

DaveMcW wrote:
Tue Sep 24, 2019 6:04 pm
There are 2 different ingredient formats. If you are copying unknown recipes, you will have to support both.

https://wiki.factorio.com/Types/ItemIngredientPrototype
And difficulties are a thing. And the results/result/result_count also have different formats.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Copying the ingredients from another recipe

Post by eradicator »

And recipe.ingredients is an array of ingredients, so it does not have "name" or "amount" keys and there's no one-line solution to multiplying the amount on every ingredient like that. It'll need a function.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
DellAquila
Inserter
Inserter
Posts: 48
Joined: Fri Mar 16, 2018 2:54 pm
Contact:

Re: Copying the ingredients from another recipe

Post by DellAquila »

eradicator, even if the recipe has only one item i have to do build a function?

im only copying the smelting recipes with one ingredient.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Copying the ingredients from another recipe

Post by eradicator »

DellAquila wrote:
Tue Sep 24, 2019 6:23 pm
im only copying the smelting recipes with one ingredient.
How do you know that the recipe has only one ingredient? And even if you know that still leaves two possible ingredient formats and 3 possible difficulty nodes. Recipe parsing is a top candidate for the "wheel most often reinvented"-award.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
DellAquila
Inserter
Inserter
Posts: 48
Joined: Fri Mar 16, 2018 2:54 pm
Contact:

Re: Copying the ingredients from another recipe

Post by DellAquila »

Like Bilka, DaveMcW said about the recipes strings, i created this code with only smeting recipes, that i believe always only has 1 item as ingredient... (maybe im wrong)

But didnt work. I think the way i'm describing each ingredient is wrong.

Code: Select all

local function createbig(name, recipe)
  
 if recipe.category == "smelting" then
 
 if recipe.normal then
 
 if recipe.normal.result_count == nil then
  
    data:extend({
    {
    type = "recipe",
    name = "big-"..recipe.name,
    category = "big-smelting",
    normal =
    {
      enabled = true,
      energy_required = recipe.normal.energy_required,
      ingredients = {{type="item",
	  name=recipe.normal.ingredients[0]["name"],
	  amount=recipe.normal.ingredients[0]["amount"]}},
      result = recipe.normal.result,
	  result_count = 50
    },
    expensive =
    {
      enabled = true,
      energy_required = recipe.expensive.energy_required,
      ingredients = {{type="item",
	  name=recipe.expensive.ingredients[0]["name"],
	  amount=recipe.expensive.ingredients[0]["amount"]}},
      result = recipe.expensive.result,
	  result_count = 50
    }}})
	
		
table.insert(data.raw["module"]["productivity-module"].limitation, "big-"..recipe.name)
table.insert(data.raw["module"]["productivity-module-2"].limitation, "big-"..recipe.name)
table.insert(data.raw["module"]["productivity-module-3"].limitation, "big-"..recipe.name)
  

  else

    data:extend({
  {
    type = "recipe",
    name = "big-"..recipe.name,
    category = "big-smelting",
    normal =
    {
      enabled = true,
      energy_required = recipe.normal.energy_required,
      ingredients = {{type="item",
	  name=recipe.normal.ingredients[0]["name"],
	  amount=recipe.normal.ingredients[0]["amount"]}},
      result = recipe.normal.result,
	  result_count = recipe.normal.result_count*50
    },
    expensive =
    {
      enabled = true,
      energy_required = recipe.expensive.energy_required,
      ingredients = {{type="item",
	  name=recipe.expensive.ingredients[0]["name"],
	  amount=recipe.expensive.ingredients[0]["amount"]}},
      result = recipe.expensive.result,
	  result_count = recipe.expensive.result_count*50
    }}})
		
	
table.insert(data.raw["module"]["productivity-module"].limitation, "big-"..recipe.name)
table.insert(data.raw["module"]["productivity-module-2"].limitation, "big-"..recipe.name)
table.insert(data.raw["module"]["productivity-module-3"].limitation, "big-"..recipe.name)

end  
else
  
if recipe.result_count == nil then
  
  
  data:extend({
  {
    type = "recipe",
    name = "big-"..recipe.name,
    category = "big-smelting",
    energy_required = recipe.energy_required,
    ingredients = {{type="item",
	name=recipe.ingredients[0]["name"],
	amount=recipe.ingredients[0]["amount"]}},
    result	= recipe.result,
	result_count = 50
  }})

 
table.insert(data.raw["module"]["productivity-module"].limitation, "big-"..recipe.name)
table.insert(data.raw["module"]["productivity-module-2"].limitation, "big-"..recipe.name)
table.insert(data.raw["module"]["productivity-module-3"].limitation, "big-"..recipe.name)

else
  
  data:extend({
  {
    type = "recipe",
    name = "big-"..recipe.name,
    category = "big-smelting",
    energy_required = recipe.energy_required,
    ingredients = {{type="item",
	name=recipe.ingredients[0]["name"],
	amount=recipe.ingredients[0]["amount"]}},
    result	= recipe.result,
	result_count = recipe.result_count*50
  }})
  
   
  
table.insert(data.raw["module"]["productivity-module"].limitation, "big-"..recipe.name)
table.insert(data.raw["module"]["productivity-module-2"].limitation, "big-"..recipe.name)
table.insert(data.raw["module"]["productivity-module-3"].limitation, "big-"..recipe.name)
  
  end
  
  
  end
  end
  end

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Copying the ingredients from another recipe

Post by eradicator »

DellAquila wrote:
Tue Sep 24, 2019 6:56 pm
Like Bilka, DaveMcW said about the recipes strings, i created this code with only smeting recipes, that i believe always only has 1 item as ingredient... (maybe im wrong)
As far as i know "smelting" recipes can have any number ingredients, both item and fluid. But furnaces will ignore any recipe with more than one item (vague speculation). In any case you can just test "if #ingredients == 1" and ignore the recipe otherwise. Also lua table indexes start at [1] not [0].
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Adamo
Filter Inserter
Filter Inserter
Posts: 479
Joined: Sat May 24, 2014 7:00 am
Contact:

Re: Copying the ingredients from another recipe

Post by Adamo »

eradicator wrote:
Tue Sep 24, 2019 7:03 pm
As far as i know "smelting" recipes can have any number ingredients, both item and fluid. But furnaces will ignore any recipe with more than one item (vague speculation).
I have heavily tested this and can confirm this is correct. The game enforces this limitation by only allowing a furnace prototype to be loaded if it has input limitations on items and fluids set to 1 and requiring the limit to be set.

User avatar
DellAquila
Inserter
Inserter
Posts: 48
Joined: Fri Mar 16, 2018 2:54 pm
Contact:

Re: Copying the ingredients from another recipe

Post by DellAquila »

Now it worked!! Thank you all, very helpful! :D

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Copying the ingredients from another recipe

Post by eradicator »

Adamo wrote:
Tue Sep 24, 2019 7:17 pm
eradicator wrote:
Tue Sep 24, 2019 7:03 pm
As far as i know "smelting" recipes can have any number ingredients, both item and fluid. But furnaces will ignore any recipe with more than one item (vague speculation).
I have heavily tested this and can confirm this is correct. The game enforces this limitation by only allowing a furnace prototype to be loaded if it has input limitations on items and fluids set to 1 and requiring the limit to be set.
That is not what i said at all. I said that you can stuff all the shit you want into the "smelting" category, but any furnace prototype won't be able to use recipes with more than one item ingredient. Modded furnaces will however happily work with item+fluid recipes, see for example the "auto barreling" mod.

Code: Select all

table.insert(data.raw.recipe["iron-plate"].ingredients,{type='fluid',name = 'water',amount=1})
table.insert(data.raw.recipe["iron-plate"].ingredients,{type='fluid',name = 'crude-oil',amount=1})
table.insert(data.raw.recipe["iron-plate"].ingredients,{type='fluid',name = 'light-oil',amount=1})
table.insert(data.raw.recipe["iron-plate"].ingredients,{type='item',name = 'copper-plate',amount=1})
smelting.png
smelting.png (109.89 KiB) Viewed 2757 times
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Adamo
Filter Inserter
Filter Inserter
Posts: 479
Joined: Sat May 24, 2014 7:00 am
Contact:

Re: Copying the ingredients from another recipe

Post by Adamo »

eradicator wrote:
Tue Sep 24, 2019 8:19 pm
Adamo wrote:
Tue Sep 24, 2019 7:17 pm
eradicator wrote:
Tue Sep 24, 2019 7:03 pm
As far as i know "smelting" recipes can have any number ingredients, both item and fluid. But furnaces will ignore any recipe with more than one item (vague speculation).
I have heavily tested this and can confirm this is correct. The game enforces this limitation by only allowing a furnace prototype to be loaded if it has input limitations on items and fluids set to 1 and requiring the limit to be set.
That is not what i said at all. I said that you can stuff all the shit you want into the "smelting" category, but any furnace prototype won't be able to use recipes with more than one item ingredient. Modded furnaces will however happily work with item+fluid recipes, see for example the "auto barreling" mod.
I don't think you understood my response. I was explaining that you are correct that furnaces will "ignore" recipes with more than one item, and explained the way the game enforces this is by only allowing you to load furnace prototypes which limit the item and fluid inputs to 1 (That's 1 for each: 1 item and 1 fluid.). This is absolutely the situation, and any "modded furnace" you make would be forced to follow this. How do I know this? Because I have several furnace mods (Two are published.), some of which I attempted to extend beyond this and reigned in one step at a time until I found the outer bounds.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Copying the ingredients from another recipe

Post by eradicator »

Adamo wrote:
Tue Sep 24, 2019 8:56 pm
I don't think you understood my response.
I don't think you understood my response. :roll:
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to “Modding help”