Lua scripts and notes for programming within Minetest.

recipes.lua 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. local recipes = {
  2. ["technic:mv_centrifuge"] = {
  3. craft = {
  4. {"basic_materials:motor", "technic:copper_plate", "technic:diamond_drill_head"},
  5. {"technic:copper_plate", "technic:machine_casing", "technic:copper_plate"},
  6. {"pipeworks:one_way_tube", "technic:mv_cable", "pipeworks:mese_filter"}
  7. }
  8. },
  9. ["basic_materials:motor"] = {
  10. craft = {
  11. {"default:mese_crystal_fragment", "basic_materials:copper_wire", "basic_materials:plastic_sheet"},
  12. {"default:copper_ingot", "default:steel_ingot", "default:steel_ingot"},
  13. {"default:mese_crystal_fragment", "basic_materials:copper_wire", "basic_materials:plastic_sheet"}
  14. },
  15. produces = 2
  16. },
  17. ["technic:copper_plate"] = {
  18. compress = {
  19. item = "technic:copper_ingot",
  20. amount = 5
  21. }
  22. },
  23. ["technic:diamond_drill_head"] = {
  24. craft = {
  25. {"technic:stainless_steel_ingot", "default:diamond", "technic:stainless_steel_ingot"},
  26. {"default:diamond", "", "default:diamond"},
  27. {"technic:stainless_steel_ingot", "default:diamond", "technic:stainless_steel_ingot"}
  28. }
  29. },
  30. ["technic:stainless_steel_ingot"] = {
  31. alloy = {
  32. ["technic:carbon_steel_ingot"] = 3,
  33. ["technic:chromium_ingot"] = 1
  34. },
  35. produces = 4
  36. },
  37. ["technic:carbon_steel_ingot"] = {
  38. alloy = {
  39. ["default:steel_ingot"] = 1,
  40. ["technic:coal_dust"] = 1
  41. }
  42. },
  43. ["technic:machine_casing"] = {
  44. craft = {
  45. {"technic:cast_iron_ingot", "technic:cast_iron_ingot", "technic:cast_iron_ingot"},
  46. {"technic:cast_iron_ingot", "basic_materials:brass_ingot", "technic:cast_iron_ingot"},
  47. {"technic:cast_iron_ingot", "technic:cast_iron_ingot", "technic:cast_iron_ingot"}
  48. }
  49. },
  50. ["basic_materials:brass_ingot"] = {
  51. alloy = {
  52. ["default:copper_ingot"] = 2,
  53. ["technic:zinc_ingot"] = 1
  54. },
  55. produces = 3
  56. },
  57. ["technic:cast_iron_ingot"] = {
  58. smelt = "default:steel_ingot"
  59. },
  60. ["pipeworks:one_way_tube"] = {
  61. craft = {
  62. {"basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet"},
  63. {"default:stick", "default:mese_crystal", "basic_materials:plastic_sheet"},
  64. {"basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet"}
  65. },
  66. produces = 2
  67. },
  68. ["technic:mv_cable"] = {
  69. craft = {
  70. {"technic:rubber", "technic:rubber", "technic:rubber"},
  71. {"technic:lv_cable", "technic:lv_cable", "technic:lv_cable"},
  72. {"technic:rubber", "technic:rubber", "technic:rubber"}
  73. },
  74. produces = 3
  75. },
  76. ["technic:rubber"] = {
  77. alloy = {
  78. ["technic:raw_latex"] = 4,
  79. ["technic:coal_dust"] = 2
  80. },
  81. produces = 6
  82. },
  83. ["technic:raw_latex"] = {
  84. extract = {
  85. item = "technic:rubber_tree_grindings",
  86. amount = 4
  87. }
  88. },
  89. ["technic:lv_cable"] = {
  90. craft = {
  91. {"default:paper", "default:paper", "default:paper"},
  92. {"default:copper_ingot", "default:copper_ingot", "default:copper_ingot"},
  93. {"default:paper", "default:paper", "default:paper"}
  94. },
  95. produces = 6
  96. },
  97. ["default:paper"] = {
  98. craft = {
  99. {"", "", ""},
  100. {"default:papyrus", "default:papyrus", "default:papyrus"},
  101. {"", "", ""}
  102. },
  103. produces = 4
  104. },
  105. ["pipeworks:mese_filter"] = {
  106. craft = {
  107. {"default:steel_ingot", "default:steel_ingot", "basic_materials:plastic_sheet"},
  108. {"default:stick", "default:mese", "basic_materials:plastic_sheet"},
  109. {"default:steel_ingot", "default:steel_ingot", "basic_materials:plastic_sheet"}
  110. },
  111. produces = 2
  112. },
  113. ["default:mese"] = {
  114. craft = {
  115. {"default:mese_crystal", "default:mese_crystal", "default:mese_crystal"},
  116. {"default:mese_crystal", "default:mese_crystal", "default:mese_crystal"},
  117. {"default:mese_crystal", "default:mese_crystal", "default:mese_crystal"}
  118. }
  119. },
  120. ["default:mese_crystal_fragment"] = {
  121. craft = {
  122. {"", "", ""},
  123. {"", "default:mese_crystal", ""},
  124. {"", "", ""}
  125. },
  126. produces = 9
  127. },
  128. ["basic_materials:copper_wire"] = {
  129. craft = {
  130. {"default:copper_ingot", "basic_materials:empty_spool", ""},
  131. {"basic_materials:empty_spool", "", ""},
  132. {"", "", ""}
  133. },
  134. produces = 2
  135. },
  136. ["basic_materials:empty_spool"] = {
  137. craft = {
  138. {"basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet"},
  139. {"", "basic_materials:plastic_sheet", ""},
  140. {"basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet"}
  141. },
  142. produces = 3
  143. },
  144. ["basic_materials:plastic_sheet"] = {
  145. smelt = "basic_materials:paraffin"
  146. },
  147. ["basic_materials:paraffin"] = {
  148. smelt = "basic_materials:oil_extract"
  149. },
  150. ["technic:solar_panel"] = {
  151. craft = {
  152. {"technic:doped_silicon_wafer", "technic:doped_silicon_wafer", "technic:doped_silicon_wafer"},
  153. {"basic_materials:silver_wire", "technic:lv_cable", "mesecons_materials:glue"},
  154. {"", "", ""}
  155. }
  156. },
  157. ["technic:doped_silicon_wafer"] = {
  158. alloy = {
  159. ["technic:silicon_wafer"] = 1,
  160. ["technic:gold_dust"] = 1
  161. }
  162. },
  163. ["technic:silicon_wafer"] = {
  164. alloy = {
  165. ["default:sand"] = 2,
  166. ["technic:coal_dust"] = 2
  167. }
  168. },
  169. ["basic_materials:silver_wire"] = {
  170. craft = {
  171. {"moreores:silver_ingot", "basic_materials:empty_spool", ""},
  172. {"basic_materials:empty_spool", "", ""},
  173. {"", "", ""}
  174. },
  175. produces = 2
  176. },
  177. ["mesecons_materials:glue"] = {
  178. smelt = "technic:raw_latex"
  179. },
  180. ["technic:solar_array_lv"] = {
  181. craft = {
  182. {"technic:solar_panel", "technic:solar_panel", "technic:solar_panel"},
  183. {"technic:carbon_steel_ingot", "technic:lv_transformer", "technic:carbon_steel_ingot"},
  184. {"", "technic:lv_cable", ""}
  185. }
  186. },
  187. ["technic:lv_transformer"] = {
  188. craft = {
  189. {"mesecons_materials:fiber", "default:steel_ingot", "mesecons_materials:fiber"},
  190. {"technic:copper_coil", "default:steel_ingot", "technic:copper_coil"},
  191. {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}
  192. }
  193. },
  194. ["mesecons_materials:fiber"] = {
  195. smelt = "mesecons_materials:glue",
  196. produces = 6
  197. },
  198. ["technic:copper_coil"] = {
  199. craft = {
  200. {"basic_materials:copper_wire", "default:steel_ingot", "basic_materials:copper_wire"},
  201. {"default:steel_ingot", "", "default:steel_ingot"},
  202. {"basic_materials:copper_wire", "default:steel_ingot", "basic_materials:copper_wire"}
  203. }
  204. },
  205. ["technic:solar_array_mv"] = {
  206. craft = {
  207. {"technic:solar_array_lv", "technic:solar_array_lv", "technic:solar_array_lv"},
  208. {"technic:carbon_steel_ingot", "technic:mv_transformer", "technic:carbon_steel_ingot"},
  209. {"", "technic:mv_cable", ""}
  210. }
  211. },
  212. ["technic:mv_transformer"] = {
  213. craft = {
  214. {"mesecons_materials:fiber", "technic:carbon_steel_ingot", "mesecons_materials:fiber"},
  215. {"technic:copper_coil", "technic:carbon_steel_ingot", "technic:copper_coil"},
  216. {"technic:carbon_steel_ingot", "technic:carbon_steel_ingot", "technic:carbon_steel_ingot"}
  217. }
  218. },
  219. }
  220. local items = {
  221. -- ["technic:mv_centrifuge"] = 31 -- 34 minus 3 I already have
  222. ["technic:mv_transformer"] = 1
  223. }
  224. local function get_count(goal, recipe)
  225. local count = goal / (recipe.produces or 1)
  226. if count ~= math.floor(count) then
  227. count = math.floor(count) + 1
  228. end
  229. return count
  230. end
  231. local steps = {}
  232. local active = true
  233. while active do
  234. active = false
  235. for item, count in pairs(items) do
  236. if recipes[item] then
  237. active = item
  238. local current = recipes[item]
  239. local _count = get_count(count, current)
  240. if current.craft then
  241. table.insert(steps, "craft "..item.." "..tostring(_count).." times")
  242. local new = {}
  243. for y=1,3 do
  244. for x=1,3 do
  245. if current.craft[y][x] ~= "" then
  246. item = current.craft[y][x]
  247. if new[item] then
  248. new[item] = new[item] + _count
  249. else
  250. new[item] = _count
  251. end
  252. end
  253. end
  254. end
  255. for item, count in pairs(new) do
  256. if items[item] then
  257. items[item] = items[item] + count
  258. else
  259. items[item] = count
  260. end
  261. end
  262. elseif current.compress then
  263. table.insert(steps, "compress "..item.." "..tostring(_count).." times")
  264. if current.compress.amount then
  265. _count = _count * current.compress.amount
  266. end
  267. if items[current.compress.item] then
  268. items[current.compress.item] = items[current.compress.item] + _count
  269. else
  270. items[current.compress.item] = _count
  271. end
  272. elseif current.alloy then
  273. table.insert(steps, "alloy "..item.." "..tostring(_count).." times")
  274. for item, amount in pairs(current.alloy) do
  275. if items[item] then
  276. items[item] = items[item] + _count * amount
  277. else
  278. items[item] = _count * amount
  279. end
  280. end
  281. elseif current.smelt then
  282. table.insert(steps, "smelt "..item.." "..tostring(_count).." times")
  283. if items[current.smelt] then
  284. items[current.smelt] = items[current.smelt] + _count
  285. else
  286. items[current.smelt] = _count
  287. end
  288. elseif current.extract then
  289. table.insert(steps, "extract "..item.." "..tostring(_count).." times")
  290. if current.extract.amount then
  291. _count = _count * current.extract.amount
  292. end
  293. if items[current.extract.item] then
  294. items[current.extract.item] = items[current.extract.item] + _count
  295. else
  296. items[current.extract.item] = _count
  297. end
  298. end
  299. break
  300. end
  301. end
  302. if active then
  303. items[active] = nil
  304. end
  305. end
  306. for k,v in pairs(items) do
  307. print(k,v)
  308. end
  309. for i=#steps,1,-1 do
  310. print(steps[i])
  311. end