sphere_tank.lua 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. local tank_builder_formspec =
  2. "size[10,8;]" ..
  3. default.gui_bg ..
  4. default.gui_bg_img ..
  5. default.gui_slots ..
  6. "list[context;main;0,0.3;4,3;]" ..
  7. "button[5,1;1,4;build;Build]" ..
  8. "list[current_player;main;0,3.85;8,1;]" ..
  9. "list[current_player;main;0,5.08;8,3;8]" ..
  10. "listring[context;main]" ..
  11. "listring[current_player;main]" ..
  12. default.get_hotbar_bg(0, 3.85)
  13. minetest.register_node("bitumen:sphere_tank_constructor", {
  14. description = "Spherical Tank Constructor",
  15. drawtype = "normal",
  16. paramtype2 = "facedir",
  17. on_rotate = screwdriver.rotate_simple,
  18. groups = {cracky=1},
  19. tiles = {
  20. "default_copper_block.png","default_tin_block.png",
  21. },
  22. on_construct = function(pos)
  23. local meta = minetest.get_meta(pos)
  24. local inv = meta:get_inventory()
  25. inv:set_size("main", 12)
  26. meta:set_string("formspec", tank_builder_formspec);
  27. end,
  28. on_receive_fields = function(pos, form, fields, player)
  29. local meta = minetest.get_meta(pos)
  30. if fields.build then
  31. -- tanks can only be built on thick foundations
  32. local ret = bitumen.check_foundation(
  33. {x = pos.x - 9, y = pos.y - 3, z = pos.z - 9},
  34. {x = pos.x + 9, y = pos.y - 1, z = pos.z + 9},
  35. {
  36. ["default:stone"] = 1,
  37. ["bitumen:concrete"] = 1,
  38. }
  39. )
  40. if ret == false then
  41. minetest.chat_send_player(player:get_player_name(), "Foundation is incomplete: 10x10x3")
  42. return
  43. else
  44. minetest.chat_send_player(player:get_player_name(), "Foundation is complete.")
  45. end
  46. local inv = meta:get_inventory();
  47. if inv:contains_item("main", "default:steelblock 15") and
  48. inv:contains_item("main", "default:coal 20") then
  49. inv:remove_item("main", "default:steelblock 15")
  50. inv:remove_item("main", "default:coal_lump 20")
  51. else
  52. minetest.chat_send_player(player:get_player_name(), "Not enough materials: 15x SteelBlock, 20x Coal Lump")
  53. return
  54. end
  55. -- ready to go
  56. minetest.chat_send_player(player:get_player_name(), "Clear area, construction starting...")
  57. minetest.after(5, function()
  58. minetest.set_node(pos, {name="bitumen:sphere_tank"})
  59. end)
  60. end
  61. end,
  62. })
  63. minetest.register_craft({
  64. output = 'bitumen:sphere_tank_constructor',
  65. recipe = {
  66. {'default:steelblock', 'default:steelblock', 'default:steelblock'},
  67. {'default:steelblock', 'vessels:steel_bottle', 'default:steelblock'},
  68. {'default:steelblock', 'default:steelblock', 'default:steelblock'},
  69. }
  70. })
  71. minetest.register_node("bitumen:sphere_tank", {
  72. paramtype = "light",
  73. drawtype = "mesh",
  74. mesh = "sphere.obj",
  75. description = "Spherical Tank",
  76. tiles = {
  77. "default_snow.png",
  78. },
  79. inventory_image = "default_snow.png",
  80. selection_box = {
  81. type = "fixed",
  82. fixed = {
  83. { -.5, -.5, -.5, .5, 1.5, .5 },
  84. -- { -8.2, -.5, -.2, -7.8, 10, .2 },
  85. -- { -.2, -.5, -8.2, .2, 10, -7.8 },
  86. -- { 8.2, -.5, -.2, 7.8, 10, .2 },
  87. -- { -.2, -.5, 8.2, .2, 10, 7.8 },
  88. },
  89. },
  90. collision_box = {
  91. type = "fixed",
  92. fixed = {
  93. { -.5, -.5, -.5, .5, 1.5, .5 },
  94. }
  95. },
  96. paramtype2 = "facedir",
  97. groups = {choppy=1, petroleum_fixture=1},
  98. sounds = default.node_sound_wood_defaults(),
  99. on_construct = function(pos)
  100. local meta = minetest.get_meta(pos)
  101. if placer then
  102. local owner = placer:get_player_name()
  103. meta:set_string("owner", owner)
  104. end
  105. meta:set_float("fluid_level", 0)
  106. meta:set_float("capacity", math.floor(3.14159 * .75 * 9 * 9 * 9 * 64))
  107. meta:set_string("infotext", "0%")
  108. bitumen.magic.set_collision_nodes(pos, gensphere({0, 11, 0}, 9.99))
  109. bitumen.magic.set_collision_nodes(pos, gencube({8, 0, 0}, {8, 8, 0}))
  110. bitumen.magic.set_collision_nodes(pos, gencube({0, 0, 8}, {0, 8, 8}))
  111. bitumen.magic.set_collision_nodes(pos, gencube({-8, 0, 0}, {-8, 8, 0}))
  112. bitumen.magic.set_collision_nodes(pos, gencube({0, 0, -8}, {0, 8, -8}))
  113. bitumen.magic.set_collision_nodes(pos, gencube({-6, 0, -6}, {-6, 8, -6}))
  114. bitumen.magic.set_collision_nodes(pos, gencube({6, 0, -6}, {6, 8, -6}))
  115. bitumen.magic.set_collision_nodes(pos, gencube({-6, 0, 6}, {-6, 8, 6}))
  116. bitumen.magic.set_collision_nodes(pos, gencube({6, 0, 6}, {6, 8, 6}))
  117. --]]
  118. bitumen.pipes.on_construct(pos)
  119. end,
  120. on_destruct = bitumen.magic.on_destruct,
  121. can_dig = function(pos, player)
  122. local meta = minetest.get_meta(pos);
  123. local owner = meta:get_string("owner")
  124. local fluid_level = meta:get_float("fluid_level") or 0
  125. return player:get_player_name() ~= owner and fluid_level <= 0.01
  126. end,
  127. })
  128. minetest.register_abm({
  129. nodenames = {"bitumen:sphere_tank"},
  130. interval = 1,
  131. chance = 1,
  132. action = function(pos)
  133. local meta = minetest.get_meta(pos)
  134. local fluid = meta:get_string("fluid") or "air"
  135. local capacity = meta:get_float("capacity") or 109000
  136. local fill = meta:get_float("fill_level") or 0
  137. -- print("tank fill: ".. fill .. " " ..capacity )
  138. local rem_capacity = capacity - fill
  139. local can_change = fill <= 0.01
  140. local pres = (fill / capacity) * 20 -- the tank is roughly 20 nodes tall, nevermind the sphere part
  141. local cap_take = math.min(rem_capacity, 60)
  142. local delta, new_fluid = bitumen.pipes.buffer(pos, fluid, pres, fill, cap_take, can_change)
  143. -- print("delta ".. delta .. " " .. new_fluid)
  144. if delta > 0.01 or delta < -0.01 then
  145. meta:set_float("fill_level", math.max(math.min(capacity, delta + fill), 0))
  146. meta:set_string("fluid", new_fluid)
  147. end
  148. -- print("")
  149. end
  150. })