fire_arrow.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. -- Localize for performance.
  2. local math_floor = math.floor
  3. minetest.register_craftitem("throwing:arrow_fire", {
  4. description = "Fire Arrow",
  5. inventory_image = "throwing_arrow_fire.png",
  6. })
  7. minetest.register_node("throwing:arrow_fire_box", {
  8. drawtype = "nodebox",
  9. node_box = {
  10. type = "fixed",
  11. fixed = {
  12. -- Shaft
  13. {-6.5/17, -1.5/17, -1.5/17, 6.5/17, 1.5/17, 1.5/17},
  14. --Spitze
  15. {-4.5/17, 2.5/17, 2.5/17, -3.5/17, -2.5/17, -2.5/17},
  16. {-8.5/17, 0.5/17, 0.5/17, -6.5/17, -0.5/17, -0.5/17},
  17. --Federn
  18. {6.5/17, 1.5/17, 1.5/17, 7.5/17, 2.5/17, 2.5/17},
  19. {7.5/17, -2.5/17, 2.5/17, 6.5/17, -1.5/17, 1.5/17},
  20. {7.5/17, 2.5/17, -2.5/17, 6.5/17, 1.5/17, -1.5/17},
  21. {6.5/17, -1.5/17, -1.5/17, 7.5/17, -2.5/17, -2.5/17},
  22. {7.5/17, 2.5/17, 2.5/17, 8.5/17, 3.5/17, 3.5/17},
  23. {8.5/17, -3.5/17, 3.5/17, 7.5/17, -2.5/17, 2.5/17},
  24. {8.5/17, 3.5/17, -3.5/17, 7.5/17, 2.5/17, -2.5/17},
  25. {7.5/17, -2.5/17, -2.5/17, 8.5/17, -3.5/17, -3.5/17},
  26. }
  27. },
  28. tiles = {"throwing_arrow_fire.png", "throwing_arrow_fire.png", "throwing_arrow_fire_back.png", "throwing_arrow_fire_front.png", "throwing_arrow_fire_2.png", "throwing_arrow_fire.png"},
  29. groups = {not_in_creative_inventory=1},
  30. })
  31. local THROWING_ARROW_ENTITY={
  32. _name = "throwing:arrow_fire",
  33. physical = false,
  34. timer=0,
  35. visual = "wielditem",
  36. visual_size = {x=0.1, y=0.1},
  37. textures = {"throwing:arrow_fire_box"},
  38. lastpos={},
  39. collisionbox = {0,0,0,0,0,0},
  40. static_save = false,
  41. }
  42. function THROWING_ARROW_ENTITY.hit_player(self, obj, intersection_point)
  43. local damage = 4*500
  44. throwing_arrow_punch_entity(obj, self, damage)
  45. minetest.add_item(self.lastpos, 'default:stick')
  46. end
  47. function THROWING_ARROW_ENTITY.hit_object(self, obj, intersection_point)
  48. local damage = 4*500
  49. throwing_arrow_punch_entity(obj, self, damage)
  50. minetest.add_item(self.lastpos, 'default:stick')
  51. end
  52. function THROWING_ARROW_ENTITY.hit_node(self, under, above, intersection_point)
  53. if not intersection_point then
  54. return
  55. end
  56. local fpos = minetest.find_node_near(intersection_point, 1, {"air", "group:airlike"}, true)
  57. if fpos then
  58. local node = minetest.get_node(fpos)
  59. if minetest.get_item_group(node.name, "unbreakable") == 0 then
  60. minetest.add_node(fpos, {name="fire:basic_flame"})
  61. end
  62. end
  63. minetest.sound_play("throwing_shell_explode", {pos=above, gain=1.0, max_hear_distance=2*64}, true)
  64. end
  65. THROWING_ARROW_ENTITY.on_step = function(self, dtime)
  66. local pos = self.object:get_pos()
  67. -- Light up the air as it passes.
  68. if self.lastpos.x ~= nil then
  69. if math_floor(self.lastpos.x+0.5) ~= math_floor(pos.x+0.5) or
  70. math_floor(self.lastpos.y+0.5) ~= math_floor(pos.y+0.5) or
  71. math_floor(self.lastpos.z+0.5) ~= math_floor(pos.z+0.5) then
  72. if minetest.get_node(pos).name == "air" then
  73. minetest.set_node(pos, {name="throwing:light"})
  74. end
  75. end
  76. end
  77. throwing.do_fly(self, dtime)
  78. end
  79. minetest.register_entity("throwing:arrow_fire_entity", THROWING_ARROW_ENTITY)
  80. minetest.register_node("throwing:light", {
  81. drawtype = "airlike",
  82. paramtype = "light",
  83. sunlight_propagates = true,
  84. tiles = {"throwing_empty.png"},
  85. light_source = default.LIGHT_MAX-5,
  86. selection_box = {
  87. type = "fixed",
  88. fixed = {
  89. {0,0,0,0,0,0}
  90. }
  91. },
  92. groups = {not_in_creative_inventory=1},
  93. on_construct = function(pos)
  94. minetest.get_node_timer(pos):start(0.5)
  95. end,
  96. on_timer = function(pos, elapsed)
  97. minetest.remove_node(pos)
  98. end,
  99. })
  100. minetest.register_craft({
  101. output = 'throwing:arrow_fire',
  102. recipe = {
  103. {'charcoal:charcoal', 'plastic:oil_extract', 'group:stick'},
  104. },
  105. })