fireworks_arrows.lua 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. local function throwing_register_fireworks(color, desc)
  2. minetest.register_craftitem("throwing:arrow_fireworks_" .. color, {
  3. description = desc .. " Fireworks Arrow",
  4. inventory_image = "throwing_arrow_fireworks_" .. color .. ".png",
  5. })
  6. minetest.register_node("throwing:arrow_fireworks_" .. color .. "_box", {
  7. drawtype = "nodebox",
  8. node_box = {
  9. type = "fixed",
  10. fixed = {
  11. -- Shaft
  12. {-6.5/17, -1.5/17, -1.5/17, 6.5/17, 1.5/17, 1.5/17},
  13. --Spitze
  14. {-4.5/17, 2.5/17, 2.5/17, -3.5/17, -2.5/17, -2.5/17},
  15. {-8.5/17, 0.5/17, 0.5/17, -6.5/17, -0.5/17, -0.5/17},
  16. --Federn
  17. {6.5/17, 1.5/17, 1.5/17, 7.5/17, 2.5/17, 2.5/17},
  18. {7.5/17, -2.5/17, 2.5/17, 6.5/17, -1.5/17, 1.5/17},
  19. {7.5/17, 2.5/17, -2.5/17, 6.5/17, 1.5/17, -1.5/17},
  20. {6.5/17, -1.5/17, -1.5/17, 7.5/17, -2.5/17, -2.5/17},
  21. {7.5/17, 2.5/17, 2.5/17, 8.5/17, 3.5/17, 3.5/17},
  22. {8.5/17, -3.5/17, 3.5/17, 7.5/17, -2.5/17, 2.5/17},
  23. {8.5/17, 3.5/17, -3.5/17, 7.5/17, 2.5/17, -2.5/17},
  24. {7.5/17, -2.5/17, -2.5/17, 8.5/17, -3.5/17, -3.5/17},
  25. }
  26. },
  27. tiles = {"throwing_arrow_fireworks_" .. color .. ".png", "throwing_arrow_fireworks_" .. color .. ".png", "throwing_arrow_fireworks_" .. color .. "_back.png", "throwing_arrow_fireworks_" .. color .. "_front.png", "throwing_arrow_fireworks_" .. color .. "_2.png", "throwing_arrow_fireworks_" .. color .. ".png"},
  28. groups = {not_in_creative_inventory=1},
  29. })
  30. local THROWING_ARROW_ENTITY={
  31. _name = "throwing:arrow_fireworks_" .. color,
  32. physical = false,
  33. timer=0,
  34. visual = "wielditem",
  35. visual_size = {x=0.1, y=0.1},
  36. textures = {"throwing:arrow_fireworks_" .. color .. "_box"},
  37. lastpos={},
  38. collisionbox = {0,0,0,0,0,0},
  39. static_save = false,
  40. }
  41. local radius = 0.5
  42. local function add_effects(pos, radius)
  43. minetest.add_particlespawner({
  44. amount = 256,
  45. time = 0.2,
  46. minpos = vector.subtract(pos, radius / 2),
  47. maxpos = vector.add(pos, radius / 2),
  48. minvel = {x=-5, y=-5, z=-5},
  49. maxvel = {x=5, y=5, z=5},
  50. minacc = {x=0, y=-8, z=0},
  51. --~ maxacc = {x=-20, y=-50, z=-50},
  52. minexptime = 2.5,
  53. maxexptime = 3,
  54. minsize = 1,
  55. maxsize = 2.5,
  56. texture = "throwing_sparkle_" .. color .. ".png",
  57. glow = 14,
  58. })
  59. end
  60. local function boom(pos)
  61. minetest.sound_play("throwing_firework_boom", {pos=pos, gain=1, max_hear_distance=2*64}, true)
  62. if minetest.get_node(pos).name == 'air' or minetest.get_node(pos).name == 'throwing:firework_trail' then
  63. minetest.add_node(pos, {name="throwing:firework_boom"})
  64. minetest.get_node_timer(pos):start(0.2)
  65. end
  66. add_effects(pos, radius)
  67. end
  68. -- Back to the arrow
  69. function THROWING_ARROW_ENTITY.hit_player(self, obj, intersection_point)
  70. local pos = intersection_point
  71. local damage = 2*500
  72. throwing_arrow_punch_entity(obj, self, damage)
  73. boom(pos)
  74. end
  75. function THROWING_ARROW_ENTITY.hit_object(self, obj, intersection_point)
  76. local pos = intersection_point
  77. local damage = 2*500
  78. throwing_arrow_punch_entity(obj, self, damage)
  79. boom(pos)
  80. end
  81. function THROWING_ARROW_ENTITY.hit_node(self, under, above, intersection_point)
  82. boom(above)
  83. end
  84. function THROWING_ARROW_ENTITY.flight_particle(self, lpos, cpos)
  85. minetest.add_particlespawner({
  86. amount = 16,
  87. time = 0.1,
  88. minpos = cpos,
  89. maxpos = cpos,
  90. minvel = {x=-5, y=-5, z=-5},
  91. maxvel = {x=5, y=5, z=5},
  92. minacc = vector.new(),
  93. maxacc = vector.new(),
  94. minexptime = 0.3,
  95. maxexptime = 0.5,
  96. minsize = 0.5,
  97. maxsize = 1,
  98. texture = "throwing_sparkle.png",
  99. glow = 13,
  100. })
  101. end
  102. THROWING_ARROW_ENTITY.on_step = function(self, dtime)
  103. self.timer = self.timer + dtime
  104. local pos = self.object:get_pos()
  105. local node = minetest.get_node(pos)
  106. if not self.played_launch_sound then
  107. ambiance.sound_play("throwing_firework_launch", pos, 0.8, 2*64)
  108. self.played_launch_sound = true
  109. end
  110. -- Flight max timelimit.
  111. if self.timer > 2 then
  112. boom(self.lastpos)
  113. self.object:remove()
  114. return
  115. end
  116. -- Leave light trail.
  117. if node.name == 'air' then
  118. minetest.add_node(pos, {name="throwing:firework_trail"})
  119. minetest.get_node_timer(pos):start(0.1)
  120. end
  121. throwing.do_fly(self, dtime)
  122. end
  123. minetest.register_entity("throwing:arrow_fireworks_" .. color .. "_entity", THROWING_ARROW_ENTITY)
  124. minetest.register_craft({
  125. output = 'throwing:arrow_fireworks_' .. color,
  126. recipe = {
  127. {'dye:' .. color, 'tnt:gunpowder', 'default:stick'},
  128. }
  129. })
  130. end
  131. --~ Arrows
  132. if not DISABLE_FIREWORKS_BLUE_ARROW then
  133. throwing_register_fireworks('blue', 'Blue')
  134. end
  135. if not DISABLE_FIREWORKS_RED_ARROW then
  136. throwing_register_fireworks('red', 'Red')
  137. end
  138. --~ Nodes
  139. minetest.register_node("throwing:firework_trail", {
  140. drawtype = "airlike",
  141. light_source = 9,
  142. walkable = false,
  143. pointable = false,
  144. buildable_to = true,
  145. drop = "",
  146. groups = utility.dig_groups("item"),
  147. on_timer = function(pos, elapsed)
  148. minetest.remove_node(pos)
  149. end,
  150. })
  151. minetest.register_node("throwing:firework_boom", {
  152. drawtype = "plantlike",
  153. tiles = {"throwing_sparkle.png"},
  154. light_source = default.LIGHT_MAX - 1,
  155. walkable = false,
  156. drop = "",
  157. groups = utility.dig_groups("item"),
  158. on_timer = function(pos, elapsed)
  159. minetest.remove_node(pos)
  160. end,
  161. after_destruct = function(pos, oldnode)
  162. minetest.set_node(pos, {name="throwing:firework_light"})
  163. minetest.get_node_timer(pos):start(3)
  164. end,
  165. })
  166. minetest.register_node("throwing:firework_light", {
  167. drawtype = "airlike",
  168. light_source = default.LIGHT_MAX - 1,
  169. pointable = false,
  170. buildable_to = true,
  171. walkable = false,
  172. drop = "",
  173. groups = utility.dig_groups("item"),
  174. on_timer = function(pos, elapsed)
  175. minetest.remove_node(pos)
  176. end,
  177. })