vertical.lua 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. local vbox = {
  2. type = "fixed",
  3. fixed = {-1/16, -.5, -1/16, 1/16, .5, 1/16}
  4. }
  5. local tbox = {
  6. type = "fixed",
  7. fixed = {{-.5, -.5, -.5, .5, -.5 + 1/16, .5}}
  8. }
  9. local bbox = {
  10. type = "fixed",
  11. fixed = {{ -.5, -.5 , -.5, .5, -.5+1/16, .5},
  12. {-1/16, -.5+1/16, -1/16, 1/16, .5 , 1/16}}
  13. }
  14. local vrules =
  15. {{x = 0, y = 1, z = 0},
  16. {x = 0, y =-1, z = 0}}
  17. local trules =
  18. {{x = 1, y = 0, z = 0},
  19. {x =-1, y = 0, z = 0},
  20. {x = 0, y = 0, z = 1},
  21. {x = 0, y = 0, z =-1},
  22. {x = 0, y =-1, z = 0}}
  23. local brules =
  24. {{x = 1, y = 0, z = 0},
  25. {x =-1, y = 0, z = 0},
  26. {x = 0, y = 0, z = 1},
  27. {x = 0, y = 0, z =-1},
  28. {x = 0, y = 1, z = 0}}
  29. local vertical_updatepos = function (pos)
  30. local node = minetest.env:get_node(pos)
  31. if minetest.registered_nodes[node.name].is_vertical_conductor then
  32. local node_above = minetest.env:get_node(mesecon:addPosRule(pos, vrules[1]))
  33. local node_below = minetest.env:get_node(mesecon:addPosRule(pos, vrules[2]))
  34. local namestate = minetest.registered_nodes[node.name].vertical_conductor_state
  35. -- above and below: vertical mesecon
  36. if minetest.registered_nodes[node_above.name].is_vertical_conductor
  37. and minetest.registered_nodes[node_below.name].is_vertical_conductor then
  38. minetest.env:add_node (pos,
  39. {name = "mesecons_extrawires:vertical_"..namestate})
  40. -- above only: bottom
  41. elseif minetest.registered_nodes[node_above.name].is_vertical_conductor
  42. and not minetest.registered_nodes[node_below.name].is_vertical_conductor then
  43. minetest.env:add_node (pos,
  44. {name = "mesecons_extrawires:vertical_bottom_"..namestate})
  45. -- below only: top
  46. elseif not minetest.registered_nodes[node_above.name].is_vertical_conductor
  47. and minetest.registered_nodes[node_below.name].is_vertical_conductor then
  48. minetest.env:add_node (pos,
  49. {name = "mesecons_extrawires:vertical_top_"..namestate})
  50. else -- no vertical wire above, no vertical wire below: use default wire
  51. minetest.env:add_node (pos,
  52. {name = "mesecons_extrawires:vertical_"..namestate})
  53. end
  54. end
  55. end
  56. local vertical_update = function (pos, node)
  57. vertical_updatepos(pos) -- this one
  58. vertical_updatepos(mesecon:addPosRule(pos, vrules[1])) -- above
  59. vertical_updatepos(mesecon:addPosRule(pos, vrules[2])) -- below
  60. end
  61. -- Vertical wire
  62. minetest.register_node("mesecons_extrawires:vertical_on", {
  63. description = "Vertical mesecon",
  64. drawtype = "nodebox",
  65. tiles = {"wires_vertical_on.png"},
  66. walkable = false,
  67. paramtype = "light",
  68. sunlight_propagates = true,
  69. groups = {dig_immediate = 3, not_in_creative_inventory = 1},
  70. selection_box = vbox,
  71. node_box = vbox,
  72. is_vertical_conductor = true,
  73. vertical_conductor_state = "on",
  74. mesecons = {conductor = {
  75. state = mesecon.state.on,
  76. offstate = "mesecons_extrawires:vertical_off",
  77. rules = vrules
  78. }},
  79. drop = {"mesecons_extrawires:vertical_off"},
  80. after_place_node = vertical_update,
  81. after_dig_node = vertical_update
  82. })
  83. minetest.register_node("mesecons_extrawires:vertical_off", {
  84. description = "Vertical mesecon",
  85. drawtype = "nodebox",
  86. tiles = {"wires_vertical_off.png"},
  87. walkable = false,
  88. paramtype = "light",
  89. sunlight_propagates = true,
  90. groups = {dig_immediate = 3},
  91. selection_box = vbox,
  92. node_box = vbox,
  93. is_vertical_conductor = true,
  94. vertical_conductor_state = "off",
  95. mesecons = {conductor = {
  96. state = mesecon.state.off,
  97. onstate = "mesecons_extrawires:vertical_on",
  98. rules = vrules
  99. }},
  100. after_place_node = vertical_update,
  101. after_dig_node = vertical_update
  102. })
  103. -- Vertical wire top
  104. minetest.register_node("mesecons_extrawires:vertical_top_on", {
  105. description = "Vertical mesecon",
  106. drawtype = "nodebox",
  107. tiles = {"wires_full_on.png"},
  108. walkable = false,
  109. paramtype = "light",
  110. sunlight_propagates = true,
  111. groups = {dig_immediate = 3, not_in_creative_inventory = 1},
  112. selection_box = tbox,
  113. node_box = tbox,
  114. is_vertical_conductor = true,
  115. vertical_conductor_state = "on",
  116. mesecons = {conductor = {
  117. state = mesecon.state.on,
  118. offstate = "mesecons_extrawires:vertical_top_off",
  119. rules = trules
  120. }},
  121. drop = {"mesecons_extrawires:vertical_off"},
  122. after_place_node = vertical_update,
  123. after_dig_node = vertical_update
  124. })
  125. minetest.register_node("mesecons_extrawires:vertical_top_off", {
  126. description = "Vertical mesecon",
  127. drawtype = "nodebox",
  128. tiles = {"wires_full_off.png"},
  129. walkable = false,
  130. paramtype = "light",
  131. sunlight_propagates = true,
  132. groups = {dig_immediate = 3, not_in_creative_inventory = 1},
  133. selection_box = tbox,
  134. node_box = tbox,
  135. is_vertical_conductor = true,
  136. vertical_conductor_state = "off",
  137. mesecons = {conductor = {
  138. state = mesecon.state.off,
  139. onstate = "mesecons_extrawires:vertical_top_on",
  140. rules = trules
  141. }},
  142. drop = {"mesecons_extrawires:vertical_off"},
  143. after_place_node = vertical_update,
  144. after_dig_node = vertical_update
  145. })
  146. -- Vertical wire bottom
  147. minetest.register_node("mesecons_extrawires:vertical_bottom_on", {
  148. description = "Vertical mesecon",
  149. drawtype = "nodebox",
  150. tiles = {"wires_full_on.png"},
  151. walkable = false,
  152. paramtype = "light",
  153. sunlight_propagates = true,
  154. vertical_conductor_state = "on",
  155. groups = {dig_immediate = 3, not_in_creative_inventory = 1},
  156. selection_box = bbox,
  157. node_box = bbox,
  158. mesecons = {conductor = {
  159. state = mesecon.state.on,
  160. offstate = "mesecons_extrawires:vertical_bottom_off",
  161. rules = brules
  162. }},
  163. drop = {"mesecons_extrawires:vertical_off"},
  164. after_place_node = vertical_update,
  165. after_dig_node = vertical_update
  166. })
  167. minetest.register_node("mesecons_extrawires:vertical_bottom_off", {
  168. description = "Vertical mesecon",
  169. drawtype = "nodebox",
  170. tiles = {"wires_full_off.png"},
  171. walkable = false,
  172. paramtype = "light",
  173. sunlight_propagates = true,
  174. groups = {dig_immediate = 3, not_in_creative_inventory = 1},
  175. selection_box = bbox,
  176. node_box = bbox,
  177. is_vertical_conductor = true,
  178. vertical_conductor_state = "off",
  179. mesecons = {conductor = {
  180. state = mesecon.state.off,
  181. onstate = "mesecons_extrawires:vertical_bottom_on",
  182. rules = brules
  183. }},
  184. drop = {"mesecons_extrawires:vertical_off"},
  185. after_place_node = vertical_update,
  186. after_dig_node = vertical_update
  187. })