signal_tubes.lua 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. local S = minetest.get_translator("pipeworks")
  2. if pipeworks.enable_detector_tube then
  3. local detector_tube_step = 5 * tonumber(minetest.settings:get("dedicated_server_step"))
  4. pipeworks.register_tube("pipeworks:detector_tube_on", {
  5. description = S("Detecting Pneumatic Tube Segment on"),
  6. inventory_image = "pipeworks_detector_tube_inv.png",
  7. plain = { "pipeworks_detector_tube_plain.png" },
  8. node_def = {
  9. tube = {can_go = function(pos, node, velocity, stack)
  10. local meta = minetest.get_meta(pos)
  11. local name = minetest.get_node(pos).name
  12. local nitems = meta:get_int("nitems")+1
  13. meta:set_int("nitems", nitems)
  14. local saved_pos = vector.new(pos)
  15. minetest.after(detector_tube_step, minetest.registered_nodes[name].item_exit, saved_pos)
  16. return pipeworks.notvel(pipeworks.meseadjlist,velocity)
  17. end},
  18. groups = {mesecon = 2, not_in_creative_inventory = 1},
  19. drop = "pipeworks:detector_tube_off_1",
  20. mesecons = {receptor = {state = "on", rules = pipeworks.mesecons_rules}},
  21. item_exit = function(pos)
  22. local meta = minetest.get_meta(pos)
  23. local nitems = meta:get_int("nitems")-1
  24. local node = minetest.get_node(pos)
  25. local name = node.name
  26. local fdir = node.param2
  27. if nitems == 0 then
  28. minetest.set_node(pos, {name = string.gsub(name, "on", "off"), param2 = fdir})
  29. mesecon.receptor_off(pos, pipeworks.mesecons_rules)
  30. else
  31. meta:set_int("nitems", nitems)
  32. end
  33. end,
  34. on_construct = function(pos)
  35. local meta = minetest.get_meta(pos)
  36. meta:set_int("nitems", 1)
  37. local name = minetest.get_node(pos).name
  38. local saved_pos = vector.new(pos)
  39. minetest.after(detector_tube_step, minetest.registered_nodes[name].item_exit, saved_pos)
  40. end,
  41. },
  42. })
  43. pipeworks.register_tube("pipeworks:detector_tube_off", {
  44. description = S("Detecting Pneumatic Tube Segment"),
  45. inventory_image = "pipeworks_detector_tube_inv.png",
  46. plain = { "pipeworks_detector_tube_plain.png" },
  47. node_def = {
  48. tube = {can_go = function(pos, node, velocity, stack)
  49. local node = minetest.get_node(pos)
  50. local name = node.name
  51. local fdir = node.param2
  52. minetest.set_node(pos,{name = string.gsub(name, "off", "on"), param2 = fdir})
  53. mesecon.receptor_on(pos, pipeworks.mesecons_rules)
  54. return pipeworks.notvel(pipeworks.meseadjlist, velocity)
  55. end},
  56. groups = {mesecon = 2},
  57. mesecons = {receptor = {state = "off", rules = pipeworks.mesecons_rules }},
  58. },
  59. })
  60. minetest.register_craft( {
  61. output = "pipeworks:detector_tube_off_1 2",
  62. recipe = {
  63. { "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" },
  64. { "mesecons:mesecon", "mesecons_materials:silicon", "mesecons:mesecon" },
  65. { "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" }
  66. },
  67. })
  68. end
  69. local digiline_enabled = minetest.get_modpath("digilines") ~= nil
  70. if digiline_enabled and pipeworks.enable_digiline_detector_tube then
  71. pipeworks.register_tube("pipeworks:digiline_detector_tube", {
  72. description = S("Digiline Detecting Pneumatic Tube Segment"),
  73. inventory_image = "pipeworks_digiline_detector_tube_inv.png",
  74. plain = { "pipeworks_digiline_detector_tube_plain.png" },
  75. node_def = {
  76. tube = {can_go = function(pos, node, velocity, stack)
  77. local meta = minetest.get_meta(pos)
  78. local setchan = meta:get_string("channel")
  79. digiline:receptor_send(pos, digiline.rules.default, setchan, stack:to_table())
  80. return pipeworks.notvel(pipeworks.meseadjlist, velocity)
  81. end},
  82. on_construct = function(pos)
  83. local meta = minetest.get_meta(pos)
  84. meta:set_string("formspec",
  85. "size[8.6,2.2]"..
  86. "field[0.6,0.6;8,1;channel;"..S("Channel")..";${channel}]"..
  87. "image[0.3,1.3;1,1;pipeworks_digiline_detector_tube_inv.png]"..
  88. "label[1.6,1.2;"..S("Digiline Detecting Tube").."]"
  89. )
  90. end,
  91. on_receive_fields = function(pos, formname, fields, sender)
  92. if fields.channel then
  93. minetest.get_meta(pos):set_string("channel", fields.channel)
  94. end
  95. end,
  96. groups = {},
  97. digiline = {
  98. receptor = {},
  99. effector = {
  100. action = function(pos,node,channel,msg) end
  101. },
  102. wire = {
  103. rules = pipeworks.digilines_rules
  104. },
  105. },
  106. },
  107. })
  108. minetest.register_craft( {
  109. output = "pipeworks:digiline_detector_tube_1 2",
  110. recipe = {
  111. { "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" },
  112. { "digilines:wire_std_00000000", "mesecons_materials:silicon", "digilines:wire_std_00000000" },
  113. { "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" }
  114. },
  115. })
  116. end
  117. if pipeworks.enable_conductor_tube then
  118. pipeworks.register_tube("pipeworks:conductor_tube_off", {
  119. description = S("Conducting Pneumatic Tube Segment"),
  120. inventory_image = "pipeworks_conductor_tube_inv.png",
  121. short = "pipeworks_conductor_tube_short.png",
  122. plain = { "pipeworks_conductor_tube_plain.png" },
  123. noctr = { "pipeworks_conductor_tube_noctr.png" },
  124. ends = { "pipeworks_conductor_tube_end.png" },
  125. node_def = {
  126. groups = {mesecon = 2},
  127. mesecons = {conductor = {state = "off",
  128. rules = pipeworks.mesecons_rules,
  129. onstate = "pipeworks:conductor_tube_on_#id"}}
  130. },
  131. })
  132. pipeworks.register_tube("pipeworks:conductor_tube_on", {
  133. description = S("Conducting Pneumatic Tube Segment on"),
  134. inventory_image = "pipeworks_conductor_tube_inv.png",
  135. short = "pipeworks_conductor_tube_short.png",
  136. plain = { "pipeworks_conductor_tube_on_plain.png" },
  137. noctr = { "pipeworks_conductor_tube_on_noctr.png" },
  138. ends = { "pipeworks_conductor_tube_on_end.png" },
  139. node_def = {
  140. groups = {mesecon = 2, not_in_creative_inventory = 1},
  141. drop = "pipeworks:conductor_tube_off_1",
  142. mesecons = {conductor = {state = "on",
  143. rules = pipeworks.mesecons_rules,
  144. offstate = "pipeworks:conductor_tube_off_#id"}}
  145. },
  146. })
  147. minetest.register_craft({
  148. type = "shapeless",
  149. output = "pipeworks:conductor_tube_off_1",
  150. recipe = {"pipeworks:tube_1", "mesecons:mesecon"}
  151. })
  152. end
  153. if digiline_enabled and pipeworks.enable_digiline_conductor_tube then
  154. pipeworks.register_tube("pipeworks:digiline_conductor_tube", {
  155. description = S("Digiline Conducting Pneumatic Tube Segment"),
  156. inventory_image = "pipeworks_tube_inv.png^pipeworks_digiline_conductor_tube_inv.png",
  157. short = "pipeworks_tube_short.png^pipeworks_digiline_conductor_tube_short.png",
  158. plain = {"pipeworks_tube_plain.png^pipeworks_digiline_conductor_tube_plain.png"},
  159. noctr = {"pipeworks_tube_noctr.png^pipeworks_digiline_conductor_tube_noctr.png"},
  160. ends = {"pipeworks_tube_end.png^pipeworks_digiline_conductor_tube_end.png"},
  161. node_def = {digiline = {wire = {rules = pipeworks.digilines_rules}}},
  162. })
  163. minetest.register_craft({
  164. type = "shapeless",
  165. output = "pipeworks:digiline_conductor_tube_1",
  166. recipe = {"pipeworks:tube_1", "digilines:wire_std_00000000"}
  167. })
  168. end
  169. if digiline_enabled and pipeworks.enable_digiline_conductor_tube and
  170. pipeworks.enable_conductor_tube then
  171. pipeworks.register_tube("pipeworks:mesecon_and_digiline_conductor_tube_off", {
  172. description = S("Mesecon and Digiline Conducting Pneumatic Tube Segment"),
  173. inventory_image = "pipeworks_conductor_tube_inv.png^pipeworks_digiline_conductor_tube_inv.png",
  174. short = "pipeworks_conductor_tube_short.png^pipeworks_digiline_conductor_tube_short.png",
  175. plain = {"pipeworks_conductor_tube_plain.png^pipeworks_digiline_conductor_tube_plain.png"},
  176. noctr = {"pipeworks_conductor_tube_noctr.png^pipeworks_digiline_conductor_tube_noctr.png"},
  177. ends = {"pipeworks_conductor_tube_end.png^pipeworks_digiline_conductor_tube_end.png"},
  178. node_def = {
  179. digiline = {wire = {rules = pipeworks.digilines_rules}},
  180. groups = {mesecon = 2},
  181. mesecons = {conductor = {
  182. state = "off",
  183. rules = pipeworks.mesecons_rules,
  184. onstate = "pipeworks:mesecon_and_digiline_conductor_tube_on_#id"
  185. }},
  186. },
  187. })
  188. pipeworks.register_tube("pipeworks:mesecon_and_digiline_conductor_tube_on", {
  189. description = S("Mesecon and Digiline Conducting Pneumatic Tube Segment on"),
  190. inventory_image = "pipeworks_conductor_tube_inv.png^pipeworks_digiline_conductor_tube_inv.png",
  191. short = "pipeworks_conductor_tube_short.png^pipeworks_digiline_conductor_tube_short.png",
  192. plain = {"pipeworks_conductor_tube_on_plain.png^pipeworks_digiline_conductor_tube_plain.png"},
  193. noctr = {"pipeworks_conductor_tube_on_noctr.png^pipeworks_digiline_conductor_tube_noctr.png"},
  194. ends = {"pipeworks_conductor_tube_on_end.png^pipeworks_digiline_conductor_tube_end.png"},
  195. node_def = {
  196. digiline = {wire = {rules = pipeworks.digilines_rules}},
  197. groups = {mesecon = 2, not_in_creative_inventory = 1},
  198. drop = "pipeworks:mesecon_and_digiline_conductor_tube_off_1",
  199. mesecons = {conductor = {
  200. state = "on",
  201. rules = pipeworks.mesecons_rules,
  202. offstate = "pipeworks:mesecon_and_digiline_conductor_tube_off_#id"}
  203. },
  204. },
  205. })
  206. minetest.register_craft({
  207. type = "shapeless",
  208. output = "pipeworks:mesecon_and_digiline_conductor_tube_off_1",
  209. recipe = {"pipeworks:tube_1", "mesecons:mesecon", "digilines:wire_std_00000000"}
  210. })
  211. minetest.register_craft({
  212. type = "shapeless",
  213. output = "pipeworks:mesecon_and_digiline_conductor_tube_off_1",
  214. recipe = {"pipeworks:conductor_tube_off_1", "digilines:wire_std_00000000"}
  215. })
  216. minetest.register_craft({
  217. type = "shapeless",
  218. output = "pipeworks:mesecon_and_digiline_conductor_tube_off_1",
  219. recipe = {"pipeworks:digiline_conductor_tube_1", "mesecons:mesecon"}
  220. })
  221. end