shell_arrow.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. }
  39. local radius = 1
  40. local function add_effects(pos, radius)
  41. minetest.add_particlespawner({
  42. amount = 8,
  43. time = 0.5,
  44. minpos = vector.subtract(pos, radius / 2),
  45. maxpos = vector.add(pos, radius / 2),
  46. minvel = {x=-10, y=-10, z=-10},
  47. maxvel = {x=10, y=10, z=10},
  48. minacc = vector.new(),
  49. maxacc = vector.new(),
  50. minexptime = 0.5,
  51. maxexptime = 1,
  52. minsize = 0.5,
  53. maxsize = 1,
  54. texture = "tnt_smoke.png",
  55. })
  56. end
  57. local function boom(pos)
  58. minetest.sound_play("throwing_shell_explode", {pos=pos, gain=1.5, max_hear_distance=2*64})
  59. -- Don't destroy things.
  60. if minetest.get_node(pos).name == "air" then
  61. minetest.set_node(pos, {name="tnt:boom"})
  62. minetest.get_node_timer(pos):start(0.1)
  63. end
  64. add_effects(pos, radius)
  65. end
  66. -- Back to the arrow
  67. THROWING_ARROW_ENTITY.on_step = function(self, dtime)
  68. self.timer=self.timer+dtime
  69. local pos = self.object:get_pos()
  70. local node = minetest.get_node(pos)
  71. if self.timer>0.2 then
  72. local vel = self.object:get_velocity()
  73. local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
  74. for k, obj in pairs(objs) do
  75. if obj:get_luaentity() ~= nil then
  76. local oname = obj:get_luaentity().name
  77. if not throwing.entity_blocks_arrow(oname) then
  78. local speed = vector.length(vel)
  79. local damage = (((speed + 5)^1.2)/10 + 12) * 1
  80. throwing_arrow_punch_entity(obj, self, damage)
  81. self.object:remove()
  82. boom(pos)
  83. end
  84. elseif obj:is_player() then
  85. local speed = vector.length(vel)
  86. local damage = ((speed + 5)^1.2)/10 + 12
  87. throwing_arrow_punch_entity(obj, self, damage)
  88. self.object:remove()
  89. boom(pos)
  90. end
  91. end
  92. end
  93. if self.lastpos.x~=nil then
  94. if throwing_node_should_block_arrow(node.name) then
  95. self.object:remove()
  96. boom(self.lastpos)
  97. end
  98. end
  99. self.lastpos={x=pos.x, y=pos.y, z=pos.z}
  100. end
  101. minetest.register_entity("throwing:arrow_shell_entity", THROWING_ARROW_ENTITY)
  102. minetest.register_craft({
  103. output = 'throwing:arrow_shell 8',
  104. recipe = {
  105. {'default:stick', 'tnt:gunpowder', 'default:copper_ingot'},
  106. }
  107. })
  108. minetest.register_craft({
  109. output = 'throwing:arrow_shell 8',
  110. recipe = {
  111. {'default:copper_ingot', 'tnt:gunpowder', 'default:stick'},
  112. }
  113. })