fire_arrow.lua 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. }
  41. THROWING_ARROW_ENTITY.on_step = function(self, dtime)
  42. self.timer=self.timer+dtime
  43. local pos = self.object:get_pos()
  44. local node = minetest.get_node(pos)
  45. if self.timer>0.2 then
  46. local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
  47. for k, obj in pairs(objs) do
  48. if obj:get_luaentity() ~= nil then
  49. local oname = obj:get_luaentity().name
  50. if not throwing.entity_blocks_arrow(oname) then
  51. local damage = 4
  52. throwing_arrow_punch_entity(obj, self, damage)
  53. self.object:remove()
  54. minetest.add_item(self.lastpos, 'default:stick')
  55. end
  56. elseif obj:is_player() then
  57. local damage = 4
  58. throwing_arrow_punch_entity(obj, self, damage)
  59. self.object:remove()
  60. minetest.add_item(self.lastpos, 'default:stick')
  61. end
  62. end
  63. end
  64. if self.lastpos.x~=nil then
  65. if throwing_node_should_block_arrow(node.name) then
  66. if node.name == "throwing:light" or not minetest.test_protection(self.lastpos, "") then
  67. minetest.add_node(self.lastpos, {name="fire:basic_flame"})
  68. else
  69. local fpos = minetest.find_node_near(pos, 1, "air")
  70. if fpos then
  71. minetest.add_node(fpos, {name="fire:basic_flame"})
  72. end
  73. end
  74. minetest.sound_play("throwing_shell_explode", {pos=pos, gain=1.0, max_hear_distance=2*64}, true)
  75. self.object:remove()
  76. end
  77. if math_floor(self.lastpos.x+0.5) ~= math_floor(pos.x+0.5) or
  78. math_floor(self.lastpos.y+0.5) ~= math_floor(pos.y+0.5) or
  79. math_floor(self.lastpos.z+0.5) ~= math_floor(pos.z+0.5) then
  80. if minetest.get_node(pos).name == "air" then
  81. minetest.set_node(pos, {name="throwing:light"})
  82. end
  83. end
  84. end
  85. self.lastpos={x=pos.x, y=pos.y, z=pos.z}
  86. end
  87. minetest.register_entity("throwing:arrow_fire_entity", THROWING_ARROW_ENTITY)
  88. minetest.register_node("throwing:light", {
  89. drawtype = "airlike",
  90. paramtype = "light",
  91. sunlight_propagates = true,
  92. tiles = {"throwing_empty.png"},
  93. light_source = default.LIGHT_MAX-5,
  94. selection_box = {
  95. type = "fixed",
  96. fixed = {
  97. {0,0,0,0,0,0}
  98. }
  99. },
  100. groups = {not_in_creative_inventory=1},
  101. on_construct = function(pos)
  102. minetest.get_node_timer(pos):start(0.5)
  103. end,
  104. on_timer = function(pos, elapsed)
  105. minetest.remove_node(pos)
  106. end,
  107. })
  108. minetest.register_craft({
  109. output = 'throwing:arrow_fire',
  110. recipe = {
  111. {'default:stick', 'default:stick', 'group:torch_craftitem'},
  112. },
  113. })
  114. minetest.register_craft({
  115. output = 'throwing:arrow_fire',
  116. recipe = {
  117. {'group:torch_craftitem', 'default:stick', 'default:stick'},
  118. },
  119. })