Guest User

Untitled

a guest
Aug 17th, 2025
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.08 KB | None | 0 0
  1. --- data-updates.lua.orig
  2. +++ data-updates.lua
  3. @@ -1,17 +1,30 @@
  4. +local RECYCLING_FRACTION = 0.25  -- Fixed recycling return rate from Factorio (hardcoded in game data)
  5. +
  6.  local function replace_ingredient(ingredients, old_ingredient, new_ingredient, new_amount)
  7. -    for i,ingredient in pairs(ingredients) do
  8. +    -- Loop through the list of ingredients/results
  9. +    for i, ingredient in pairs(ingredients) do
  10.          if ingredient.name then
  11. +            -- Full format: {type=..., name=..., amount=...}
  12.              if ingredient.name == old_ingredient then
  13.                  ingredient.name = new_ingredient
  14. -                ingredient.amount = new_amount
  15. +                if new_amount then  -- Set only if provided (for compatibility)
  16. +                    ingredient.amount = new_amount
  17. +                end
  18.              end
  19.          elseif ingredient[1] == old_ingredient then
  20. +            -- Short format: {"name", amount}
  21.              ingredient[1] = new_ingredient
  22. +            if new_amount then
  23. +                ingredient[2] = new_amount
  24. +            end
  25.          end
  26.      end
  27.  end
  28.  
  29.  local function update_recipe(recipe, old_ingredient, new_ingredient, new_amount)
  30. +    -- Replace in the main crafting recipe (unchanged)
  31.      if data.raw.recipe[recipe].ingredients then
  32.          replace_ingredient(data.raw.recipe[recipe].ingredients, old_ingredient, new_ingredient, new_amount)
  33.      end
  34. @@ -21,4 +34,14 @@
  35.      if data.raw.recipe[recipe].expensive then
  36.          replace_ingredient(data.raw.recipe[recipe].expensive.ingredients, old_ingredient, new_ingredient, new_amount)
  37.      end
  38. +
  39. +    -- Handle the recycling recipe
  40. +    local recycling_name = recipe .. "-recycling"
  41. +    local recycling_recipe = data.raw.recipe[recycling_name]
  42. +    if recycling_recipe and recycling_recipe.results then
  43. +        -- Replace in results with 25% of new_amount (floored)
  44. +        replace_ingredient(recycling_recipe.results, old_ingredient, new_ingredient, (new_amount * RECYCLING_FRACTION))
  45. +    end
  46. +    -- No need for normal/expensive checks — recycling recipes don't have them
  47.  end
Advertisement
Add Comment
Please, Sign In to add comment