arrow.lua 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. minetest.register_craftitem("throwing:arrow", {
  2. description = "Arrow",
  3. inventory_image = "throwing_arrow.png",
  4. })
  5. minetest.register_node("throwing:arrow_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.png", "throwing_arrow.png", "throwing_arrow_back.png", "throwing_arrow_front.png", "throwing_arrow_2.png", "throwing_arrow.png"},
  27. groups = {not_in_creative_inventory=1},
  28. })
  29. local THROWING_ARROW_ENTITY={
  30. physical = false,
  31. timer=0,
  32. visual = "wielditem",
  33. visual_size = {x=0.1, y=0.1},
  34. textures = {"throwing:arrow_box"},
  35. lastpos={},
  36. collisionbox = {0,0,0,0,0,0},
  37. }
  38. THROWING_ARROW_ENTITY.on_step = function(self, dtime)
  39. self.timer=self.timer+dtime
  40. local pos = self.object:getpos()
  41. local node = minetest.env:get_node(pos)
  42. if self.timer>0.2 then
  43. local objs = minetest.env:get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
  44. for k, obj in pairs(objs) do
  45. if obj:get_luaentity() ~= nil then
  46. if obj:get_luaentity().name ~= "throwing:arrow_entity" and obj:get_luaentity().name ~= "__builtin:item" then
  47. local damage = 3
  48. obj:punch(self.object, 1.0, {
  49. full_punch_interval=1.0,
  50. damage_groups={fleshy=damage},
  51. }, nil)
  52. self.object:remove()
  53. end
  54. else
  55. local damage = 3
  56. obj:punch(self.object, 1.0, {
  57. full_punch_interval=1.0,
  58. damage_groups={fleshy=damage},
  59. }, nil)
  60. self.object:remove()
  61. end
  62. end
  63. end
  64. if self.lastpos.x~=nil then
  65. if node.name ~= "air" then
  66. minetest.env:add_item(self.lastpos, 'throwing:arrow')
  67. self.object:remove()
  68. end
  69. end
  70. self.lastpos={x=pos.x, y=pos.y, z=pos.z}
  71. end
  72. minetest.register_entity("throwing:arrow_entity", THROWING_ARROW_ENTITY)
  73. minetest.register_craft({
  74. output = 'throwing:arrow 16',
  75. recipe = {
  76. {'default:stick', 'default:stick', 'default:steel_ingot'},
  77. }
  78. })