fire_arrow.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. local fpos = minetest.find_node_near(above, 1, "group:airlike", true)
  54. if fpos then
  55. local node = minetest.get_node(fpos)
  56. if minetest.get_item_group(node.name, "unbreakable") == 0 then
  57. minetest.add_node(fpos, {name="fire:basic_flame"})
  58. end
  59. end
  60. minetest.sound_play("throwing_shell_explode", {pos=above, gain=1.0, max_hear_distance=2*64}, true)
  61. end
  62. THROWING_ARROW_ENTITY.on_step = function(self, dtime)
  63. local pos = self.object:get_pos()
  64. -- Light up the air as it passes.
  65. if self.lastpos.x ~= nil then
  66. if math_floor(self.lastpos.x+0.5) ~= math_floor(pos.x+0.5) or
  67. math_floor(self.lastpos.y+0.5) ~= math_floor(pos.y+0.5) or
  68. math_floor(self.lastpos.z+0.5) ~= math_floor(pos.z+0.5) then
  69. if minetest.get_node(pos).name == "air" then
  70. minetest.set_node(pos, {name="throwing:light"})
  71. end
  72. end
  73. end
  74. throwing.do_fly(self, dtime)
  75. end
  76. minetest.register_entity("throwing:arrow_fire_entity", THROWING_ARROW_ENTITY)
  77. minetest.register_node("throwing:light", {
  78. drawtype = "airlike",
  79. paramtype = "light",
  80. sunlight_propagates = true,
  81. tiles = {"throwing_empty.png"},
  82. light_source = default.LIGHT_MAX-5,
  83. selection_box = {
  84. type = "fixed",
  85. fixed = {
  86. {0,0,0,0,0,0}
  87. }
  88. },
  89. groups = {not_in_creative_inventory=1},
  90. on_construct = function(pos)
  91. minetest.get_node_timer(pos):start(0.5)
  92. end,
  93. on_timer = function(pos, elapsed)
  94. minetest.remove_node(pos)
  95. end,
  96. })
  97. minetest.register_craft({
  98. output = 'throwing:arrow_fire',
  99. recipe = {
  100. {'charcoal:charcoal', 'plastic:oil_extract', 'default:stick'},
  101. },
  102. })