wells.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. minetest.register_node("springs:well_pipe", {
  2. description = "Well Pipe Section",
  3. drawtype = "nodebox",
  4. node_box = {
  5. type = "fixed",
  6. fixed = {
  7. -- pump bar
  8. {-.05, .5, -.05, .05, .65, .05 },
  9. -- casing
  10. {-.2, -.5, -.2, .2, .5, .2 },
  11. {-.10, -.5, -.25, .10, .5, .25 },
  12. {-.25, -.5, -.10, .25, .5, .10 },
  13. },
  14. },
  15. paramtype = "light",
  16. is_ground_content = false,
  17. tiles = { "default_steel_block.png" },
  18. walkable = true,
  19. groups = { cracky = 3 },
  20. })
  21. local function check_well_pipe(pos)
  22. end
  23. minetest.register_node("springs:well_head", {
  24. description = "Well Head",
  25. drawtype = "connected",
  26. node_box = {
  27. type = "fixed",
  28. fixed = {
  29. -- housing
  30. {-.3, -.3, -.3, .3, .3, .3 },
  31. -- casing
  32. {-.2, -.5, -.2, .2, 0, .2 },
  33. {-.10, -.5, -.25, .10, 0, .25 },
  34. {-.25, -.5, -.10, .25, 0, .10 },
  35. },
  36. connect_front = {{-.1, -.1, -.5, .1, .1, .1}},
  37. connect_left = {{-.5, -.1, -.1, -.1, .1, .1}},
  38. connect_back = {{-.1, -.1, .1, .1, .1, .5}},
  39. connect_right = {{ .1, -.1, -.1, .5, .1, .1}},
  40. },
  41. connects_to = { "group:water_pipe" },
  42. paramtype = "light",
  43. is_ground_content = false,
  44. tiles = { "default_steel_block.png" },
  45. walkable = true,
  46. groups = { cracky = 3, water_fixture = 1 },
  47. on_punch = function(pos)
  48. ----local node = minetest.get_node(pos)
  49. --local n = math.min(8, i + 1)
  50. --minetest.set_node(pos, {name = "springs:sluice_gate_"..n, param2 = node.param2})
  51. end,
  52. on_construct = function(pos)
  53. print("\nwell head placed at "..pos.x..","..pos.y..","..pos.z)
  54. local hash = minetest.hash_node_position(pos)
  55. local merge_list = {}
  56. local current_net = nil
  57. local found_net = 0
  58. local check_net = function(npos)
  59. local nhash = minetest.hash_node_position(npos)
  60. local nphash = net_members[nhash]
  61. if nphash ~= nil then
  62. local pnet = networks[nphash]
  63. if nil == current_net then
  64. print("joining existing network: ".. pnet.name)
  65. net_members[hash] = nphash
  66. current_net = nphash
  67. pnet.count = pnet.count + 1
  68. pnet.inputs[hash] = 1
  69. table.insert(merge_list, pnet)
  70. elseif current_net == nphash then
  71. print("alternate connection to existing network")
  72. else
  73. print("found seconday network: "..pnet.name)
  74. table.insert(merge_list, pnet)
  75. end
  76. found_net = 1
  77. end
  78. end
  79. check_net({x=pos.x, y=pos.y - 1, z=pos.z})
  80. check_net({x=pos.x, y=pos.y + 1, z=pos.z})
  81. check_net({x=pos.x, y=pos.y, z=pos.z + 1})
  82. check_net({x=pos.x, y=pos.y, z=pos.z - 1})
  83. if found_net == 0 then
  84. print("new network: hash: ".. hash .." name: " ..netname);
  85. networks[hash] = {
  86. hash = hash,
  87. pos = {x=pos.x, y=pos.y, z=pos.z},
  88. name = netname,
  89. count = 1,
  90. inputs = {
  91. [hash] = 1,
  92. },
  93. outputs = {},
  94. buffer = 0,
  95. }
  96. net_members[hash] = hash
  97. netname = netname + 1
  98. end
  99. if #merge_list > 1 then
  100. print("\n merging "..#merge_list.." networks")
  101. local biggest = {count = 0}
  102. local mlookup = {}
  103. for _,n in ipairs(merge_list) do
  104. mlookup[n.hash] = 1
  105. if n.count > biggest.count then
  106. biggest = n
  107. end
  108. end
  109. mlookup[biggest.hash] = 0
  110. for k,v in pairs(net_members) do
  111. if mlookup[v] == 1 then
  112. net_members[k] = biggest.hash
  113. end
  114. end
  115. for _,n in ipairs(merge_list) do
  116. if n.hash ~= biggest.hash then
  117. biggest.count = biggest.count + n.count
  118. n.count = 0
  119. end
  120. end
  121. end
  122. save_data()
  123. end
  124. })