shell_arrow.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. minetest.register_craftitem("throwing:arrow_shell", {
  2. description = "Shell Arrow",
  3. inventory_image = "throwing_arrow_shell.png",
  4. })
  5. minetest.register_node("throwing:arrow_shell_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_shell.png", "throwing_arrow_shell.png", "throwing_arrow_shell_back.png", "throwing_arrow_shell_front.png", "throwing_arrow_shell_2.png", "throwing_arrow_shell.png"},
  27. groups = {not_in_creative_inventory=1},
  28. })
  29. local THROWING_ARROW_ENTITY={
  30. _name = "throwing:arrow_shell",
  31. physical = false,
  32. timer=0,
  33. visual = "wielditem",
  34. visual_size = {x=0.1, y=0.1},
  35. textures = {"throwing:arrow_shell_box"},
  36. lastpos={},
  37. collisionbox = {0,0,0,0,0,0},
  38. static_save = false,
  39. }
  40. local radius = 1
  41. local function add_effects(pos, radius)
  42. minetest.add_particlespawner({
  43. amount = 8,
  44. time = 0.5,
  45. minpos = vector.subtract(pos, radius / 2),
  46. maxpos = vector.add(pos, radius / 2),
  47. minvel = {x=-10, y=-10, z=-10},
  48. maxvel = {x=10, y=10, z=10},
  49. minacc = vector.new(),
  50. maxacc = vector.new(),
  51. minexptime = 0.5,
  52. maxexptime = 1,
  53. minsize = 0.5,
  54. maxsize = 1,
  55. texture = "tnt_smoke.png",
  56. })
  57. end
  58. local function boom(pos)
  59. minetest.sound_play("throwing_shell_explode", {pos=pos, gain=1.5, max_hear_distance=2*64}, true)
  60. -- Don't destroy things.
  61. if minetest.get_node(pos).name == "air" then
  62. minetest.set_node(pos, {name="tnt:boom"})
  63. minetest.get_node_timer(pos):start(0.1)
  64. end
  65. add_effects(pos, radius)
  66. end
  67. -- Back to the arrow
  68. local function explode_nearby(self, pos)
  69. local vel = self.object:get_velocity()
  70. local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
  71. for k, obj in pairs(objs) do
  72. if obj:get_luaentity() ~= nil then
  73. local oname = obj:get_luaentity().name
  74. if not throwing.entity_ignores_arrow(oname) then
  75. local speed = vector.length(vel)
  76. local damage = (((speed + 5)^1.2)/5 + 12) * 1
  77. throwing_arrow_punch_entity(obj, self, damage*500)
  78. boom(pos)
  79. end
  80. elseif obj:is_player() then
  81. local speed = vector.length(vel)
  82. local damage = ((speed + 5)^1.2)/5 + 12
  83. throwing_arrow_punch_entity(obj, self, damage*500)
  84. boom(pos)
  85. end
  86. end
  87. end
  88. function THROWING_ARROW_ENTITY.hit_player(self, obj, intersection_point)
  89. explode_nearby(self, intersection_point)
  90. end
  91. function THROWING_ARROW_ENTITY.hit_object(self, obj, intersection_point)
  92. explode_nearby(self, intersection_point)
  93. end
  94. function THROWING_ARROW_ENTITY.hit_node(self, under, above, intersection_point)
  95. explode_nearby(self, intersection_point)
  96. end
  97. THROWING_ARROW_ENTITY.on_step = function(self, dtime)
  98. throwing.do_fly(self, dtime)
  99. end
  100. minetest.register_entity("throwing:arrow_shell_entity", THROWING_ARROW_ENTITY)
  101. minetest.register_craft({
  102. output = 'throwing:arrow_shell 3',
  103. recipe = {
  104. {'', 'tnt:gunpowder', 'default:stick'},
  105. {'default:copper_ingot', 'tnt:gunpowder', 'default:stick'},
  106. {'', 'tnt:gunpowder', 'default:stick'},
  107. }
  108. })