tnt_arrow.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. minetest.register_craftitem("throwing:arrow_tnt", {
  2. description = "TNT Arrow",
  3. inventory_image = "throwing_arrow_tnt.png",
  4. })
  5. minetest.register_node("throwing:arrow_tnt_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_tnt.png", "throwing_arrow_tnt.png", "throwing_arrow_tnt_back.png", "throwing_arrow_tnt_front.png", "throwing_arrow_tnt_2.png", "throwing_arrow_tnt.png"},
  27. groups = {not_in_creative_inventory=1},
  28. })
  29. local THROWING_ARROW_ENTITY={
  30. _name = "throwing:arrow_tnt",
  31. physical = false,
  32. timer=0,
  33. visual = "wielditem",
  34. visual_size = {x=0.1, y=0.1},
  35. textures = {"throwing:arrow_tnt_box"},
  36. lastpos={},
  37. collisionbox = {0,0,0,0,0,0},
  38. static_save = false,
  39. }
  40. local function boom(pos, pname)
  41. -- Detonate some TNT!
  42. tnt.boom(pos, {
  43. radius = 2,
  44. ignore_protection = false,
  45. ignore_on_blast = false,
  46. damage_radius = 5,
  47. disable_drops = true,
  48. name = pname,
  49. from_arrow = true,
  50. })
  51. end
  52. -- Back to the arrow
  53. local function explode_nearby(self, pos)
  54. local vel = self.object:get_velocity()
  55. local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
  56. for k, obj in pairs(objs) do
  57. if obj:get_luaentity() ~= nil then
  58. local oname = obj:get_luaentity().name
  59. if not throwing.entity_ignores_arrow(oname) then
  60. local speed = vector.length(vel)
  61. local damage = 1*500
  62. throwing_arrow_punch_entity(obj, self, damage)
  63. boom(pos, self.player_name)
  64. end
  65. elseif obj:is_player() then
  66. local speed = vector.length(vel)
  67. local damage = 1
  68. throwing_arrow_punch_entity(obj, self, damage)
  69. boom(pos, self.player_name)
  70. end
  71. end
  72. end
  73. function THROWING_ARROW_ENTITY.hit_player(self, obj, intersection_point)
  74. explode_nearby(self, intersection_point)
  75. end
  76. function THROWING_ARROW_ENTITY.hit_object(self, obj, intersection_point)
  77. explode_nearby(self, intersection_point)
  78. end
  79. function THROWING_ARROW_ENTITY.hit_node(self, under, above, intersection_point)
  80. boom(above, self.player_name)
  81. end
  82. THROWING_ARROW_ENTITY.on_step = function(self, dtime)
  83. throwing.do_fly(self, dtime)
  84. end
  85. minetest.register_entity("throwing:arrow_tnt_entity", THROWING_ARROW_ENTITY)
  86. minetest.register_craft({
  87. output = 'throwing:arrow_tnt 3',
  88. recipe = {
  89. {'', 'tnt:tnt_stick', 'default:stick'},
  90. {'default:copper_ingot', 'tnt:tnt_stick', 'default:stick'},
  91. {'', 'tnt:tnt_stick', 'default:stick'},
  92. }
  93. })