tube.lua 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. --[[
  2. Hyperloop Mod
  3. =============
  4. Copyright (C) 2017-2019 Joachim Stolberg
  5. LGPLv2.1+
  6. See LICENSE.txt for more information
  7. ]]--
  8. -- for lazy programmers
  9. local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
  10. local P = minetest.string_to_pos
  11. local M = minetest.get_meta
  12. -- Load support for intllib.
  13. local S = vents.S
  14. local NS = vents.NS
  15. local function station_name(pos)
  16. local dataSet = vents.get_station(pos)
  17. if dataSet then
  18. if dataSet.junction == true then
  19. return S('Junction at ')..SP(pos)
  20. elseif dataSet.name ~= nil then
  21. return S('Station \'')..dataSet.name..'\' at '..SP(pos)
  22. else
  23. return S('Station at ')..SP(pos)
  24. end
  25. end
  26. return S('Open end at ')..minetest.pos_to_string(pos)
  27. end
  28. function vents.check_network_level(pos, player)
  29. if vents.free_tube_placement_enabled then
  30. return
  31. end
  32. for key,_ in pairs(vents.Stations.tStations) do
  33. if pos.y == P(key).y then
  34. return
  35. end
  36. end
  37. vents.chat(player, S('There is no station/junction on this level. ')..
  38. S('Do you really want to start a new network?!'))
  39. end
  40. -- North, East, South, West, Down, Up
  41. local dirs_to_check = {1,2,3,4} -- horizontal only
  42. if vents.free_tube_placement_enabled then
  43. dirs_to_check = {1,2,3,4,5,6} -- all directions
  44. end
  45. local Tube = tubelib2.Tube:new({
  46. dirs_to_check = dirs_to_check,
  47. max_tube_length = 1000,
  48. show_infotext = true,
  49. primary_node_names = {'vents:tubeS', 'vents:tubeS2', 'vents:tubeA', 'vents:tubeA2'},
  50. secondary_node_names = {'vents:junction', 'vents:station', 'vents:tube_wifi1'},
  51. after_place_tube = function(pos, param2, tube_type, num_tubes)
  52. if num_tubes == 2 then
  53. minetest.set_node(pos, {name = 'vents:tube'..tube_type..'2', param2 = param2})
  54. else
  55. minetest.set_node(pos, {name = 'vents:tube'..tube_type, param2 = param2})
  56. end
  57. end,
  58. })
  59. vents.Tube = Tube
  60. minetest.register_node('vents:tubeS', {
  61. description = S('Vent'),
  62. inventory_image = minetest.inventorycube('vents_tube.png',
  63. 'hyperloop_tube_open.png', 'vents_tube.png'),
  64. tiles = {
  65. -- up, down, right, left, back, front
  66. 'hyperloop_tube_closed.png^[transformR90]',
  67. 'hyperloop_tube_closed.png^[transformR90]',
  68. 'hyperloop_tube_closed.png',
  69. 'hyperloop_tube_closed.png',
  70. {
  71. image = 'hyperloop_tube_open_active.png',
  72. backface_culling = false,
  73. animation = {
  74. type = 'vertical_frames',
  75. aspect_w = 32,
  76. aspect_h = 32,
  77. length = 0.5,
  78. },
  79. },
  80. },
  81. drawtype = 'nodebox',
  82. node_box = {
  83. type = 'fixed',
  84. fixed = {
  85. {-8/16, -8/16, -8/16, -7/16, 8/16, 8/16},
  86. { 7/16, -8/16, -8/16, 8/16, 8/16, 8/16},
  87. {-8/16, 7/16, -8/16, 8/16, 8/16, 8/16},
  88. {-8/16, -8/16, -8/16, 8/16, -7/16, 8/16},
  89. {-7/16, -7/16, -7/16, 7/16, 7/16, 7/16},
  90. },
  91. },
  92. selection_box = {
  93. type = 'fixed',
  94. fixed = {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16},
  95. },
  96. after_place_node = function(pos, placer, itemstack, pointed_thing)
  97. if not Tube:after_place_tube(pos, placer, pointed_thing) then
  98. minetest.remove_node(pos)
  99. return true
  100. end
  101. return false
  102. end,
  103. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  104. Tube:after_dig_tube(pos, oldnode, oldmetadata)
  105. end,
  106. paramtype2 = 'facedir', -- important!
  107. on_rotate = screwdriver.disallow, -- important!
  108. paramtype = 'light',
  109. is_ground_content = false,
  110. groups = {breakable=1},
  111. sounds = {footstep = {name = 'metal', gain = 1}},
  112. })
  113. minetest.register_node('vents:tubeS2', {
  114. description = 'Vent',
  115. tiles = {
  116. -- up, down, right, left, back, front
  117. 'vents_tube.png',
  118. 'vents_tube.png',
  119. 'vents_tube.png',
  120. 'vents_tube.png',
  121. {
  122. image = 'hyperloop_tube_open_active.png',
  123. backface_culling = false,
  124. animation = {
  125. type = 'vertical_frames',
  126. aspect_w = 32,
  127. aspect_h = 32,
  128. length = 0.5,
  129. },
  130. },
  131. },
  132. drawtype = 'nodebox',
  133. node_box = {
  134. type = 'fixed',
  135. fixed = {
  136. {-8/16, -8/16, -8/16, -7/16, 8/16, 8/16},
  137. { 7/16, -8/16, -8/16, 8/16, 8/16, 8/16},
  138. {-8/16, 7/16, -8/16, 8/16, 8/16, 8/16},
  139. {-8/16, -8/16, -8/16, 8/16, -7/16, 8/16},
  140. {-7/16, -7/16, -7/16, 7/16, 7/16, 7/16},
  141. },
  142. },
  143. selection_box = {
  144. type = 'fixed',
  145. fixed = {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16},
  146. },
  147. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  148. Tube:after_dig_tube(pos, oldnode, oldmetadata)
  149. end,
  150. paramtype2 = 'facedir', -- important!
  151. on_rotate = screwdriver.disallow, -- important!
  152. paramtype = 'light',
  153. is_ground_content = false,
  154. diggable = false,
  155. groups = {not_in_creative_inventory=1},
  156. sounds = {footstep = {name = 'metal', gain = 1}},
  157. })
  158. minetest.register_node('vents:tubeA', {
  159. description = S('Vent'),
  160. inventory_image = minetest.inventorycube('vents_tube.png',
  161. 'hyperloop_tube_open.png', 'vents_tube.png'),
  162. tiles = {
  163. -- up, down, right, left, back, front
  164. 'hyperloop_tube_closed.png^[transformR90]',
  165. {
  166. image = 'hyperloop_tube_open_active.png',
  167. backface_culling = false,
  168. animation = {
  169. type = 'vertical_frames',
  170. aspect_w = 32,
  171. aspect_h = 32,
  172. length = 0.5,
  173. },
  174. },
  175. 'hyperloop_tube_closed.png',
  176. 'hyperloop_tube_closed.png',
  177. 'hyperloop_tube_closed.png^[transformR90]',
  178. {
  179. image = 'hyperloop_tube_open_active.png',
  180. backface_culling = false,
  181. animation = {
  182. type = 'vertical_frames',
  183. aspect_w = 32,
  184. aspect_h = 32,
  185. length = 0.5,
  186. },
  187. },
  188. },
  189. drawtype = 'nodebox',
  190. node_box = {
  191. type = 'fixed',
  192. fixed = {
  193. {-8/16, -8/16, -8/16, -7/16, 8/16, 8/16},
  194. { 7/16, -8/16, -8/16, 8/16, 8/16, 8/16},
  195. {-8/16, 7/16, -8/16, 8/16, 8/16, 8/16},
  196. {-8/16, -8/16, 7/16, 8/16, 8/16, 8/16},
  197. {-8/16, -8/16, -8/16, 8/16, -7/16, -7/16},
  198. {-7/16, -7/16, -7/16, 7/16, 7/16, 7/16},
  199. },
  200. },
  201. selection_box = {
  202. type = 'fixed',
  203. fixed = {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16},
  204. },
  205. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  206. Tube:after_dig_tube(pos, oldnode, oldmetadata)
  207. end,
  208. paramtype2 = 'facedir', -- important!
  209. on_rotate = screwdriver.disallow, -- important!
  210. paramtype = 'light',
  211. is_ground_content = false,
  212. groups = {breakable=1, not_in_creative_inventory=1},
  213. drop = 'vents:tubeS',
  214. sounds = {footstep = {name = 'metal', gain = 1}},
  215. })
  216. minetest.register_node('vents:tubeA2', {
  217. description = 'Hyperloop Tube',
  218. tiles = {'vents_tube.png',},
  219. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  220. Tube:after_dig_tube(pos, oldnode, oldmetadata)
  221. end,
  222. paramtype2 = 'facedir', -- important!
  223. on_rotate = screwdriver.disallow, -- important!
  224. paramtype = 'light',
  225. is_ground_content = false,
  226. diggable = false,
  227. groups = {breakable=1, not_in_creative_inventory=1},
  228. sounds = {footstep = {name = 'metal', gain = 1}},
  229. })