fire_arrow.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. minetest.register_craftitem("throwing:arrow_fire", {
  2. description = "Fire Arrow",
  3. inventory_image = "throwing_arrow_fire.png",
  4. })
  5. minetest.register_node("throwing:arrow_fire_box", {
  6. drawtype = "nodebox",
  7. node_box = {
  8. type = "fixed",
  9. fixed = {
  10. -- Shaft
  11. {-6.5/17, -1.5/17, -1.5/17, 6.5/17, 1.5/17, 1.5/17},
  12. --Spitze
  13. {-4.5/17, 2.5/17, 2.5/17, -3.5/17, -2.5/17, -2.5/17},
  14. {-8.5/17, 0.5/17, 0.5/17, -6.5/17, -0.5/17, -0.5/17},
  15. --Federn
  16. {6.5/17, 1.5/17, 1.5/17, 7.5/17, 2.5/17, 2.5/17},
  17. {7.5/17, -2.5/17, 2.5/17, 6.5/17, -1.5/17, 1.5/17},
  18. {7.5/17, 2.5/17, -2.5/17, 6.5/17, 1.5/17, -1.5/17},
  19. {6.5/17, -1.5/17, -1.5/17, 7.5/17, -2.5/17, -2.5/17},
  20. {7.5/17, 2.5/17, 2.5/17, 8.5/17, 3.5/17, 3.5/17},
  21. {8.5/17, -3.5/17, 3.5/17, 7.5/17, -2.5/17, 2.5/17},
  22. {8.5/17, 3.5/17, -3.5/17, 7.5/17, 2.5/17, -2.5/17},
  23. {7.5/17, -2.5/17, -2.5/17, 8.5/17, -3.5/17, -3.5/17},
  24. }
  25. },
  26. 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"},
  27. groups = {not_in_creative_inventory=1},
  28. })
  29. local THROWING_ARROW_ENTITY={
  30. _name = "throwing:arrow_fire",
  31. physical = false,
  32. timer=0,
  33. visual = "wielditem",
  34. visual_size = {x=0.1, y=0.1},
  35. textures = {"throwing:arrow_fire_box"},
  36. lastpos={},
  37. collisionbox = {0,0,0,0,0,0},
  38. }
  39. THROWING_ARROW_ENTITY.on_step = function(self, dtime)
  40. self.timer=self.timer+dtime
  41. local pos = self.object:get_pos()
  42. local node = minetest.get_node(pos)
  43. if self.timer>0.2 then
  44. local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
  45. for k, obj in pairs(objs) do
  46. if obj:get_luaentity() ~= nil then
  47. local oname = obj:get_luaentity().name
  48. if not throwing.entity_blocks_arrow(oname) then
  49. local damage = 4
  50. throwing_arrow_punch_entity(obj, self, damage)
  51. self.object:remove()
  52. minetest.add_item(self.lastpos, 'default:stick')
  53. end
  54. elseif obj:is_player() then
  55. local damage = 4
  56. throwing_arrow_punch_entity(obj, self, damage)
  57. self.object:remove()
  58. minetest.add_item(self.lastpos, 'default:stick')
  59. end
  60. end
  61. end
  62. if self.lastpos.x~=nil then
  63. if throwing_node_should_block_arrow(node.name) then
  64. if node.name == "throwing:light" or not minetest.test_protection(self.lastpos, "") then
  65. minetest.add_node(self.lastpos, {name="fire:basic_flame"})
  66. else
  67. local fpos = minetest.find_node_near(pos, 1, "air")
  68. if fpos then
  69. minetest.add_node(fpos, {name="fire:basic_flame"})
  70. end
  71. end
  72. minetest.sound_play("throwing_shell_explode", {pos=pos, gain=1.0, max_hear_distance=2*64})
  73. self.object:remove()
  74. end
  75. if math.floor(self.lastpos.x+0.5) ~= math.floor(pos.x+0.5) or
  76. math.floor(self.lastpos.y+0.5) ~= math.floor(pos.y+0.5) or
  77. math.floor(self.lastpos.z+0.5) ~= math.floor(pos.z+0.5) then
  78. if minetest.get_node(pos).name == "air" then
  79. minetest.set_node(pos, {name="throwing:light"})
  80. end
  81. end
  82. end
  83. self.lastpos={x=pos.x, y=pos.y, z=pos.z}
  84. end
  85. minetest.register_entity("throwing:arrow_fire_entity", THROWING_ARROW_ENTITY)
  86. minetest.register_node("throwing:light", {
  87. drawtype = "airlike",
  88. paramtype = "light",
  89. sunlight_propagates = true,
  90. tiles = {"throwing_empty.png"},
  91. light_source = default.LIGHT_MAX-5,
  92. selection_box = {
  93. type = "fixed",
  94. fixed = {
  95. {0,0,0,0,0,0}
  96. }
  97. },
  98. groups = {not_in_creative_inventory=1},
  99. on_construct = function(pos)
  100. minetest.get_node_timer(pos):start(0.5)
  101. end,
  102. on_timer = function(pos, elapsed)
  103. minetest.remove_node(pos)
  104. end,
  105. })
  106. minetest.register_craft({
  107. output = 'throwing:arrow_fire',
  108. recipe = {
  109. {'default:stick', 'default:stick', 'group:torch_craftitem'},
  110. },
  111. })
  112. minetest.register_craft({
  113. output = 'throwing:arrow_fire',
  114. recipe = {
  115. {'group:torch_craftitem', 'default:stick', 'default:stick'},
  116. },
  117. })