laser_gate.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. local fdir_table = {
  2. { 1, 0 },
  3. { 0, -1 },
  4. { -1, 0 },
  5. { 0, 1 },
  6. { 1, 0 },
  7. { 0, -1 },
  8. { -1, 0 },
  9. { 0, 1 },
  10. }
  11. local laser_gate = {
  12. type = 'fixed',
  13. fixed = {
  14. {-.5, -.3, -.2, .5, .3, .2},},}
  15. minetest.register_node('ship:laser_gate', {
  16. description = 'Laser Gate',
  17. drawtype = 'mesh',
  18. mesh = 'ship_laser_gate.obj',
  19. paramtype = 'light',
  20. paramtype2 = 'facedir',
  21. light_source = 10,
  22. tiles = {'ship_laser_gate.png'},
  23. groups = {breakable=1},
  24. selection_box = laser_gate,
  25. collision_box = laser_gate,
  26. after_place_node = function(pos, placer, itemstack)
  27. local node = minetest.get_node(pos)
  28. local fdir = node.param2
  29. local length = 0
  30. if fdir == 1 then -- negative z
  31. local pos1 = {x=pos.x, y=pos.y, z=pos.z-1}
  32. local pos1_name = minetest.get_node(pos1).name
  33. while pos1_name == 'air' and length <= 10 do
  34. length = length + 1
  35. pos1 = {x=pos1.x, y=pos1.y, z=pos1.z-1}
  36. pos1_name = minetest.get_node(pos1).name
  37. end
  38. if length >= 1 then
  39. minetest.set_node(pos, {name = 'ship:laser_gate_l', param2 = fdir})
  40. for i = 1, (length-1) do
  41. local place_pos = {x=pos.x, y=pos.y, z=pos.z-i}
  42. minetest.set_node(place_pos, {name = 'ship:laser_gate_m', param2 = fdir})
  43. end
  44. local end_pos = {x=pos.x, y=pos.y, z=pos.z-length}
  45. minetest.set_node(end_pos, {name = 'ship:laser_gate_r', param2 = fdir})
  46. end
  47. elseif fdir == 2 then -- negative x
  48. local pos1 = {x=pos.x-1, y=pos.y, z=pos.z}
  49. local pos1_name = minetest.get_node(pos1).name
  50. while pos1_name == 'air' and length <= 10 do
  51. length = length + 1
  52. pos1 = {x=pos1.x-1, y=pos1.y, z=pos1.z}
  53. pos1_name = minetest.get_node(pos1).name
  54. end
  55. if length >= 1 then
  56. minetest.set_node(pos, {name = 'ship:laser_gate_l', param2 = fdir})
  57. for i = 1, (length-1) do
  58. local place_pos = {x=pos.x-i, y=pos.y, z=pos.z}
  59. minetest.set_node(place_pos, {name = 'ship:laser_gate_m', param2 = fdir})
  60. end
  61. local end_pos = {x=pos.x-length, y=pos.y, z=pos.z}
  62. minetest.set_node(end_pos, {name = 'ship:laser_gate_r', param2 = fdir})
  63. end
  64. elseif fdir == 3 then -- positive z
  65. local pos1 = {x=pos.x, y=pos.y, z=pos.z+1}
  66. local pos1_name = minetest.get_node(pos1).name
  67. while pos1_name == 'air' and length <= 10 do
  68. length = length + 1
  69. pos1 = {x=pos1.x, y=pos1.y, z=pos1.z+1}
  70. pos1_name = minetest.get_node(pos1).name
  71. end
  72. if length >= 1 then
  73. minetest.set_node(pos, {name = 'ship:laser_gate_l', param2 = fdir})
  74. for i = 1, (length-1) do
  75. local place_pos = {x=pos.x, y=pos.y, z=pos.z+i}
  76. minetest.set_node(place_pos, {name = 'ship:laser_gate_m', param2 = fdir})
  77. end
  78. local end_pos = {x=pos.x, y=pos.y, z=pos.z+length}
  79. minetest.set_node(end_pos, {name = 'ship:laser_gate_r', param2 = fdir})
  80. end
  81. elseif fdir == 0 then -- positive x
  82. local pos1 = {x=pos.x+1, y=pos.y, z=pos.z}
  83. local pos1_name = minetest.get_node(pos1).name
  84. while pos1_name == 'air' and length <= 10 do
  85. length = length + 1
  86. pos1 = {x=pos1.x+1, y=pos1.y, z=pos1.z}
  87. pos1_name = minetest.get_node(pos1).name
  88. end
  89. if length >= 1 then
  90. minetest.set_node(pos, {name = 'ship:laser_gate_l', param2 = fdir})
  91. for i = 1, (length-1) do
  92. local place_pos = {x=pos.x+i, y=pos.y, z=pos.z}
  93. minetest.set_node(place_pos, {name = 'ship:laser_gate_m', param2 = fdir})
  94. end
  95. local end_pos = {x=pos.x+length, y=pos.y, z=pos.z}
  96. minetest.set_node(end_pos, {name = 'ship:laser_gate_r', param2 = fdir})
  97. end
  98. end
  99. end,
  100. })
  101. minetest.register_node('ship:laser_gate_l', {
  102. drawtype = 'mesh',
  103. mesh = 'ship_laser_gate_L.obj',
  104. paramtype = 'light',
  105. paramtype2 = 'facedir',
  106. light_source = 10,
  107. tiles = {'ship_laser_gate.png'},
  108. groups = {breakable=1, not_in_creative_inventory=1},
  109. drop = 'ship:laser_gate',
  110. selection_box = laser_gate,
  111. collision_box = laser_gate,
  112. })
  113. minetest.register_node('ship:laser_gate_r', {
  114. drawtype = 'mesh',
  115. mesh = 'ship_laser_gate_R.obj',
  116. paramtype = 'light',
  117. paramtype2 = 'facedir',
  118. light_source = 10,
  119. tiles = {'ship_laser_gate.png'},
  120. groups = {breakable=1, not_in_creative_inventory=1},
  121. drop = 'ship:laser_gate',
  122. selection_box = laser_gate,
  123. collision_box = laser_gate,
  124. })
  125. minetest.register_node('ship:laser_gate_m', {
  126. drawtype = 'mesh',
  127. mesh = 'ship_laser_gate_M.obj',
  128. paramtype = 'light',
  129. paramtype2 = 'facedir',
  130. light_source = 10,
  131. tiles = {'ship_laser_gate.png'},
  132. groups = {breakable=1, not_in_creative_inventory=1},
  133. drop = 'ship:laser_gate',
  134. selection_box = laser_gate,
  135. collision_box = laser_gate,
  136. })