teleport_arrow.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. _name = "throwing:arrow_teleport",
  31. physical = false,
  32. timer=0,
  33. visual = "wielditem",
  34. visual_size = {x=0.1, y=0.1},
  35. textures = {"throwing:arrow_teleport_box"},
  36. lastpos = {},
  37. collisionbox = {0,0,0,0,0,0},
  38. player = "",
  39. static_save = false,
  40. }
  41. local air_nodes = {"air", "group:airlike"}
  42. local function do_teleport(self, tptarget, under, above)
  43. if not self.player_name then
  44. return
  45. end
  46. -- Player may have logged off after firing the arrow.
  47. local player = minetest.get_player_by_name(self.player_name)
  48. local tpos = minetest.find_node_near(tptarget, 1, air_nodes, true)
  49. if not player or not tpos then
  50. return
  51. end
  52. if not rc.is_valid_realm_pos(tpos) then
  53. return
  54. end
  55. local node = minetest.get_node(tpos)
  56. -- Maptools air is airlike but unbreakable. Don't TP in here.
  57. if minetest.get_item_group(node.name, "unbreakable") == 0 then
  58. if under and above then
  59. -- Arrow hit node.
  60. local node = minetest.get_node(under)
  61. local ndef = minetest.registered_nodes[node.name]
  62. if ndef then
  63. if not ndef.disallow_teleport then
  64. player:set_pos(tpos)
  65. end
  66. end
  67. else
  68. -- Hit player or object, 'tptarget' is intersection point.
  69. player:set_pos(tpos)
  70. end
  71. end
  72. end
  73. function THROWING_ARROW_ENTITY.hit_player(self, obj, intersection_point)
  74. do_teleport(self, intersection_point)
  75. end
  76. function THROWING_ARROW_ENTITY.hit_object(self, obj, intersection_point)
  77. do_teleport(self, intersection_point)
  78. end
  79. function THROWING_ARROW_ENTITY.hit_node(self, under, above, intersection_point)
  80. -- Intentionally duplicated 'above', not a bug.
  81. do_teleport(self, above, under, above)
  82. end
  83. THROWING_ARROW_ENTITY.on_step = function(self, dtime)
  84. throwing.do_fly(self, dtime)
  85. end
  86. minetest.register_entity("throwing:arrow_teleport_entity", THROWING_ARROW_ENTITY)
  87. minetest.register_craft({
  88. output = 'throwing:arrow_teleport 3',
  89. recipe = {
  90. {'', 'default:stick', 'default:stick'},
  91. {'starpearl:pearl', 'default:stick', 'default:stick'},
  92. {'', 'default:stick', 'default:stick'},
  93. }
  94. })