magical_arrow.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. minetest.register_craftitem("lottthrowing:arrow_magical", {
  2. description = "Magical Arrow",
  3. inventory_image = "lottthrowing_arrow_magical.png",
  4. groups = {forbidden=1},
  5. })
  6. minetest.register_node("lottthrowing:arrow_magical_box", {
  7. drawtype = "nodebox",
  8. node_box = {
  9. type = "fixed",
  10. fixed = {
  11. -- Shaft
  12. {-6.5/17, -1.5/17, -1.5/17, 6.5/17, 1.5/17, 1.5/17},
  13. --Spitze
  14. {-4.5/17, 2.5/17, 2.5/17, -3.5/17, -2.5/17, -2.5/17},
  15. {-8.5/17, 0.5/17, 0.5/17, -6.5/17, -0.5/17, -0.5/17},
  16. --Federn
  17. {6.5/17, 1.5/17, 1.5/17, 7.5/17, 2.5/17, 2.5/17},
  18. {7.5/17, -2.5/17, 2.5/17, 6.5/17, -1.5/17, 1.5/17},
  19. {7.5/17, 2.5/17, -2.5/17, 6.5/17, 1.5/17, -1.5/17},
  20. {6.5/17, -1.5/17, -1.5/17, 7.5/17, -2.5/17, -2.5/17},
  21. {7.5/17, 2.5/17, 2.5/17, 8.5/17, 3.5/17, 3.5/17},
  22. {8.5/17, -3.5/17, 3.5/17, 7.5/17, -2.5/17, 2.5/17},
  23. {8.5/17, 3.5/17, -3.5/17, 7.5/17, 2.5/17, -2.5/17},
  24. {7.5/17, -2.5/17, -2.5/17, 8.5/17, -3.5/17, -3.5/17},
  25. }
  26. },
  27. tiles = {"lottthrowing_arrow_magical.png", "lottthrowing_arrow_magical.png", "lottthrowing_arrow_magical_back.png", "lottthrowing_arrow_magical_front.png", "lottthrowing_arrow_magical_2.png", "lottthrowing_arrow_magical.png"},
  28. groups = {not_in_creative_inventory=1},
  29. })
  30. local THROWING_ARROW_ENTITY={
  31. physical = false,
  32. timer=0,
  33. visual = "wielditem",
  34. visual_size = {x=0.1, y=0.1},
  35. textures = {"lottthrowing:arrow_magical_box"},
  36. lastpos={},
  37. collisionbox = {0,0,0,0,0,0},
  38. player = "",
  39. }
  40. THROWING_ARROW_ENTITY.on_step = function(self, dtime)
  41. self.timer=self.timer+dtime
  42. local pos = self.object:getpos()
  43. local node = minetest.get_node(pos)
  44. if self.timer>0.2 then
  45. local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
  46. for k, obj in pairs(objs) do
  47. if obj:get_luaentity() ~= nil then
  48. if obj:get_luaentity().name ~= "lottthrowing:arrow_magical_entity" and obj:get_luaentity().name ~= "__builtin:item" then
  49. if self.player ~= "" then
  50. self.player:setpos(pos)
  51. self.player:get_inventory():add_item("main", ItemStack("lottthrowing:arrow_magical"))
  52. end
  53. self.object:remove()
  54. end
  55. else
  56. if self.player ~= "" then
  57. self.player:setpos(pos)
  58. self.player:get_inventory():add_item("main", ItemStack("lottthrowing:arrow_magical"))
  59. end
  60. self.object:remove()
  61. end
  62. end
  63. end
  64. if self.lastpos.x~=nil then
  65. if node.name ~= "air" then
  66. if self.player ~= "" then
  67. self.player:setpos(self.lastpos)
  68. self.player:get_inventory():add_item("main", ItemStack("lottthrowing:arrow_magical"))
  69. end
  70. self.object:remove()
  71. end
  72. end
  73. self.lastpos={x=pos.x, y=pos.y, z=pos.z}
  74. end
  75. minetest.register_entity("lottthrowing:arrow_magical_entity", THROWING_ARROW_ENTITY)
  76. minetest.register_craft({
  77. output = 'lottthrowing:arrow_magical',
  78. recipe = {
  79. {'default:stick', 'default:stick', 'default:mese'},
  80. }
  81. })