View difference between Paste ID: 4BQriFAR and 0z3LAXaZ
SHOW: | | - or go back to the newest paste.
1
if not bobmods.lib.recipe then bobmods.lib.recipe = {} end
2
3
4
function bobmods.lib.recipe.replace_ingredient(recipe, old, new)
5
  print("Hello from replace_ingredient in bobs!")
6
  print("Recipe: "..recipe)
7
  print("HELP(0)! "..recipe)
8
  print("OUTPUTTING data.raw")
9
  print(data.raw)
10
  print("OUTPUTTING data.raw.recipe")
11
  print(data.raw.recipe)
12
  print("OUTPUTTING data.raw.recipe[recipe] ")
13
  print(data.raw.recipe[recipe])
14
  print("OUTPUTTING bobmods ")
15
  print(bobmods)
16
  print("OUTPUTTING bobmods.lib ")
17
  print(bobmods.lib)
18
  print("OUTPUTTING bobmods.lib.item ")
19
  print(bobmods.lib.item)
20
  
21
  if not data.raw.recipe[recipe] then
22
    log("Recipe " .. recipe .. " does not exist.")
23
    return false
24
  end
25
  
26
  if data.raw.recipe[recipe] and bobmods.lib.item.get_type(new) then
27
    print("HELP(1)! "..recipe)
28
    local amount = 0
29
    for i, ingredient in pairs(data.raw.recipe[recipe].ingredients) do
30
      if ingredient[1] == old then
31
        amount = ingredient[2] + amount
32
      end
33
      if ingredient.name == old then
34
        amount = ingredient.amount + amount
35
      end
36
    end
37
    if amount > 0 then
38
      bobmods.lib.recipe.remove_ingredient(recipe, old)
39
      bobmods.lib.recipe.add_ingredient(recipe, {new, amount})
40
      return true
41
    else
42
      return false
43
    end
44
    print("HELP(2)! "..recipe)
45
  else
46
    print("HELP(3)! "..recipe)
47
    if not data.raw.recipe[recipe] then
48
      log("Recipe " .. recipe .. " does not exist.")
49
    end
50
    print("HELP(4)! "..recipe)
51
    if not bobmods.lib.item.get_type(new) then
52
      log("Ingredient " .. new .. " does not exist.")
53
    end
54
    print("HELP(5)! "..recipe)
55
    return false
56
  end
57
end
58
59
function bobmods.lib.recipe.replace_ingredient_crude(recipe, old, new)
60
  if data.raw.recipe[recipe] and bobmods.lib.item.get_basic_type(new) then
61
    local replaced = false
62
    for i, ingredient in pairs(data.raw.recipe[recipe].ingredients) do
63
      if ingredient[1] == old or ingredient.name == old then
64
        local item = bobmods.lib.item.basic_item(ingredient)
65
        item.name = new
66
        item.type = bobmods.lib.item.get_basic_type(new)
67
        ingredient = item
68
        replaced = true
69
      end
70
    end
71
    return replaced
72
  else
73
    if not data.raw.recipe[recipe] then
74
      log("Recipe " .. recipe .. " does not exist.")
75
    end
76
    if not bobmods.lib.item.get_type(new) then
77
      log("Ingredient " .. new .. " does not exist.")
78
    end
79
    return false
80
  end
81
end
82
83
function bobmods.lib.recipe.replace_ingredient_in_all(old, new)
84
  if bobmods.lib.item.get_basic_type(new) then
85
    for i, recipe in pairs(data.raw.recipe) do
86
      bobmods.lib.recipe.replace_ingredient(recipe.name, old, new)
87
    end
88
  else
89
    log("Ingredient " .. new .. " does not exist.")
90
  end
91
end
92
93
function bobmods.lib.recipe.remove_ingredient(recipe, item)
94
  if data.raw.recipe[recipe] then
95
    bobmods.lib.item.remove(data.raw.recipe[recipe].ingredients, item)
96
  else
97
    log("Recipe " .. recipe .. " does not exist.")
98
  end
99
end
100
101
function bobmods.lib.recipe.add_new_ingredient(recipe, item)
102
  if data.raw.recipe[recipe] and bobmods.lib.item.get_type(bobmods.lib.item.basic_item(item).name) then
103
    bobmods.lib.item.add_new(data.raw.recipe[recipe].ingredients, bobmods.lib.item.basic_item(item))
104
  else
105
    if not data.raw.recipe[recipe] then
106
      log("Recipe " .. recipe .. " does not exist.")
107
    end
108
    if not bobmods.lib.item.get_type(item) then
109
      log("Ingredient " .. bobmods.lib.item.basic_item(item).name .. " does not exist.")
110
    end
111
  end
112
end
113
114
function bobmods.lib.recipe.add_ingredient(recipe, item)
115
  if data.raw.recipe[recipe] and bobmods.lib.item.get_type(bobmods.lib.item.basic_item(item).name) then
116
    bobmods.lib.item.add(data.raw.recipe[recipe].ingredients, bobmods.lib.item.basic_item(item))
117
  else
118
    if not data.raw.recipe[recipe] then
119
      log("Recipe " .. recipe .. " does not exist.")
120
    end
121
    if not bobmods.lib.item.get_basic_type(bobmods.lib.item.basic_item(item).name) then
122
      log("Ingredient " .. bobmods.lib.item.basic_item(item).name .. " does not exist.")
123
    end
124
  end
125
end
126
127
128
function bobmods.lib.recipe.add_result(recipe, item)
129
  if data.raw.recipe[recipe] and bobmods.lib.item.get_type(bobmods.lib.item.basic_item(item).name) then
130
    bobmods.lib.result_check(data.raw.recipe[recipe])
131
    bobmods.lib.item.add(data.raw.recipe[recipe].results, item)
132
  else
133
    if not data.raw.recipe[recipe] then
134
      log("Recipe " .. recipe .. " does not exist.")
135
    end
136
    if not bobmods.lib.item.get_basic_type(bobmods.lib.item.basic_item(item).name) then
137
      log("Item " .. bobmods.lib.item.basic_item(item).name .. " does not exist.")
138
    end
139
  end
140
end
141
142
function bobmods.lib.recipe.remove_result(recipe, item)
143
  if data.raw.recipe[recipe] then
144
    bobmods.lib.result_check(data.raw.recipe[recipe])
145
    bobmods.lib.item.remove(data.raw.recipe[recipe].results, item)
146
  else
147
    log("Recipe " .. recipe .. " does not exist.")
148
  end
149
end