Page 1 of 1

Get specific ingredient amount from a recipe

Posted: Fri Apr 13, 2018 1:21 pm
by kingarthur
is there anyway to get the amount value for a specific item from a recipes list of ingredients. what im trying to do is get the amount value for sulfuric acid in a list of recipes that have sulfuric acid as an ingredient so i can multiply that value by 3.

Code: Select all

if settings.startup["pymods-acid-increase"].value then

recipes = {'concrete-richclay'}

for i, recipename in ipairs(recipes) do
	
	Oldamount = data.raw["recipe"][recipename].ingredients["sulfuric-acid"]["amount"]
	
	OV.patch_recipes({
	{
	name = recipename, ingredients = 
		{
			{
			name = "sulfuric-acid", type = "fluid", amount = 150 <--this needs to be a variable
			--data.raw["recipe"][recipename].ingredients[1] = {"sulfuric-acid", 5 * 3}
			}
		}
	}
	
	})
	end
	
end
the for loop works when i set the amount by hand. i want to be able to get the old value multiply by 3 and set that as the amount.

Re: Get specific ingredient amount from a recipe

Posted: Fri Apr 13, 2018 6:18 pm
by darkfrei
You are need this function (not tested):

Code: Select all

function dif_recipe_handler (dif_recipe_prototype, item_name, factor)
  local ingredients = dif_recipe_prototype.ingredients
  for i, ingredient in pairs(ingredients) do
    if ingredient.name and ingredient.name == item_name and ingredient.type == 'item' and ingredient.count then
      ingredients[i].count = ingredient.count * factor
    end
    if ingredient[1] and ingredient[1] == item_name and ingredient[2] then
      ingredients[i][2] = ingredient[2] * factor
    end
  end
end
And you can call this function like there (not tested):

Code: Select all

local recipes_list = {'concrete-richclay'}
local items_list = {'sulfuric-acid'}
local factor = 3

for i, recipe_name in pairs (recipes_list) do
  if data.raw.recipe[recipe_name] then
    local recipe_prototype = data.raw.recipe[recipe_name]
    for j, item_name in pairs (items_list) do
      -- normal
      if recipe_prototype.normal and recipe_prototype.normal.ingredients then
        dif_recipe_handler (recipe_prototype.normal, item_name, factor)
      end
      -- expensive
      if recipe_prototype.expensive and recipe_prototype.expensive.ingredients then
        dif_recipe_handler (recipe_prototype.expensive, item_name, factor)
      end
      -- standard
      if recipe_prototype.ingredients then
        dif_recipe_handler (recipe_prototype, item_name, factor)
      end
    end
  end
end

Re: Get specific ingredient amount from a recipe

Posted: Sat Apr 14, 2018 6:19 am
by kingarthur
so i wasnt able to get all that to work. but i spent far longer than i proably should have working it over and got a working solution out of it.

Code: Select all

local OV = angelsmods.functions.OV

if settings.startup["pymods-acid-increase"].value then

local recipes_list = {'concrete-richclay','heavy-oleo','oleo-heavy','explosive-glycerol'}
local items_list = {'sulfuric-acid'}
local factor = 3

for i, recipe_name in ipairs(recipes_list) do
	
	local ingredients = data.raw.recipe[recipe_name].ingredients
	for k, ingredient in ipairs(ingredients) do
	for j, item_name in ipairs(items_list) do
	if ingredient.name == item_name then
	
	OV.patch_recipes({
	{
	name = recipe_name, ingredients = 
		{
			{
			name = "sulfuric-acid", type = "fluid", amount = ingredient.amount * factor
			--data.raw.recipe[recipe_name].ingredients[2].amount * factor
			
			}
		}
	}
	
	})
	end
	end
	end
	end
end

Re: Get specific ingredient amount from a recipe

Posted: Sat Apr 14, 2018 9:16 pm
by Arch666Angel
Depending on if you want it hardcoded or more dynamic, the recipe builder supports adding values to existing recipe ingredients:

Code: Select all

   OV.patch_recipes({
   {
   name = recipe_name, ingredients = 
      {
         {
         name = "sulfuric-acid", type = "fluid", amount = +value
         },
      }
   }
   })

Re: Get specific ingredient amount from a recipe

Posted: Sat Apr 14, 2018 10:52 pm
by kingarthur
Arch666Angel wrote:Depending on if you want it hardcoded or more dynamic, the recipe builder supports adding values to existing recipe ingredients:

Code: Select all

   OV.patch_recipes({
   {
   name = recipe_name, ingredients = 
      {
         {
         name = "sulfuric-acid", type = "fluid", amount = +value
         },
      }
   }
   })
ya i got that to work just fine and hard set a value. i could have just hardcoded it but i didnt want to have to figure out the values for the 1 or 2 dozen recipes i needed to adjust for even though im pretty sure i spent more time getting this to work then just doing that would have taken to just update pymods sulfuric acid amounts by hand