Page 1 of 1

Copying the ingredients from another recipe

Posted: Tue Sep 24, 2019 5:49 pm
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!

Re: Copying the ingredients from another recipe

Posted: Tue Sep 24, 2019 6:04 pm
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

Re: Copying the ingredients from another recipe

Posted: Tue Sep 24, 2019 6:07 pm
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.

Re: Copying the ingredients from another recipe

Posted: Tue Sep 24, 2019 6:12 pm
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.

Re: Copying the ingredients from another recipe

Posted: Tue Sep 24, 2019 6:23 pm
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.

Re: Copying the ingredients from another recipe

Posted: Tue Sep 24, 2019 6:46 pm
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.

Re: Copying the ingredients from another recipe

Posted: Tue Sep 24, 2019 6:56 pm
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

Re: Copying the ingredients from another recipe

Posted: Tue Sep 24, 2019 7:03 pm
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].

Re: Copying the ingredients from another recipe

Posted: Tue Sep 24, 2019 7:17 pm
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.

Re: Copying the ingredients from another recipe

Posted: Tue Sep 24, 2019 8:08 pm
by DellAquila
Now it worked!! Thank you all, very helpful! :D

Re: Copying the ingredients from another recipe

Posted: Tue Sep 24, 2019 8:19 pm
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 3734 times

Re: Copying the ingredients from another recipe

Posted: Tue Sep 24, 2019 8:56 pm
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.

Re: Copying the ingredients from another recipe

Posted: Tue Sep 24, 2019 10:49 pm
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: