You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

259 lines
6.9KB

  1. -- This file supplies the steel pipes
  2. local S = minetest.get_translator("pipeworks")
  3. local REGISTER_COMPATIBILITY = true
  4. local pipes_empty_nodenames = {}
  5. local pipes_full_nodenames = {}
  6. local new_flow_logic_register = pipeworks.flowables.register
  7. local polys = ""
  8. if pipeworks.enable_lowpoly then polys = "_lowpoly" end
  9. local vti = {4, 3, 2, 1, 6, 5}
  10. local cconnects = {{}, {1}, {1, 2}, {1, 3}, {1, 3, 5}, {1, 2, 3}, {1, 2, 3, 5}, {1, 2, 3, 4}, {1, 2, 3, 4, 5}, {1, 2, 3, 4, 5, 6}}
  11. for index, connects in ipairs(cconnects) do
  12. local outsel = {}
  13. local jx = 0
  14. local jy = 0
  15. local jz = 0
  16. for _, v in ipairs(connects) do
  17. if v == 1 or v == 2 then
  18. jx = jx + 1
  19. elseif v == 3 or v == 4 then
  20. jy = jy + 1
  21. else
  22. jz = jz + 1
  23. end
  24. table.insert(outsel, pipeworks.pipe_selectboxes[v])
  25. end
  26. if #connects == 1 then
  27. local v = connects[1]
  28. v = v-1 + 2*(v%2) -- Opposite side
  29. end
  30. local pgroups = {snappy = 3, pipe = 1, not_in_creative_inventory = 1}
  31. local pipedesc = S("Pipe Segment").." "..dump(connects)
  32. if #connects == 0 then
  33. pgroups = {snappy = 3, tube = 1}
  34. pipedesc = S("Pipe Segment")
  35. end
  36. local outimg_e = { "pipeworks_pipe_plain.png" }
  37. local outimg_l = { "pipeworks_pipe_plain.png" }
  38. if index == 3 then
  39. outimg_e = { "pipeworks_pipe_3_empty.png" }
  40. outimg_l = { "pipeworks_pipe_3_loaded.png" }
  41. end
  42. local mesh = "pipeworks_pipe_"..index..polys..".obj"
  43. if index == 1 then
  44. mesh = "pipeworks_pipe_3"..polys..".obj"
  45. end
  46. minetest.register_node("pipeworks:pipe_"..index.."_empty", {
  47. description = pipedesc,
  48. drawtype = "mesh",
  49. mesh = mesh,
  50. tiles = outimg_e,
  51. sunlight_propagates = true,
  52. paramtype = "light",
  53. paramtype2 = "facedir",
  54. selection_box = {
  55. type = "fixed",
  56. fixed = outsel
  57. },
  58. collision_box = {
  59. type = "fixed",
  60. fixed = outsel
  61. },
  62. groups = pgroups,
  63. sounds = default.node_sound_metal_defaults(),
  64. walkable = true,
  65. drop = "pipeworks:pipe_1_empty",
  66. after_place_node = function(pos)
  67. pipeworks.scan_for_pipe_objects(pos)
  68. end,
  69. after_dig_node = function(pos)
  70. pipeworks.scan_for_pipe_objects(pos)
  71. end,
  72. on_rotate = false,
  73. check_for_pole = pipeworks.check_for_vert_pipe,
  74. check_for_horiz_pole = pipeworks.check_for_horiz_pipe,
  75. pipenumber = index
  76. })
  77. local pgroups = {snappy = 3, pipe = 1, not_in_creative_inventory = 1}
  78. minetest.register_node("pipeworks:pipe_"..index.."_loaded", {
  79. description = pipedesc,
  80. drawtype = "mesh",
  81. mesh = mesh,
  82. tiles = outimg_l,
  83. sunlight_propagates = true,
  84. paramtype = "light",
  85. paramtype2 = "facedir",
  86. selection_box = {
  87. type = "fixed",
  88. fixed = outsel
  89. },
  90. collision_box = {
  91. type = "fixed",
  92. fixed = outsel
  93. },
  94. groups = pgroups,
  95. sounds = default.node_sound_metal_defaults(),
  96. walkable = true,
  97. drop = "pipeworks:pipe_1_empty",
  98. after_place_node = function(pos)
  99. minetest.set_node(pos, { name = "pipeworks:pipe_"..index.."_empty" })
  100. pipeworks.scan_for_pipe_objects(pos)
  101. end,
  102. after_dig_node = function(pos)
  103. pipeworks.scan_for_pipe_objects(pos)
  104. end,
  105. on_rotate = false,
  106. check_for_pole = pipeworks.check_for_vert_pipe,
  107. check_for_horiz_pole = pipeworks.check_for_horiz_pipe,
  108. pipenumber = index
  109. })
  110. local emptypipe = "pipeworks:pipe_"..index.."_empty"
  111. local fullpipe = "pipeworks:pipe_"..index.."_loaded"
  112. table.insert(pipes_empty_nodenames, emptypipe)
  113. table.insert(pipes_full_nodenames, fullpipe)
  114. new_flow_logic_register.simple(emptypipe)
  115. new_flow_logic_register.simple(fullpipe)
  116. end
  117. if REGISTER_COMPATIBILITY then
  118. local cempty = "pipeworks:pipe_compatibility_empty"
  119. local cloaded = "pipeworks:pipe_compatibility_loaded"
  120. minetest.register_node(cempty, {
  121. drawtype = "airlike",
  122. sunlight_propagates = true,
  123. paramtype = "light",
  124. description = S("Pipe Segment (legacy)"),
  125. groups = {not_in_creative_inventory = 1, pipe_to_update = 1},
  126. drop = "pipeworks:pipe_1_empty",
  127. after_place_node = function(pos)
  128. pipeworks.scan_for_pipe_objects(pos)
  129. end,
  130. on_rotate = false
  131. })
  132. minetest.register_node(cloaded, {
  133. drawtype = "airlike",
  134. sunlight_propagates = true,
  135. paramtype = "light",
  136. groups = {not_in_creative_inventory = 1, pipe_to_update = 1},
  137. drop = "pipeworks:pipe_1_empty",
  138. after_place_node = function(pos)
  139. pipeworks.scan_for_pipe_objects(pos)
  140. end,
  141. on_rotate = false
  142. })
  143. for xm = 0, 1 do
  144. for xp = 0, 1 do
  145. for ym = 0, 1 do
  146. for yp = 0, 1 do
  147. for zm = 0, 1 do
  148. for zp = 0, 1 do
  149. local pname = xm..xp..ym..yp..zm..zp
  150. minetest.register_alias("pipeworks:pipe_"..pname.."_empty", cempty)
  151. minetest.register_alias("pipeworks:pipe_"..pname.."_loaded", cloaded)
  152. end
  153. end
  154. end
  155. end
  156. end
  157. end
  158. minetest.register_abm({
  159. nodenames = {"group:pipe_to_update"},
  160. interval = 1,
  161. chance = 1,
  162. action = function(pos, node, active_object_count, active_object_count_wider)
  163. local minp = {x = pos.x-1, y = pos.y-1, z = pos.z-1}
  164. local maxp = {x = pos.x+1, y = pos.y+1, z = pos.z+1}
  165. if table.getn(minetest.find_nodes_in_area(minp, maxp, "ignore")) == 0 then
  166. pipeworks.scan_for_pipe_objects(pos)
  167. end
  168. end
  169. })
  170. end
  171. local valve_on = "pipeworks:valve_on_empty"
  172. local valve_off = "pipeworks:valve_off_empty"
  173. local entry_panel_empty = "pipeworks:entry_panel_empty"
  174. local flow_sensor_empty = "pipeworks:flow_sensor_empty"
  175. local sp_empty = "pipeworks:straight_pipe_empty"
  176. -- XXX: why aren't these in devices.lua!?
  177. table.insert(pipes_empty_nodenames, valve_on)
  178. table.insert(pipes_empty_nodenames, valve_off)
  179. table.insert(pipes_empty_nodenames, entry_panel_empty)
  180. table.insert(pipes_empty_nodenames, flow_sensor_empty)
  181. table.insert(pipes_empty_nodenames, sp_empty)
  182. local valve_on_loaded = "pipeworks:valve_on_loaded"
  183. local entry_panel_loaded = "pipeworks:entry_panel_loaded"
  184. local flow_sensor_loaded = "pipeworks:flow_sensor_loaded"
  185. local sp_loaded = "pipeworks:straight_pipe_loaded"
  186. table.insert(pipes_full_nodenames, valve_on_loaded)
  187. table.insert(pipes_full_nodenames, entry_panel_loaded)
  188. table.insert(pipes_full_nodenames, flow_sensor_loaded)
  189. table.insert(pipes_full_nodenames, sp_loaded)
  190. pipeworks.pipes_full_nodenames = pipes_full_nodenames
  191. pipeworks.pipes_empty_nodenames = pipes_empty_nodenames
  192. if pipeworks.toggles.pipe_mode == "classic" then
  193. minetest.register_abm({
  194. nodenames = pipes_empty_nodenames,
  195. interval = 1,
  196. chance = 1,
  197. action = function(pos, node, active_object_count, active_object_count_wider)
  198. pipeworks.check_for_inflows(pos,node)
  199. end
  200. })
  201. minetest.register_abm({
  202. nodenames = pipes_full_nodenames,
  203. interval = 1,
  204. chance = 1,
  205. action = function(pos, node, active_object_count, active_object_count_wider)
  206. pipeworks.check_sources(pos,node)
  207. end
  208. })
  209. minetest.register_abm({
  210. nodenames = {"pipeworks:spigot","pipeworks:spigot_pouring"},
  211. interval = 1,
  212. chance = 1,
  213. action = function(pos, node, active_object_count, active_object_count_wider)
  214. pipeworks.spigot_check(pos,node)
  215. end
  216. })
  217. minetest.register_abm({
  218. nodenames = {"pipeworks:fountainhead","pipeworks:fountainhead_pouring"},
  219. interval = 1,
  220. chance = 1,
  221. action = function(pos, node, active_object_count, active_object_count_wider)
  222. pipeworks.fountainhead_check(pos,node)
  223. end
  224. })
  225. end