refinery.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. -- need:
  2. -- bottler?
  3. local function mul(t, x)
  4. local o = {}
  5. for n,i in ipairs(t) do
  6. o[n] = i * x
  7. end
  8. o[2] = o[2] / x
  9. o[5] = o[5] / x
  10. return o
  11. end
  12. --
  13. -- usage: alternate distillation columns and dist. col. outlets
  14. -- put boiler on the bottom
  15. -- pipe various distillates out
  16. --
  17. --
  18. minetest.register_node("bitumen:distillation_column", {
  19. paramtype = "light",
  20. description = "Distillation Column Segment",
  21. tiles = {"bitumen_cracking_column.png", "bitumen_cracking_column.png", "bitumen_cracking_column.png",
  22. "bitumen_cracking_column.png", "bitumen_cracking_column.png", "bitumen_cracking_column.png"},
  23. node_box = {
  24. type = "fixed",
  25. fixed = {
  26. --11.25
  27. mul({-0.49, -0.5, -0.10, 0.49, 0.5, 0.10}, 1.5),
  28. mul({-0.10, -0.5, -0.49, 0.10, 0.5, 0.49}, 1.5),
  29. --22.5
  30. mul({-0.46, -0.5, -0.19, 0.46, 0.5, 0.19}, 1.5),
  31. mul({-0.19, -0.5, -0.46, 0.19, 0.5, 0.46}, 1.5),
  32. -- 33.75
  33. mul({-0.416, -0.5, -0.28, 0.416, 0.5, 0.28}, 1.5),
  34. mul({-0.28, -0.5, -0.416, 0.28, 0.5, 0.416}, 1.5),
  35. --45
  36. mul({-0.35, -0.5, -0.35, 0.35, 0.5, 0.35}, 1.5),
  37. },
  38. },
  39. selection_box = {
  40. type = "fixed",
  41. fixed = {
  42. mul({-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, 1.5),
  43. },
  44. },
  45. drawtype = "nodebox",
  46. groups = {cracky=3,oddly_breakable_by_hand=3 },
  47. legacy_facedir_simple = true,
  48. sounds = default.node_sound_wood_defaults(),
  49. on_construct = function(pos)
  50. end,
  51. })
  52. minetest.register_node("bitumen:distillation_column_outlet", {
  53. paramtype = "light",
  54. description = "Distillation Column Outlet",
  55. tiles = {"bitumen_cracking_column.png", "bitumen_cracking_column_outlet.png", "bitumen_cracking_column_outlet.png",
  56. "bitumen_cracking_column_outlet.png", "bitumen_cracking_column_outlet.png", "bitumen_cracking_column.png"},
  57. node_box = {
  58. type = "fixed",
  59. fixed = {
  60. --11.25
  61. mul({-0.49, -0.5, -0.10, 0.49, 0.5, 0.10}, 1.5),
  62. mul({-0.10, -0.5, -0.49, 0.10, 0.5, 0.49}, 1.5),
  63. --22.5
  64. mul({-0.46, -0.5, -0.19, 0.46, 0.5, 0.19}, 1.5),
  65. mul({-0.19, -0.5, -0.46, 0.19, 0.5, 0.46}, 1.5),
  66. -- 33.75
  67. mul({-0.416, -0.5, -0.28, 0.416, 0.5, 0.28}, 1.5),
  68. mul({-0.28, -0.5, -0.416, 0.28, 0.5, 0.416}, 1.5),
  69. --45
  70. mul({-0.35, -0.5, -0.35, 0.35, 0.5, 0.35}, 1.5),
  71. },
  72. },
  73. selection_box = {
  74. type = "fixed",
  75. fixed = {
  76. mul({-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, 1.0)
  77. },
  78. },
  79. drawtype = "nodebox",
  80. groups = {cracky=3,oddly_breakable_by_hand=3, petroleum_fixture=1},
  81. legacy_facedir_simple = true,
  82. sounds = default.node_sound_wood_defaults(),
  83. on_construct = function(pos)
  84. -- connect to the pipe network
  85. bitumen.pipes.on_construct(pos)
  86. end,
  87. })
  88. bitumen.distillation_stack = {
  89. "tar",
  90. "heavy_oil",
  91. "light_oil",
  92. "diesel",
  93. "kerosene",
  94. "gasoline",
  95. "mineral_spirits",
  96. -- "lpg",
  97. }
  98. local function check_stack(opos)
  99. local ret = { }
  100. local oh = opos.y
  101. local pos = {x=opos.x, y=opos.y+1, z=opos.z}
  102. local height = 0
  103. local n
  104. while height < 7 do
  105. local n = minetest.get_node(pos)
  106. if n.name == "bitumen:distillation_column" then
  107. -- noop
  108. --print("col")
  109. elseif n.name == "bitumen:distillation_column_outlet" then
  110. height = height+1
  111. --local t = bitumen.distillation_stack[height]
  112. ret[height] = {x=pos.x, y=pos.y, z=pos.z}
  113. --print(t.." at ".. (pos.y).. " - " .. height)
  114. else
  115. --print("n "..n.name)
  116. -- end of the stack
  117. break
  118. end
  119. pos.y = pos.y+1
  120. end
  121. --print("returning")
  122. return ret
  123. end
  124. local function dcb_node_timer(pos, elapsed)
  125. end
  126. local function swap_node(pos, name)
  127. local node = minetest.get_node(pos)
  128. if node.name == name then
  129. return
  130. end
  131. node.name = name
  132. minetest.swap_node(pos, node)
  133. end
  134. bitumen.register_burner({"bitumen:distillation_column_boiler_on"}, {
  135. start_cook = function()
  136. --print("starting")
  137. return 2
  138. end,
  139. finish_cook = function(pos)
  140. --print("y1 ".. pos.y)
  141. local input = bitumen.pipes.take_fluid(pos, 64)
  142. print(pos.x .. " crude taken: ".. input)
  143. if input <= 0 then
  144. return
  145. end
  146. --print("y2 ".. pos.y)
  147. local stack = check_stack(pos)
  148. --print("y3 ".. pos.y)
  149. for i,p in ipairs(stack) do
  150. local fluid = bitumen.distillation_stack[i]
  151. local yield = bitumen.distillation_yield[fluid] * (input / 100) -- convert to levels
  152. --print("pushing "..yield.. " " ..fluid.." at "..p.y)
  153. bitumen.pipes.push_fluid(p, "bitumen:"..fluid, yield, 20)
  154. end
  155. end,
  156. get_formspec_on = get_melter_active_formspec,
  157. }, 5.0)
  158. minetest.register_node("bitumen:distillation_column_boiler", {
  159. description = "Distillation Column Boiler",
  160. tiles = {
  161. "default_bronze_block.png", "default_bronze_block.png",
  162. "default_bronze_block.png", "default_bronze_block.png",
  163. "default_bronze_block.png", "default_furnace_front.png",
  164. },
  165. paramtype2 = "facedir",
  166. groups = {cracky=2, petroleum_fixture=1},
  167. is_ground_content = false,
  168. sounds = default.node_sound_stone_defaults(),
  169. --can_dig = can_dig,
  170. --on_timer = burner_on_timer,
  171. on_construct = function(pos)
  172. local meta = minetest.get_meta(pos)
  173. meta:set_string("formspec", bitumen.get_melter_active_formspec())
  174. local inv = meta:get_inventory()
  175. inv:set_size('fuel', 4)
  176. bitumen.pipes.on_construct(pos)
  177. minetest.get_node_timer(pos):start(1.0)
  178. end,
  179. -- on_metadata_inventory_move = function(pos)
  180. -- minetest.get_node_timer(pos):start(1.0)
  181. -- end,
  182. -- on_metadata_inventory_put = function(pos)
  183. -- -- start timer function, it will sort out whether furnace can burn or not.
  184. -- minetest.get_node_timer(pos):start(1.0)
  185. -- end,
  186. --
  187. on_punch = function(pos)
  188. swap_node(pos, "bitumen:distillation_column_boiler_on")
  189. minetest.get_node_timer(pos):start(1.0)
  190. end,
  191. -- on_blast = function(pos)
  192. -- local drops = {}
  193. -- default.get_inventory_drops(pos, "src", drops)
  194. -- default.get_inventory_drops(pos, "fuel", drops)
  195. -- default.get_inventory_drops(pos, "dst", drops)
  196. -- drops[#drops+1] = "machines:machine"
  197. -- minetest.remove_node(pos)
  198. -- return drops
  199. -- end,
  200. allow_metadata_inventory_put = allow_metadata_inventory_put,
  201. allow_metadata_inventory_move = allow_metadata_inventory_move,
  202. allow_metadata_inventory_take = allow_metadata_inventory_take,
  203. })
  204. minetest.register_node("bitumen:distillation_column_boiler_on", {
  205. description = "Distillation Column Boiler",
  206. tiles = {
  207. "default_tin_block.png", "default_bronze_block.png",
  208. "default_bronze_block.png", "default_tin_block.png",
  209. "default_tin_block.png",
  210. {
  211. image = "default_furnace_front_active.png",
  212. backface_culling = false,
  213. animation = {
  214. type = "vertical_frames",
  215. aspect_w = 16,
  216. aspect_h = 16,
  217. length = 1.5
  218. },
  219. }
  220. },
  221. paramtype2 = "facedir",
  222. groups = {cracky=2, petroleum_fixture=1, not_in_creative_inventory=1},
  223. is_ground_content = false,
  224. sounds = default.node_sound_stone_defaults(),
  225. --can_dig = can_dig,
  226. on_timer = bitumen.burner_on_timer,
  227. on_construct = function(pos)
  228. local meta = minetest.get_meta(pos)
  229. meta:set_string("formspec", bitumen.get_melter_active_formspec())
  230. local inv = meta:get_inventory()
  231. inv:set_size('fuel', 4)
  232. bitumen.pipes.on_construct(pos)
  233. minetest.get_node_timer(pos):start(1.0)
  234. end,
  235. -- on_metadata_inventory_move = function(pos)
  236. -- minetest.get_node_timer(pos):start(1.0)
  237. -- end,
  238. -- on_metadata_inventory_put = function(pos)
  239. -- -- start timer function, it will sort out whether furnace can burn or not.
  240. -- minetest.get_node_timer(pos):start(1.0)
  241. -- end,
  242. --
  243. on_punch = function(pos)
  244. swap_node(pos, "bitumen:distillation_column_boiler")
  245. end,
  246. allow_metadata_inventory_put = allow_metadata_inventory_put,
  247. allow_metadata_inventory_move = allow_metadata_inventory_move,
  248. allow_metadata_inventory_take = allow_metadata_inventory_take,
  249. })
  250. -- must add up to 100
  251. bitumen.distillation_yield = {
  252. tar = 20,
  253. heavy_oil = 20,
  254. light_oil = 10,
  255. diesel = 20,
  256. kerosene = 15,
  257. gasoline = 10,
  258. mineral_spirits = 5,
  259. }
  260. -- TODO: more
  261. bitumen.cracking_yield = {
  262. ["bitumen:tar"] = {
  263. {"tar", 40},
  264. {"heavy_oil", 30},
  265. {"light_oil", 20},
  266. {"diesel", 10},
  267. },
  268. ["bitumen:heavy_oil"] = {
  269. {"heavy_oil", 30},
  270. {"light_oil", 30},
  271. {"diesel", 30},
  272. {"kerosene", 10},
  273. },
  274. ["bitumen:light_oil"] = {
  275. {"light_oil", 30},
  276. {"diesel", 30},
  277. {"kerosene", 20},
  278. {"gasoline", 20},
  279. },
  280. ["bitumen:diesel"] = {
  281. {"diesel", 20},
  282. {"kerosene", 30},
  283. {"gasoline", 25},
  284. {"mineral_spirits", 25},
  285. },
  286. ["bitumen:kerosene"] = {
  287. {"kerosene", 10},
  288. {"gasoline", 30},
  289. {"mineral_spirits", 30},
  290. --lpg = 30,
  291. },
  292. ["bitumen:gasoline"] = {
  293. {"gasoline", 5},
  294. {"mineral_spirits", 40},
  295. -- lpg = 40,
  296. -- ethane = 15,
  297. },
  298. ["bitumen:mineral_spirits"] = {
  299. {"mineral_spirits", 10},
  300. -- lpg = 60,
  301. -- ethane = 30,
  302. },
  303. }
  304. -- cracking columns
  305. bitumen.register_burner({"bitumen:cracking_boiler_on"}, {
  306. start_cook = function()
  307. return 2
  308. end,
  309. finish_cook = function(pos)
  310. local input, influid = bitumen.pipes.take_fluid(pos, 64)
  311. if input <= 0 then
  312. return
  313. end
  314. local ytable = bitumen.cracking_yield[influid]
  315. if not ytable then
  316. return
  317. end
  318. local stack = check_stack(pos)
  319. for i,p in ipairs(stack) do
  320. local def = ytable[i]
  321. if not def then
  322. break
  323. end
  324. local yield = def[2] * (input / 100) -- convert to levels
  325. bitumen.pipes.push_fluid(p, "bitumen:"..def[1], yield, 20)
  326. end
  327. end,
  328. get_formspec_on = get_melter_active_formspec,
  329. }, 5.0)
  330. minetest.register_node("bitumen:cracking_boiler", {
  331. description = "Cracking Column Boiler",
  332. tiles = {
  333. "default_bronze_block.png", "default_bronze_block.png",
  334. "default_bronze_block.png", "default_bronze_block.png",
  335. "default_bronze_block.png", "default_furnace_front.png",
  336. },
  337. paramtype2 = "facedir",
  338. groups = {cracky=2, petroleum_fixture=1},
  339. is_ground_content = false,
  340. sounds = default.node_sound_stone_defaults(),
  341. on_construct = function(pos)
  342. local meta = minetest.get_meta(pos)
  343. meta:set_string("formspec", bitumen.get_melter_active_formspec())
  344. local inv = meta:get_inventory()
  345. inv:set_size('fuel', 4)
  346. bitumen.pipes.on_construct(pos)
  347. minetest.get_node_timer(pos):start(1.0)
  348. end,
  349. on_punch = function(pos)
  350. swap_node(pos, "bitumen:cracking_boiler_on")
  351. minetest.get_node_timer(pos):start(1.0)
  352. end,
  353. allow_metadata_inventory_put = allow_metadata_inventory_put,
  354. allow_metadata_inventory_move = allow_metadata_inventory_move,
  355. allow_metadata_inventory_take = allow_metadata_inventory_take,
  356. })
  357. minetest.register_node("bitumen:cracking_boiler_on", {
  358. description = "Cracking Column Boiler",
  359. tiles = {
  360. "default_tin_block.png", "default_bronze_block.png",
  361. "default_bronze_block.png", "default_tin_block.png",
  362. "default_tin_block.png",
  363. {
  364. image = "default_furnace_front_active.png",
  365. backface_culling = false,
  366. animation = {
  367. type = "vertical_frames",
  368. aspect_w = 16,
  369. aspect_h = 16,
  370. length = 1.5
  371. },
  372. }
  373. },
  374. paramtype2 = "facedir",
  375. groups = {cracky=2, petroleum_fixture=1, not_in_creative_inventory=1},
  376. is_ground_content = false,
  377. sounds = default.node_sound_stone_defaults(),
  378. --can_dig = can_dig,
  379. on_timer = bitumen.burner_on_timer,
  380. on_construct = function(pos)
  381. local meta = minetest.get_meta(pos)
  382. meta:set_string("formspec", bitumen.get_melter_active_formspec())
  383. local inv = meta:get_inventory()
  384. inv:set_size('fuel', 4)
  385. bitumen.pipes.on_construct(pos)
  386. minetest.get_node_timer(pos):start(1.0)
  387. end,
  388. -- on_metadata_inventory_move = function(pos)
  389. -- minetest.get_node_timer(pos):start(1.0)
  390. -- end,
  391. -- on_metadata_inventory_put = function(pos)
  392. -- -- start timer function, it will sort out whether furnace can burn or not.
  393. -- minetest.get_node_timer(pos):start(1.0)
  394. -- end,
  395. --
  396. on_punch = function(pos)
  397. swap_node(pos, "bitumen:cracking_boiler")
  398. end,
  399. allow_metadata_inventory_put = allow_metadata_inventory_put,
  400. allow_metadata_inventory_move = allow_metadata_inventory_move,
  401. allow_metadata_inventory_take = allow_metadata_inventory_take,
  402. })