teleport_arrow.lua 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. minetest.register_craftitem("throwing:arrow_teleport", {
  2. description = "Teleport Arrow",
  3. inventory_image = "throwing_arrow_teleport.png",
  4. })
  5. minetest.register_node("throwing:arrow_teleport_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_teleport.png", "throwing_arrow_teleport.png", "throwing_arrow_teleport_back.png", "throwing_arrow_teleport_front.png", "throwing_arrow_teleport_2.png", "throwing_arrow_teleport.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_teleport_box"},
  35. lastpos={},
  36. collisionbox = {0,0,0,0,0,0},
  37. player = "",
  38. }
  39. THROWING_ARROW_ENTITY.on_step = function(self, dtime)
  40. self.timer=self.timer+dtime
  41. local pos = self.object:getpos()
  42. local node = minetest.env:get_node(pos)
  43. if self.timer>0.2 then
  44. local objs = minetest.env:get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
  45. for k, obj in pairs(objs) do
  46. if obj:get_luaentity() ~= nil then
  47. if obj:get_luaentity().name ~= "throwing:arrow_teleport_entity" and obj:get_luaentity().name ~= "__builtin:item" then
  48. if self.player ~= "" then
  49. self.player:setpos(pos)
  50. self.player:get_inventory():add_item("main", ItemStack("throwing:arrow_teleport"))
  51. end
  52. self.object:remove()
  53. end
  54. else
  55. if self.player ~= "" then
  56. self.player:setpos(pos)
  57. self.player:get_inventory():add_item("main", ItemStack("throwing:arrow_teleport"))
  58. end
  59. self.object:remove()
  60. end
  61. end
  62. end
  63. if self.lastpos.x~=nil then
  64. if node.name ~= "air" then
  65. if self.player ~= "" then
  66. self.player:setpos(self.lastpos)
  67. self.player:get_inventory():add_item("main", ItemStack("throwing:arrow_teleport"))
  68. end
  69. self.object:remove()
  70. end
  71. end
  72. self.lastpos={x=pos.x, y=pos.y, z=pos.z}
  73. end
  74. minetest.register_entity("throwing:arrow_teleport_entity", THROWING_ARROW_ENTITY)
  75. minetest.register_craft({
  76. output = 'throwing:arrow_teleport',
  77. recipe = {
  78. {'default:stick', 'default:stick', 'default:mese'},
  79. }
  80. })