Advertisement
Guest User

Untitled

a guest
Sep 26th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function bobmods.lib.recipe.replace_ingredient(recipe, old, new)
  2.   print("Hello from replace_ingredient in bobs!")
  3.   print("Recipe: "..recipe)
  4.   print("HELP(0)! "..recipe)
  5.   print("OUTPUTTING data.raw")
  6.   print(data.raw)
  7.   print("OUTPUTTING data.raw.recipe")
  8.   print(data.raw.recipe)
  9.   print("OUTPUTTING data.raw.recipe[recipe] ")
  10.   print(data.raw.recipe[recipe])
  11.   print("OUTPUTTING bobmods ")
  12.   print(bobmods)
  13.   print("OUTPUTTING bobmods.lib ")
  14.   print(bobmods.lib)
  15.   print("OUTPUTTING bobmods.lib.item ")
  16.   print(bobmods.lib.item)
  17.  
  18.   if not data.raw.recipe[recipe] then
  19.     return false
  20.   end
  21.  
  22.   if data.raw.recipe[recipe] and bobmods.lib.item.get_type(new) then
  23.     print("HELP(1)! "..recipe)
  24.     local amount = 0
  25.     for i, ingredient in pairs(data.raw.recipe[recipe].ingredients) do
  26.       if ingredient[1] == old then
  27.         amount = ingredient[2] + amount
  28.       end
  29.       if ingredient.name == old then
  30.         amount = ingredient.amount + amount
  31.       end
  32.     end
  33.     if amount > 0 then
  34.       bobmods.lib.recipe.remove_ingredient(recipe, old)
  35.       bobmods.lib.recipe.add_ingredient(recipe, {new, amount})
  36.       return true
  37.     else
  38.       return false
  39.     end
  40.     print("HELP(2)! "..recipe)
  41.   else
  42.     print("HELP(3)! "..recipe)
  43.     if not data.raw.recipe[recipe] then
  44.       log("Recipe " .. recipe .. " does not exist.")
  45.     end
  46.     print("HELP(4)! "..recipe)
  47.     if not bobmods.lib.item.get_type(new) then
  48.       log("Ingredient " .. new .. " does not exist.")
  49.     end
  50.     print("HELP(5)! "..recipe)
  51.     return false
  52.   end
  53. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement