objects.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. minetest.register_node('ship:ladder', {
  2. description = 'Ladder',
  3. drawtype = 'mesh',
  4. mesh = 'ship_ladder.obj',
  5. paramtype = 'light',
  6. paramtype2 = 'facedir',
  7. climbable = true,
  8. selection_box = {
  9. type = 'fixed',
  10. fixed = {
  11. {-.4, -.5, .3, .4, .5, .5},},
  12. },
  13. collision_box = {
  14. type = 'fixed',
  15. fixed = {
  16. {-.4, -.5, .3, .4, .5, .5},},
  17. },
  18. tiles = {'ship_rail_blank.png', 'ship_floor_blank.png'},
  19. groups = {breakable=1}
  20. })
  21. minetest.register_node('ship:door_H_1_0', {
  22. description = 'Closed Door',
  23. drawtype = 'mesh',
  24. mesh = 'ship_door_H_closed.obj',
  25. paramtype = 'light',
  26. paramtype2 = 'facedir',
  27. tiles = {'ship_door_H_0.png'},
  28. groups = {breakable=1},
  29. selection_box = {
  30. type = 'fixed',
  31. fixed = {
  32. {-.5, -.5, -.1, .5, 1.5, .1},},
  33. },
  34. collision_box = {
  35. type = 'fixed',
  36. fixed = {
  37. {-.5, -.5, -.1, .5, 1.5, .1},},
  38. },
  39. on_rightclick = function(pos, node)
  40. local fdir = node.param2
  41. local timer = minetest.get_node_timer(pos)
  42. timer:start(3)
  43. minetest.set_node(pos, {name = 'ship:door_H_1_1', param2=fdir})
  44. minetest.sound_play('ship_door_open', {pos = pos, max_hear_distance = 10, gain = 1})
  45. if fdir == 0 then --Search in the X axis
  46. local other_door_pos = {x=pos.x+1, y=pos.y, z=pos.z}
  47. local other_door = minetest.get_node(other_door_pos)
  48. if other_door.name == 'ship:door_H_1_0' then
  49. minetest.set_node(other_door_pos, {name = 'ship:door_H_1_1', param2=other_door.param2})
  50. local timer = minetest.get_node_timer(other_door_pos)
  51. timer:start(3)
  52. end
  53. elseif fdir == 1 then --Search in the Z axis
  54. local other_door_pos = {x=pos.x, y=pos.y, z=pos.z-1}
  55. local other_door = minetest.get_node(other_door_pos)
  56. if other_door.name == 'ship:door_H_1_0' then
  57. minetest.set_node(other_door_pos, {name = 'ship:door_H_1_1', param2=other_door.param2})
  58. local timer = minetest.get_node_timer(other_door_pos)
  59. timer:start(3)
  60. end
  61. elseif fdir == 2 then --Search in the X axis
  62. local other_door_pos = {x=pos.x-1, y=pos.y, z=pos.z}
  63. local other_door = minetest.get_node(other_door_pos)
  64. if other_door.name == 'ship:door_H_1_0' then
  65. minetest.set_node(other_door_pos, {name = 'ship:door_H_1_1', param2=other_door.param2})
  66. local timer = minetest.get_node_timer(other_door_pos)
  67. timer:start(3)
  68. end
  69. elseif fdir == 3 then --Search in the Z axis
  70. local other_door_pos = {x=pos.x, y=pos.y, z=pos.z+1}
  71. local other_door = minetest.get_node(other_door_pos)
  72. if other_door.name == 'ship:door_H_1_0' then
  73. minetest.set_node(other_door_pos, {name = 'ship:door_H_1_1', param2=other_door.param2})
  74. local timer = minetest.get_node_timer(other_door_pos)
  75. timer:start(3)
  76. end
  77. end
  78. end,
  79. })
  80. minetest.register_node('ship:door_H_1_1', {
  81. description = 'Open Door',
  82. drawtype = 'mesh',
  83. mesh = 'ship_door_H_open.obj',
  84. paramtype = 'light',
  85. paramtype2 = 'facedir',
  86. tiles = {'ship_door_H_0.png'},
  87. groups = {breakable=1, not_in_creative_inventory=1},
  88. drop = 'ship:door_H_1_0',
  89. selection_box = {
  90. type = 'fixed',
  91. fixed = {
  92. {-.5, -.5, -.1, -.4, 1.5, .1},},
  93. },
  94. collision_box = {
  95. type = 'fixed',
  96. fixed = {
  97. {-.5, -.5, -.1, -.4, 1.5, .1},},
  98. },
  99. on_rightclick = function(pos, node)
  100. minetest.set_node(pos, {name = 'ship:door_H_1_0', param2=node.param2})
  101. minetest.sound_play('ship_door_close', {pos = pos, max_hear_distance = 10, gain = 1})
  102. end,
  103. on_timer = function(pos)
  104. local node = minetest.get_node(pos)
  105. minetest.set_node(pos, {name = 'ship:door_H_1_0', param2=node.param2})
  106. minetest.sound_play('ship_door_close', {pos = pos, max_hear_distance = 10, gain = .5})
  107. end
  108. })
  109. minetest.register_node('ship:door_V_1_0', { --Vertical opening, style 1, binary state 0 (closed)
  110. description = 'Closed Door',
  111. drawtype = 'mesh',
  112. mesh = 'ship_door_V_closed.obj',
  113. paramtype = 'light',
  114. paramtype2 = 'facedir',
  115. tiles = {'ship_door_V_0.png'},
  116. groups = {breakable=1},
  117. selection_box = {
  118. type = 'fixed',
  119. fixed = {
  120. {-.5, -.5, -.1, .5, 1.5, .1},},
  121. },
  122. collision_box = {
  123. type = 'fixed',
  124. fixed = {
  125. {-.5, -.5, -.1, .5, 1.5, .1},},
  126. },
  127. on_rightclick = function(pos, node)
  128. local fdir = node.param2
  129. local timer = minetest.get_node_timer(pos)
  130. timer:start(3)
  131. minetest.set_node(pos, {name = 'ship:door_V_1_1', param2=fdir})
  132. minetest.sound_play('ship_door_open', {pos = pos, max_hear_distance = 10, gain = 1})
  133. if fdir == 0 or fdir == 2 then --Search in the X axis
  134. local other_door_r_pos = {x=pos.x+1, y=pos.y, z=pos.z}
  135. local other_door_r = minetest.get_node(other_door_r_pos).name
  136. local other_door_l_pos = {x=pos.x-1, y=pos.y, z=pos.z}
  137. local other_door_l = minetest.get_node(other_door_l_pos).name
  138. while other_door_r == 'ship:door_V_1_0' do
  139. local timer = minetest.get_node_timer(other_door_r_pos)
  140. timer:start(3)
  141. minetest.set_node(other_door_r_pos, {name = 'ship:door_V_1_1', param2=fdir})
  142. other_door_r_pos.x = other_door_r_pos.x + 1
  143. other_door_r = minetest.get_node(other_door_r_pos).name
  144. end
  145. while other_door_l == 'ship:door_V_1_0' do
  146. local timer = minetest.get_node_timer(other_door_l_pos)
  147. timer:start(3)
  148. minetest.set_node(other_door_l_pos, {name = 'ship:door_V_1_1', param2=fdir})
  149. other_door_l_pos.x = other_door_l_pos.x - 1
  150. other_door_l = minetest.get_node(other_door_l_pos).name
  151. end
  152. elseif fdir == 1 or fdir == 3 then --Search in the Z axis
  153. local other_door_r_pos = {x=pos.x, y=pos.y, z=pos.z+1}
  154. local other_door_r = minetest.get_node(other_door_r_pos).name
  155. local other_door_l_pos = {x=pos.x, y=pos.y, z=pos.z-1}
  156. local other_door_l = minetest.get_node(other_door_l_pos).name
  157. while other_door_r == 'ship:door_V_1_0' do
  158. local timer = minetest.get_node_timer(other_door_r_pos)
  159. timer:start(3)
  160. minetest.set_node(other_door_r_pos, {name = 'ship:door_V_1_1', param2=fdir})
  161. other_door_r_pos.z = other_door_r_pos.z + 1
  162. other_door_r = minetest.get_node(other_door_r_pos).name
  163. end
  164. while other_door_l == 'ship:door_V_1_0' do
  165. local timer = minetest.get_node_timer(other_door_l_pos)
  166. timer:start(3)
  167. minetest.set_node(other_door_l_pos, {name = 'ship:door_V_1_1', param2=fdir})
  168. other_door_l_pos.z = other_door_l_pos.z - 1
  169. other_door_l = minetest.get_node(other_door_l_pos).name
  170. end
  171. end
  172. end,
  173. })
  174. minetest.register_node('ship:door_V_1_1', { --Vertical opening, style 1, binary state 1 (open)
  175. description = 'Open Door',
  176. drawtype = 'mesh',
  177. mesh = 'ship_door_V_open.obj',
  178. paramtype = 'light',
  179. paramtype2 = 'facedir',
  180. tiles = {'ship_door_V_0.png'},
  181. groups = {breakable=1, not_in_creative_inventory=1},
  182. drop = 'ship:door_H_1_0',
  183. selection_box = {
  184. type = 'fixed',
  185. fixed = {
  186. {-.5, -.5, -.1, .5, -.4, .1},
  187. {-.5, 1.4, -.1, .5, 1.5, .1},},
  188. },
  189. collision_box = {
  190. type = 'fixed',
  191. fixed = {
  192. {-.5, -.5, -.1, .5, -.4, .1},
  193. {-.5, 1.4, -.1, .5, 1.5, .1},},
  194. },
  195. on_rightclick = function(pos, node)
  196. minetest.set_node(pos, {name = 'ship:door_V_1_0', param2=node.param2})
  197. minetest.sound_play('ship_door_close', {pos = pos, max_hear_distance = 10, gain = 1})
  198. end,
  199. on_timer = function(pos)
  200. local node = minetest.get_node(pos)
  201. minetest.set_node(pos, {name = 'ship:door_V_1_0', param2=node.param2})
  202. minetest.sound_play('ship_door_close', {pos = pos, max_hear_distance = 10, gain = .5})
  203. end
  204. })
  205. minetest.register_node('ship:energy_support', {
  206. description = 'Energy Support Beam',
  207. drawtype = 'mesh',
  208. mesh = 'ship_energy_support.obj',
  209. paramtype = 'light',
  210. paramtype2 = 'facedir',
  211. light_source = 10,
  212. tiles = {'ship_energy_support.png'},
  213. groups = {breakable=1},
  214. selection_box = {
  215. type = 'fixed',
  216. fixed = {
  217. {-.35, -.5, -.35, .35, .4, .35},}
  218. },
  219. collision_box = {
  220. type = 'fixed',
  221. fixed = {
  222. {-.35, -.5, -.35, .35, .4, .35},}
  223. },
  224. after_place_node = function(pos, placer, itemstack)
  225. local node = minetest.get_node(pos)
  226. local above_pos = {x=pos.x, y=pos.y+1, z=pos.z}
  227. local above_name = minetest.get_node(above_pos).name
  228. local height = 0
  229. while above_name == 'air' and height < 20 do
  230. minetest.set_node(above_pos, {name = 'ship:energy_beam', param2 = node.param2})
  231. above_pos = {x=above_pos.x, y=above_pos.y+1, z=above_pos.z}
  232. above_name = minetest.get_node(above_pos).name
  233. height = height + 1
  234. end
  235. if above_name ~= 'air' then
  236. local pos = {x=above_pos.x, y=above_pos.y-1, z=above_pos.z}
  237. minetest.set_node(pos, {name = 'ship:energy_support_top', param2 = node.param2})
  238. end
  239. end,
  240. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  241. local above_pos = {x=pos.x, y=pos.y+1, z=pos.z}
  242. local above_name = minetest.get_node(above_pos).name
  243. while above_name == 'ship:energy_beam' do
  244. minetest.remove_node(above_pos)
  245. above_pos = {x=above_pos.x, y=above_pos.y+1, z=above_pos.z}
  246. above_name = minetest.get_node(above_pos).name
  247. end
  248. if above_name == 'ship:energy_support_top' then
  249. minetest.remove_node(above_pos)
  250. end
  251. end,
  252. })
  253. local beam_select = {
  254. type = 'fixed',
  255. fixed = {
  256. {-.2, -.5, -.2, .2, .5, .2},},}
  257. minetest.register_node('ship:energy_beam', {
  258. drawtype = 'mesh',
  259. mesh = 'ship_energy_beam.obj',
  260. paramtype = 'light',
  261. light_source = 10,
  262. tiles = {'ship_energy_beam.png'},
  263. groups = {breakable=1, not_in_creative_inventory=1},
  264. drop = '',
  265. selection_box = beam_select,
  266. collision_box = beam_select,
  267. })
  268. minetest.register_node('ship:energy_support_top', {
  269. drawtype = 'mesh',
  270. mesh = 'ship_energy_support_top.obj',
  271. paramtype = 'light',
  272. paramtype2 = 'facedir',
  273. light_source = 10,
  274. tiles = {'ship_energy_support_top.png'},
  275. groups = {breakable=1, not_in_creative_inventory=1},
  276. drop = '',
  277. selection_box = beam_select,
  278. collision_box = beam_select,
  279. })