wells.lua 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954
  1. local function check_drill_stack(opos)
  2. local pos = vector.new(opos)
  3. pos.y = pos.y - 1
  4. while 1 == 1 do
  5. local name = minetest.get_node(pos).name
  6. if name == "bitumen:drill_pipe" then
  7. elseif name == "bitumen:drill_mud_extractor" then
  8. elseif name == "bitumen:drill_mud_injector" then
  9. -- noop
  10. else
  11. -- end of the stack
  12. break
  13. end
  14. pos.y = pos.y - 1
  15. end
  16. print("check stack well depth: "..pos.y)
  17. return {x=pos.x, y=pos.y, z=pos.z}
  18. end
  19. local function mul(t, x)
  20. local o = {}
  21. for n,i in ipairs(t) do
  22. o[n] = i * x
  23. end
  24. o[2] = o[2] / x
  25. o[5] = o[5] / x
  26. return o
  27. end
  28. minetest.register_node("bitumen:drill_pipe", {
  29. paramtype = "light",
  30. description = "Drill Pipe",
  31. tiles = {"default_copper_block.png", "default_copper_block.png", "default_copper_block.png",
  32. "default_copper_block.png", "default_copper_block.png", "default_copper_block.png"},
  33. node_box = {
  34. type = "fixed",
  35. fixed = {
  36. --11.25
  37. mul({-0.49, -0.5, -0.10, 0.49, 0.5, 0.10}, .3),
  38. mul({-0.10, -0.5, -0.49, 0.10, 0.5, 0.49}, .3),
  39. --22.5
  40. mul({-0.46, -0.5, -0.19, 0.46, 0.5, 0.19}, .3),
  41. mul({-0.19, -0.5, -0.46, 0.19, 0.5, 0.46}, .3),
  42. -- 33.75
  43. mul({-0.416, -0.5, -0.28, 0.416, 0.5, 0.28}, .3),
  44. mul({-0.28, -0.5, -0.416, 0.28, 0.5, 0.416}, .3),
  45. --45
  46. mul({-0.35, -0.5, -0.35, 0.35, 0.5, 0.35}, .3),
  47. },
  48. },
  49. selection_box = {
  50. type = "fixed",
  51. fixed = {
  52. mul({-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, .3),
  53. },
  54. },
  55. drawtype = "nodebox",
  56. groups = {cracky=3,oddly_breakable_by_hand=3 },
  57. legacy_facedir_simple = true,
  58. sounds = default.node_sound_wood_defaults(),
  59. on_punch = function(pos)
  60. check_drill_stack(pos)
  61. end,
  62. })
  63. minetest.register_node("bitumen:well_siphon", {
  64. paramtype = "light",
  65. description = "Well Siphon",
  66. tiles = {"default_bronze_block.png", "default_bronze_block.png", "default_bronze_block.png",
  67. "default_bronze_block.png", "default_bronze_block.png", "default_bronze_block.png"},
  68. node_box = {
  69. type = "fixed",
  70. fixed = {
  71. --11.25
  72. {-0.49, -0.5, -0.10, 0.49, 0.5, 0.10},
  73. {-0.10, -0.5, -0.49, 0.10, 0.5, 0.49},
  74. --22.5
  75. {-0.46, -0.5, -0.19, 0.46, 0.5, 0.19},
  76. {-0.19, -0.5, -0.46, 0.19, 0.5, 0.46},
  77. -- 33.75
  78. {-0.416, -0.5, -0.28, 0.416, 0.5, 0.28},
  79. {-0.28, -0.5, -0.416, 0.28, 0.5, 0.416},
  80. --45
  81. {-0.35, -0.5, -0.35, 0.35, 0.5, 0.35},
  82. },
  83. },
  84. selection_box = {
  85. type = "fixed",
  86. fixed = {
  87. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
  88. },
  89. },
  90. drawtype = "nodebox",
  91. groups = {cracky=3,oddly_breakable_by_hand=3 },
  92. legacy_facedir_simple = true,
  93. sounds = default.node_sound_wood_defaults(),
  94. on_construct = function(pos)
  95. end,
  96. })
  97. local function pushpos(t, v, p)
  98. local h = minetest.hash_node_position(p)
  99. if v[h] == nil then
  100. table.insert(t, p)
  101. end
  102. end
  103. local function find_blob_extent(startpos)
  104. local blob = {}
  105. local stack = {}
  106. local visited = {}
  107. local future = {}
  108. -- local shell = {}
  109. local node = minetest.get_node(startpos)
  110. if node.name == "air" then
  111. return nil
  112. end
  113. local bname = node.name
  114. table.insert(stack, startpos)
  115. while #stack > 0 do
  116. local p = table.remove(stack)
  117. local ph = minetest.hash_node_position(p)
  118. --print("visiting "..minetest.pos_to_string(p))
  119. if p.x < startpos.x - 50
  120. or p.x > startpos.x + 50
  121. or p.y < startpos.y - 50
  122. or p.y > startpos.y + 50
  123. or p.z < startpos.z - 50
  124. or p.z > startpos.z + 50
  125. then
  126. print("got to extent")
  127. visited[ph] = 1
  128. end
  129. if visited[ph] == nil then
  130. print("visiting "..minetest.pos_to_string(p))
  131. local pn = minetest.get_node(p)
  132. if pn then
  133. if pn.name == "bitumen:crude_oil" or pn.name == "bitumen:crude_oil_full" then
  134. blob[ph] = {x=p.x, y=p.y, z=p.z}
  135. pushpos(stack, visited, {x=p.x+1, y=p.y, z=p.z})
  136. pushpos(stack, visited, {x=p.x-1, y=p.y, z=p.z})
  137. pushpos(stack, visited, {x=p.x, y=p.y+1, z=p.z})
  138. pushpos(stack, visited, {x=p.x, y=p.y-1, z=p.z})
  139. pushpos(stack, visited, {x=p.x, y=p.y, z=p.z+1})
  140. pushpos(stack, visited, {x=p.x, y=p.y, z=p.z-1})
  141. visited[ph] = 1
  142. elseif pn.name == "ignore" then
  143. if minetest.forceload_block(p, false) then
  144. print("forceload successful: ".. minetest.pos_to_string(p))
  145. else
  146. print("forceload failed: ".. minetest.pos_to_string(p))
  147. end
  148. table.insert(future, p)
  149. end
  150. else
  151. print("failed to get node")
  152. end
  153. end
  154. end
  155. for _,p in pairs(blob) do
  156. print("blob "..minetest.pos_to_string(p))
  157. end
  158. -- for n,v in pairs(shell) do
  159. -- print("shell "..n.." - ".. v)
  160. -- end
  161. return blob--, shell
  162. end
  163. local function forceload_deposit(pos)
  164. -- minetest.emerge_area(dp, {x=dp.x, y=dp.y - 20, z=dp.z})
  165. find_blob_extent(pos)
  166. end
  167. local function drill(pos)
  168. local meta = minetest.get_meta(pos)
  169. local dp = meta:get_string("drilldepth") or ""
  170. print("dp" .. dump(dp))
  171. if dp == "" then
  172. dp = check_drill_stack(pos)
  173. meta:set_string("drilldepth", minetest.serialize(dp))
  174. else
  175. dp = minetest.deserialize(dp)
  176. --print("deserialized " .. dump(pos))
  177. dp.y = dp.y - 1
  178. end
  179. local n = minetest.get_node(dp)
  180. if n.name == "ignore" then
  181. if minetest.forceload_block(dp, true) then
  182. print("forceload successful: ".. minetest.pos_to_string(dp))
  183. local n = minetest.get_node(dp)
  184. else
  185. --minetest.emerge_area(dp, {x=dp.x, y=dp.y - 20, z=dp.z})
  186. -- print("forceload failed, emerging " .. minetest.pos_to_string(dp))
  187. -- return
  188. end
  189. -- minetest.emerge_area(pos, pos)
  190. end
  191. local hit_oil = false
  192. if n.name == "ignore" then
  193. minetest.emerge_area(dp, {x=dp.x, y=dp.y - 20, z=dp.z})
  194. print("emerging " .. minetest.pos_to_string(dp))
  195. return
  196. elseif n.name == "bitumen:drill_pipe" or n.name == "bitumen:drill_mud_injector" or n.name == "bitumen:drill_mud_extractor"then
  197. dp = check_drill_stack(dp)
  198. elseif n.name == "bitumen:crude_oil" or n.name == "bitumen:crude_oil_full" then
  199. pos.y = pos.y + 2
  200. minetest.set_node(pos, {name = "bitumen:crude_oil"})
  201. minetest.set_node_level(pos, 64)
  202. hit_oil = true
  203. else
  204. print("drilling at "..dp.y.." of "..n.name )
  205. minetest.set_node(dp, {name = "bitumen:drill_pipe"})
  206. end
  207. meta:set_string("drilldepth", minetest.serialize(dp))
  208. local desc = minetest.registered_nodes[n.name].description
  209. if n.name == "air" then
  210. desc = "Air" -- because of a cheeky description in the default game
  211. end
  212. return desc, dp.y, hit_oil
  213. end
  214. minetest.register_node("bitumen:drill_controls", {
  215. description = "Drilling Controls",
  216. tiles = {"default_bronze_block.png", "default_bronze_block.png", "default_bronze_block.png",
  217. "default_bronze_block.png", "default_bronze_block.png", "default_bronze_block.png"},
  218. drawtype = "normal",
  219. paramtype = "light",
  220. paramtype2 = "facedir",
  221. groups = { }, -- undiggable: part of the drill rig
  222. sounds = default.node_sound_wood_defaults(),
  223. on_receive_fields = function(pos, form, fields, player)
  224. local cmd = "none"
  225. if fields.drill then
  226. cmd = "drill"
  227. elseif fields.retract then
  228. cmd = "retract"
  229. elseif fields.stop then
  230. cmd = "stop"
  231. elseif fields.pump then
  232. cmd = "pump"
  233. elseif fields.up then
  234. cmd = "up"
  235. elseif fields.down then
  236. cmd = "down"
  237. elseif fields.explore then
  238. cmd = "explore"
  239. elseif fields.forceload then
  240. cmd = "forceload"
  241. elseif fields.un_forceload then
  242. cmd = "un_forceload"
  243. end
  244. if cmd ~= "none" then
  245. local meta = minetest.get_meta(pos)
  246. local dpos = minetest.deserialize(meta:get_string("magic_parent"))
  247. local dmeta = minetest.get_meta(dpos)
  248. --print(dump(dpos))
  249. --if 1==1 then return end
  250. local state = minetest.deserialize(dmeta:get_string("state"))
  251. state.command = cmd
  252. dmeta:set_string("state", minetest.serialize(state))
  253. end
  254. end,
  255. -- on_rick_click = function(pos, node, player, itemstack, pointed_thing)
  256. -- minetest.show_formspec(player:get_player_name(), fs)]]
  257. -- return itemstack -- don't take anything
  258. -- end,
  259. })
  260. minetest.register_node("bitumen:drill_pipe_chest", {
  261. description = "Drilling Controls",
  262. tiles = {"default_bronze_block.png", "default_bronze_block.png", "default_bronze_block.png",
  263. "default_bronze_block.png", "default_bronze_block.png", "default_bronze_block.png"},
  264. drawtype = "nodebox",
  265. paramtype = "light",
  266. paramtype2 = "facedir",
  267. node_box = {
  268. type = "fixed",
  269. fixed = {
  270. { -.5, -1.5, -.5, .5, 1.5, .5 },
  271. },
  272. },
  273. selection_box = {
  274. type = "fixed",
  275. fixed = {
  276. { -.5, -1.5, -.5, .5, 1.5, .5 },
  277. },
  278. },
  279. collision_box = {
  280. type = "fixed",
  281. fixed = {
  282. { -.5, -1.5, -.5, .5, 1.5, .5 },
  283. },
  284. },
  285. groups = { }, -- undiggable: part of the drill rig
  286. sounds = default.node_sound_wood_defaults(),
  287. on_construct = function(pos)
  288. local meta = minetest.get_meta(pos)
  289. local inv = meta:get_inventory()
  290. inv:set_size("main", 4*8)
  291. end,
  292. })
  293. minetest.register_node("bitumen:drill_mud_injector", {
  294. description = "Drilling Mud Injector",
  295. tiles = {"default_bronze_block.png", "default_bronze_block.png", "default_bronze_block.png",
  296. "default_bronze_block.png", "default_bronze_block.png", "default_bronze_block.png"},
  297. drawtype = "nodebox",
  298. paramtype = "light",
  299. paramtype2 = "facedir",
  300. node_box = {
  301. type = "fixed",
  302. fixed = {
  303. { -.5, -.5, -.5, .5, .5, .5 },
  304. },
  305. },
  306. selection_box = {
  307. type = "fixed",
  308. fixed = {
  309. { -.5, -.5, -.5, .5, .5, .5 },
  310. },
  311. },
  312. collision_box = {
  313. type = "fixed",
  314. fixed = {
  315. { -.5, -.5, -.5, .5, .5, .5 },
  316. },
  317. },
  318. groups = { petroleum_fixture=1 }, -- undiggable: part of the drill rig
  319. sounds = default.node_sound_wood_defaults(),
  320. })
  321. minetest.register_node("bitumen:drill_mud_extractor", {
  322. description = "Drilling Mud Extractor",
  323. tiles = {"default_bronze_block.png", "default_bronze_block.png", "default_bronze_block.png",
  324. "default_bronze_block.png", "default_bronze_block.png", "default_bronze_block.png"},
  325. drawtype = "nodebox",
  326. paramtype = "light",
  327. paramtype2 = "facedir",
  328. node_box = {
  329. type = "fixed",
  330. fixed = {
  331. { -.5, -.5, -.5, .5, .5, .5 },
  332. },
  333. },
  334. selection_box = {
  335. type = "fixed",
  336. fixed = {
  337. { -.5, -.5, -.5, .5, .5, .5 },
  338. },
  339. },
  340. collision_box = {
  341. type = "fixed",
  342. fixed = {
  343. { -.5, -.5, -.5, .5, .5, .5 },
  344. },
  345. },
  346. groups = { petroleum_fixture=1 }, -- undiggable: part of the drill rig
  347. sounds = default.node_sound_wood_defaults(),
  348. })
  349. minetest.register_node("bitumen:drill_rig", {
  350. description = "Drill Rig",
  351. paramtype = "light",
  352. drawtype = "mesh",
  353. mesh = "oil_derrick.obj",
  354. description = "Drilling Derrick",
  355. inventory_image = "bitumen_cement_mixer_invimg.png",
  356. tiles = {
  357. "default_obsidian_block.png",
  358. },
  359. selection_box = {
  360. type = "fixed",
  361. fixed = {
  362. { -.5, -.5, -.5, .5, 1.5, .5 },
  363. },
  364. },
  365. collision_box = {
  366. type = "fixed",
  367. fixed = {
  368. { -.5, -.5, -.5, .5, 1.5, .5 },
  369. -- { -1.5, -1.5, -1.5, -1.4, 3, -1.4 },
  370. -- { 1.5, -1.5, -1.5, 1.4, 3, -1.4 },
  371. -- { -1.5, -1.5, 1.5, -1.4, 3, 1.4 },
  372. -- { 1.5, -1.5, 1.5, 1.4, 3, 1.4 },
  373. -- { 1.5, 1.5, 1.5, -1.5, 4.5, -1.5 },
  374. }
  375. },
  376. paramtype2 = "facedir",
  377. groups = {choppy=1 },
  378. sounds = default.node_sound_wood_defaults(),
  379. on_timer = dcb_node_timer,
  380. on_construct = function(pos)
  381. bitumen.magic.set_collision_nodes(pos, {
  382. {3, -2, 3}, {3, -1, 3},
  383. {3, -2, -3}, {3, -1, -3},
  384. {-3, -2, 3}, {-3, -1, 3},
  385. {-3, -2, -3}, {-3, -1, -3},
  386. {-2, 0, -2}, {-2, 0, -1}, {-2, 0, 0}, {-2, 0, 1}, {-2, 0, 2},
  387. {2, 0, -2}, {2, 0, -1}, {2, 0, 0}, {2, 0, 1}, {2, 0, 2},
  388. {-1, 0, -2}, {0, 0, -2}, {1, 0, -2},
  389. {-1, 0, 2}, {0, 0, 2}, {1, 0, 2},
  390. {0, 9, 0},
  391. {0, 8, 0},
  392. })
  393. bitumen.magic.set_collision_nodes(pos, bitumen.magic.gencube({1, 1, 1}, {1, 7, 1}))
  394. bitumen.magic.set_collision_nodes(pos, bitumen.magic.gencube({1, 1, -1}, {1, 7, -1}))
  395. bitumen.magic.set_collision_nodes(pos, bitumen.magic.gencube({-1, 1, 1}, {-1, 7, 1}))
  396. bitumen.magic.set_collision_nodes(pos, bitumen.magic.gencube({-1, 1, -1}, {-1, 7, -1}))
  397. local controls_delta = {1, 2, 0}
  398. local pipe_chest_delta = {0, 2, 1}
  399. local mud_injector_delta = {0, -1, 0}
  400. local mud_extractor_delta = {0, -2, 0}
  401. bitumen.magic.set_nodes(pos, "bitumen:drill_controls", {controls_delta})
  402. bitumen.magic.set_nodes(pos, "bitumen:drill_pipe_chest", {pipe_chest_delta})
  403. bitumen.magic.set_nodes(pos, "bitumen:drill_mud_injector", {mud_injector_delta})
  404. bitumen.magic.set_nodes(pos, "bitumen:drill_mud_extractor", {mud_extractor_delta})
  405. local function add(p, d)
  406. return {x=p.x + d[1], y=p.y + d[2], z=p.z + d[3]}
  407. end
  408. local altnodes = {
  409. controls = add(pos, controls_delta),
  410. pipe_chest = add(pos, pipe_chest_delta),
  411. mud_injector = add(pos, mud_injector_delta),
  412. mud_extractor = add(pos, mud_extractor_delta),
  413. }
  414. local pcmeta = minetest.get_meta(altnodes.pipe_chest)
  415. local pcinv = pcmeta:get_inventory()
  416. pcinv:set_size("main", 8*32)
  417. local pipe_chest_formspec =
  418. "size[8,9;]" ..
  419. default.gui_bg ..
  420. default.gui_bg_img ..
  421. default.gui_slots ..
  422. "list[context;main;0,0.3;8,4;]" ..
  423. "list[current_player;main;0,4.85;8,1;]" ..
  424. "list[current_player;main;0,6.08;8,3;8]" ..
  425. "listring[context;main]" ..
  426. "listring[current_player;main]" ..
  427. default.get_hotbar_bg(0, 4.85)
  428. pcmeta:set_string("formspec", pipe_chest_formspec)
  429. local state = {
  430. state = "idle",
  431. command = "none",
  432. depth = pos.y - 3, -- depth of the next non-pipe node
  433. max_depth = pos.y - 3,
  434. forceload_oil = false, -- forceload the oil field to make the fluids flow
  435. last_drilled_node = "none"
  436. }
  437. local meta = minetest.get_meta(pos)
  438. meta:set_string("altnodes", minetest.serialize(altnodes))
  439. meta:set_string("state", minetest.serialize(state))
  440. meta:set_string("drilldepth", minetest.serialize(add(pos, {0, -3, 0})))
  441. end,
  442. on_destruct = bitumen.magic.on_destruct,
  443. -- on_punch = function(pos)
  444. -- drill(pos)
  445. -- end,
  446. })
  447. local function get_controls_formspec(state)
  448. local up_down = ""
  449. if state.state == "idle" then
  450. up_down = "button[5,3;4,1;up;Up One]" ..
  451. "button[5,4;4,1;down;Down One]"
  452. end
  453. local stop = ""
  454. if state.state ~= "idle" then
  455. stop = "button[5,0;4,1;stop;Stop]"
  456. end
  457. local drill = ""
  458. if state.state ~= "drilling" then
  459. drill = "button[5,1;4,1;drill;Drill]"
  460. end
  461. local retract= ""
  462. if state.state ~= "retracting" then
  463. retract = "button[5,2;4,1;retract;Retract Pipe]"
  464. end
  465. local forceload= ""
  466. if state.state ~= "forceload" then
  467. forceload = "button[5,3;4,1;forceload;Forceload]"
  468. end
  469. local pump= ""
  470. if state.state ~= "pump" then
  471. pump = "button[5,4;4,1;pump;Pump]"
  472. end
  473. local state_strings = {
  474. drilling = "Drilling",
  475. retracting = "Retracting",
  476. idle = "Idle",
  477. pump = "Pumping",
  478. }
  479. local state_str = state_strings[state.state] or "None"
  480. return "" ..
  481. "size[10,8;]" ..
  482. default.gui_bg ..
  483. default.gui_bg_img ..
  484. default.gui_slots ..
  485. "label[1,1;"..state_str.."]" ..
  486. "label[1,2;Last Node: "..(state.last_drilled_node or "none").."]" ..
  487. "label[1,3;Depth: "..state.depth.."]" ..
  488. stop ..
  489. drill ..
  490. retract ..
  491. up_down ..
  492. forceload ..
  493. pump ..
  494. ""
  495. end
  496. local function retract(pos)
  497. local meta = minetest.get_meta(pos)
  498. local dp = meta:get_string("drilldepth") or ""
  499. if dp == "" then
  500. dp = check_drill_stack(pos)
  501. meta:set_string("drilldepth", minetest.serialize(dp))
  502. else
  503. dp = minetest.deserialize(dp)
  504. --print("deserialized " .. dump(pos))
  505. --dp.y = dp.y - 1
  506. end
  507. local n = minetest.get_node(dp)
  508. if n.name == "ignore" then
  509. if minetest.forceload_block(dp, true) then
  510. print("forceload successful: ".. minetest.pos_to_string(dp))
  511. local n = minetest.get_node(dp)
  512. end
  513. -- minetest.emerge_area(pos, pos)
  514. end
  515. local removed = false
  516. if n.name == "ignore" then
  517. minetest.emerge_area(dp, {x=dp.x, y=dp.y - 20, z=dp.z})
  518. print("emerging " .. minetest.pos_to_string(dp))
  519. return dp.y, false, false
  520. elseif n.name == "bitumen:drill_pipe" then
  521. minetest.set_node(dp, {name = "air"})
  522. removed = true
  523. elseif n.name == "bitumen:drill_mud_injector" or n.name == "bitumen:drill_mud_extractor"then
  524. return dp.y, false, true
  525. else
  526. print("retract at "..dp.y.." of "..n.name )
  527. end
  528. dp.y = dp.y + 1
  529. meta:set_string("drilldepth", minetest.serialize(dp))
  530. return dp.y, removed, false
  531. end
  532. local function pump_oil(pos)
  533. local dp = check_drill_stack(pos)
  534. local n = minetest.get_node(dp)
  535. if n.name == "bitumen:crude_oil" then
  536. minetest.set_node(dp, {name="air"})
  537. pos.x = pos.x + 1
  538. minetest.set_node(pos, {name="bitumen:crude_oil"})
  539. minetest.set_node_level(pos, 64)
  540. end
  541. end
  542. minetest.register_abm({
  543. nodenames = {"bitumen:drill_rig"},
  544. interval = 2,
  545. chance = 1,
  546. action = function(pos, node, active_object_count, active_object_count_wider)
  547. --print("trydrill")
  548. --if 1==1 then return end
  549. local meta = minetest.get_meta(pos)
  550. local state = minetest.deserialize(meta:get_string("state"))
  551. local alts = minetest.deserialize(meta:get_string("altnodes"))
  552. -- print(dump(alts))
  553. if alts == nil then
  554. --print("\n\nnull alts: "..dump(pos).."\n\n")
  555. return
  556. end
  557. local inch = 0
  558. if state.command ~= "none" then
  559. if state.command == "drill" then
  560. state.state = "drilling"
  561. elseif state.command == "retract" then
  562. state.state = "retracting"
  563. elseif state.command == "stop" then
  564. state.state = "idle"
  565. elseif state.command == "pump" then
  566. print("set to pump")
  567. state.state = "pump"
  568. elseif state.command == "explore" then
  569. state.state = "idle"
  570. -- explore extent of oil deposit
  571. elseif state.command == "forceload" then
  572. state.state = "idle"
  573. forceload_deposit({x=pos.x, y = state.depth - 1, z=pos.z})
  574. -- do forceload
  575. elseif state.command == "un_forceload" then
  576. state.state = "idle"
  577. -- undo forceload
  578. elseif state.command == "up" then
  579. state.state = "idle"
  580. inch = 1
  581. elseif state.command == "down" then
  582. state.state = "idle"
  583. inch = -1
  584. end
  585. state.command = "none"
  586. end
  587. local pcmeta, pcinv
  588. if state.state == "drilling" or state.state == "retracting" then
  589. pcmeta = minetest.get_meta(alts.pipe_chest)
  590. pcinv = pcmeta:get_inventory()
  591. end
  592. if state.state == "drilling" or inch == -1 then
  593. local pcmeta = minetest.get_meta(alts.pipe_chest)
  594. local pcinv = pcmeta:get_inventory()
  595. if pcinv:contains_item("main", "bitumen:drill_pipe 1") then
  596. local n, y, hit_oil = drill(pos)
  597. if n then
  598. state.last_drilled_node = n
  599. state.depth = y
  600. state.max_depth = math.min(y, state.max_depth or y)
  601. pcinv:remove_item("main", "bitumen:drill_pipe 1")
  602. if hit_oil and inch == 0 then
  603. state.state = "idle"
  604. end
  605. end
  606. else
  607. -- out of pipe
  608. state.state = "idle"
  609. end
  610. elseif state.state == "retracting" or inch == 1 then
  611. local y, removed, ended
  612. for i = 1,3 do
  613. y, removed, ended = retract(pos)
  614. if removed then
  615. pcinv:add_item("main", "bitumen:drill_pipe")
  616. end
  617. state.depth = y
  618. if ended or inch == 1 then
  619. break
  620. end
  621. end
  622. elseif state.state == "pump" then
  623. local expos = alts.mud_extractor
  624. expos.x = expos.x + 1
  625. local exnet = bitumen.pipes.get_net(expos)
  626. if exnet and (exnet.fluid == "bitumen:crude_oil" or exnet.fluid == "air") then
  627. -- pump oil
  628. local dp = {x=pos.x, y = state.depth - 1, z=pos.z}
  629. local n = minetest.get_node(dp)
  630. if n.name == "bitumen:crude_oil" or n.name == "bitumen:crude_oil_full" then
  631. -- minetest.set_node(dp, {name="air"})
  632. -- local expos = alts.mud_extractor
  633. -- expos.x = expos.x + 1
  634. local p = bitumen.pipes.push_fluid(expos, "bitumen:crude_oil", 15, 20)
  635. --print("pushed " .. p)
  636. end
  637. else
  638. -- must empty the mud out of the pipe first
  639. print("well not connected " .. dump(exnet))
  640. end
  641. end
  642. -- update the control box formspec
  643. local control_meta = minetest.get_meta(alts.controls)
  644. control_meta:set_string("formspec", get_controls_formspec(state))
  645. meta:set_string("state", minetest.serialize(state))
  646. end
  647. })
  648. minetest.register_node("bitumen:well_pump", {
  649. description = "Drill Rig",
  650. tiles = {"default_gold_block.png", "default_steel_block.png", "default_copper_block.png",
  651. "default_tin_block.png", "default_gold_block.png", "default_steel_block.png"},
  652. paramtype2 = "facedir",
  653. groups = {cracky=2, petroleum_fixture=1},
  654. sounds = default.node_sound_wood_defaults(),
  655. can_dig = function(pos,player)
  656. return true
  657. end,
  658. on_timer = dcb_node_timer,
  659. on_punch = function(pos)
  660. pump_oil(pos)
  661. end,
  662. })
  663. local rig_builder_formspec =
  664. "size[10,8;]" ..
  665. default.gui_bg ..
  666. default.gui_bg_img ..
  667. default.gui_slots ..
  668. "list[context;main;0,0.3;4,3;]" ..
  669. "button[5,1;1,4;build;Build]" ..
  670. "list[current_player;main;0,3.85;8,1;]" ..
  671. "list[current_player;main;0,5.08;8,3;8]" ..
  672. "listring[context;main]" ..
  673. "listring[current_player;main]" ..
  674. default.get_hotbar_bg(0, 3.85)
  675. minetest.register_node("bitumen:oil_rig_constructor", {
  676. description = "Oil Rig Constructor",
  677. drawtype = "normal",
  678. paramtype2 = "facedir",
  679. on_rotate = screwdriver.rotate_simple,
  680. groups = {cracky=1},
  681. tiles = {
  682. "default_copper_block.png","default_tin_block.png",
  683. },
  684. on_construct = function(pos)
  685. local meta = minetest.get_meta(pos)
  686. local inv = meta:get_inventory()
  687. inv:set_size("main", 12)
  688. meta:set_string("formspec", rig_builder_formspec);
  689. end,
  690. on_receive_fields = function(pos, form, fields, player)
  691. local meta = minetest.get_meta(pos)
  692. if fields.build then
  693. -- tanks can only be built on thick foundations
  694. --[[
  695. local ret = check_foundation(
  696. {x = pos.x - 9, y = pos.y - 3, z = pos.z - 9},
  697. {x = pos.x + 9, y = pos.y - 1, z = pos.z + 9},
  698. {
  699. ["default:stone"] = 1,
  700. ["bitumen:concrete"] = 1,
  701. }
  702. )
  703. if ret == false then
  704. minetest.chat_send_player(player:get_player_name(), "Foundation is incomplete: 10x10x3")
  705. return
  706. else
  707. minetest.chat_send_player(player:get_player_name(), "Foundation is complete.")
  708. end
  709. ]]
  710. -- local inv = meta:get_inventory();
  711. --
  712. -- if inv:contains_item("main", "default:steelblock 8") then
  713. --
  714. -- inv:remove_item("main", "default:steelblock 8")
  715. -- else
  716. -- minetest.chat_send_player(player:get_player_name(), "Not enough materials: 8x SteelBlock")
  717. -- return
  718. -- end
  719. -- ready to go
  720. minetest.chat_send_player(player:get_player_name(), "Clear area, construction starting...")
  721. minetest.after(5, function()
  722. minetest.set_node({x=pos.x, y=pos.y + 2, z=pos.z}, {name="bitumen:drill_rig"})
  723. end)
  724. end
  725. end,
  726. })
  727. bitumen.register_blueprint({name="bitumen:drill_rig"})
  728. minetest.register_craft({
  729. output = 'bitumen:oil_rig_constructor',
  730. recipe = {
  731. {'default:steelblock', 'default:steelblock', 'default:steelblock'},
  732. {'default:steelblock', 'bitumen:drill_rig_blueprint', 'default:steelblock'},
  733. {'default:steelblock', 'default:steelblock', 'default:steelblock'},
  734. }
  735. })