vertical.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. local vertical_box = {
  2. type = "fixed",
  3. fixed = {-1/16, -8/16, -1/16, 1/16, 8/16, 1/16}
  4. }
  5. local top_box = {
  6. type = "fixed",
  7. fixed = {{-8/16, -8/16, -8/16, 8/16, -7/16, 8/16}}
  8. }
  9. local bottom_box = {
  10. type = "fixed",
  11. fixed = {
  12. {-8/16, -8/16, -8/16, 8/16, -7/16, 8/16},
  13. {-1/16, -7/16, -1/16, 1/16, 8/16, 1/16},
  14. }
  15. }
  16. local vertical_rules = {
  17. {x=0, y=1, z=0},
  18. {x=0, y=-1, z=0}
  19. }
  20. local top_rules = {
  21. {x=1,y=0, z=0},
  22. {x=-1,y=0, z=0},
  23. {x=0,y=0, z=1},
  24. {x=0,y=0, z=-1},
  25. {x=0,y=-1, z=0}
  26. }
  27. local bottom_rules = {
  28. {x=1, y=0, z=0},
  29. {x=-1, y=0, z=0},
  30. {x=0, y=0, z=1},
  31. {x=0, y=0, z=-1},
  32. {x=0, y=1, z=0},
  33. {x=0, y=2, z=0} -- receive power from pressure plate / detector / ... 2 nodes above
  34. }
  35. local vertical_updatepos = function (pos)
  36. local node = minetest.get_node(pos)
  37. if minetest.registered_nodes[node.name]
  38. and minetest.registered_nodes[node.name].is_vertical_conductor then
  39. local node_above = minetest.get_node(vector.add(pos, vertical_rules[1]))
  40. local node_below = minetest.get_node(vector.add(pos, vertical_rules[2]))
  41. local above = minetest.registered_nodes[node_above.name]
  42. and minetest.registered_nodes[node_above.name].is_vertical_conductor
  43. local below = minetest.registered_nodes[node_below.name]
  44. and minetest.registered_nodes[node_below.name].is_vertical_conductor
  45. mesecon.on_dignode(pos, node)
  46. -- Always place offstate conductor and let mesecon.on_placenode take care
  47. local newname = "mesecons_extrawires:vertical_"
  48. if above and below then -- above and below: vertical mesecon
  49. newname = newname .. "off"
  50. elseif above and not below then -- above only: bottom
  51. newname = newname .. "bottom_off"
  52. elseif not above and below then -- below only: top
  53. newname = newname .. "top_off"
  54. else -- no vertical wire above, no vertical wire below: use bottom
  55. newname = newname .. "bottom_off"
  56. end
  57. minetest.set_node(pos, {name = newname})
  58. mesecon.on_placenode(pos, {name = newname})
  59. end
  60. end
  61. local vertical_update = function (pos, node)
  62. vertical_updatepos(pos) -- this one
  63. vertical_updatepos(vector.add(pos, vertical_rules[1])) -- above
  64. vertical_updatepos(vector.add(pos, vertical_rules[2])) -- below
  65. end
  66. -- Vertical wire
  67. mesecon.register_node("mesecons_extrawires:vertical", {
  68. description = "Vertical Mesecon",
  69. drawtype = "nodebox",
  70. walkable = false,
  71. paramtype = "light",
  72. is_ground_content = false,
  73. sunlight_propagates = true,
  74. selection_box = vertical_box,
  75. node_box = vertical_box,
  76. is_vertical_conductor = true,
  77. drop = "mesecons_extrawires:vertical_off",
  78. after_place_node = vertical_update,
  79. after_dig_node = vertical_update
  80. },{
  81. tiles = {"mesecons_wire_off.png"},
  82. groups = {dig_immediate=3},
  83. mesecons = {conductor = {
  84. state = mesecon.state.off,
  85. onstate = "mesecons_extrawires:vertical_on",
  86. rules = vertical_rules,
  87. }}
  88. },{
  89. tiles = {"mesecons_wire_on.png"},
  90. groups = {dig_immediate=3, not_in_creative_inventory=1},
  91. mesecons = {conductor = {
  92. state = mesecon.state.on,
  93. offstate = "mesecons_extrawires:vertical_off",
  94. rules = vertical_rules,
  95. }}
  96. })
  97. -- Vertical wire top
  98. mesecon.register_node("mesecons_extrawires:vertical_top", {
  99. description = "Vertical mesecon",
  100. drawtype = "nodebox",
  101. walkable = false,
  102. paramtype = "light",
  103. is_ground_content = false,
  104. sunlight_propagates = true,
  105. groups = {dig_immediate=3, not_in_creative_inventory=1},
  106. selection_box = top_box,
  107. node_box = top_box,
  108. is_vertical_conductor = true,
  109. drop = "mesecons_extrawires:vertical_off",
  110. after_place_node = vertical_update,
  111. after_dig_node = vertical_update
  112. },{
  113. tiles = {"mesecons_wire_off.png"},
  114. mesecons = {conductor = {
  115. state = mesecon.state.off,
  116. onstate = "mesecons_extrawires:vertical_top_on",
  117. rules = top_rules,
  118. }}
  119. },{
  120. tiles = {"mesecons_wire_on.png"},
  121. mesecons = {conductor = {
  122. state = mesecon.state.on,
  123. offstate = "mesecons_extrawires:vertical_top_off",
  124. rules = top_rules,
  125. }}
  126. })
  127. -- Vertical wire bottom
  128. mesecon.register_node("mesecons_extrawires:vertical_bottom", {
  129. description = "Vertical mesecon",
  130. drawtype = "nodebox",
  131. walkable = false,
  132. paramtype = "light",
  133. is_ground_content = false,
  134. sunlight_propagates = true,
  135. groups = {dig_immediate = 3, not_in_creative_inventory = 1},
  136. selection_box = bottom_box,
  137. node_box = bottom_box,
  138. is_vertical_conductor = true,
  139. drop = "mesecons_extrawires:vertical_off",
  140. after_place_node = vertical_update,
  141. after_dig_node = vertical_update
  142. },{
  143. tiles = {"mesecons_wire_off.png"},
  144. mesecons = {conductor = {
  145. state = mesecon.state.off,
  146. onstate = "mesecons_extrawires:vertical_bottom_on",
  147. rules = bottom_rules,
  148. }}
  149. },{
  150. tiles = {"mesecons_wire_on.png"},
  151. mesecons = {conductor = {
  152. state = mesecon.state.on,
  153. offstate = "mesecons_extrawires:vertical_bottom_off",
  154. rules = bottom_rules,
  155. }}
  156. })
  157. minetest.register_craft({
  158. output = "mesecons_extrawires:vertical_off 3",
  159. recipe = {
  160. {"mesecons:wire_00000000_off"},
  161. {"mesecons:wire_00000000_off"},
  162. {"mesecons:wire_00000000_off"}
  163. }
  164. })
  165. minetest.register_craft({
  166. output = "mesecons:wire_00000000_off",
  167. recipe = {{"mesecons_extrawires:vertical_off"}}
  168. })