Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- data-updates.lua.orig
- +++ data-updates.lua
- @@ -1,17 +1,30 @@
- +local RECYCLING_FRACTION = 0.25 -- Fixed recycling return rate from Factorio (hardcoded in game data)
- +
- local function replace_ingredient(ingredients, old_ingredient, new_ingredient, new_amount)
- - for i,ingredient in pairs(ingredients) do
- + -- Loop through the list of ingredients/results
- + for i, ingredient in pairs(ingredients) do
- if ingredient.name then
- + -- Full format: {type=..., name=..., amount=...}
- if ingredient.name == old_ingredient then
- ingredient.name = new_ingredient
- - ingredient.amount = new_amount
- + if new_amount then -- Set only if provided (for compatibility)
- + ingredient.amount = new_amount
- + end
- end
- elseif ingredient[1] == old_ingredient then
- + -- Short format: {"name", amount}
- ingredient[1] = new_ingredient
- + if new_amount then
- + ingredient[2] = new_amount
- + end
- end
- end
- end
- local function update_recipe(recipe, old_ingredient, new_ingredient, new_amount)
- + -- Replace in the main crafting recipe (unchanged)
- if data.raw.recipe[recipe].ingredients then
- replace_ingredient(data.raw.recipe[recipe].ingredients, old_ingredient, new_ingredient, new_amount)
- end
- @@ -21,4 +34,14 @@
- if data.raw.recipe[recipe].expensive then
- replace_ingredient(data.raw.recipe[recipe].expensive.ingredients, old_ingredient, new_ingredient, new_amount)
- end
- +
- + -- Handle the recycling recipe
- + local recycling_name = recipe .. "-recycling"
- + local recycling_recipe = data.raw.recipe[recycling_name]
- + if recycling_recipe and recycling_recipe.results then
- + -- Replace in results with 25% of new_amount (floored)
- + replace_ingredient(recycling_recipe.results, old_ingredient, new_ingredient, (new_amount * RECYCLING_FRACTION))
- + end
- + -- No need for normal/expensive checks — recycling recipes don't have them
- end
Advertisement
Add Comment
Please, Sign In to add comment