teleport_arrow.lua 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. }
  40. THROWING_ARROW_ENTITY.on_step = function(self, dtime)
  41. self.timer=self.timer+dtime
  42. local pos = self.object:get_pos()
  43. local node = minetest.get_node(pos)
  44. if not self.player then
  45. self.object:remove()
  46. end
  47. if self.timer>0.2 then
  48. local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
  49. for k, obj in pairs(objs) do
  50. if obj:get_luaentity() ~= nil then
  51. local oname = obj:get_luaentity().name
  52. if not throwing.entity_blocks_arrow(oname) then
  53. self.object:remove()
  54. if self.player ~= "" then
  55. self.player:set_pos(pos)
  56. self.player:get_inventory():add_item("main", ItemStack("default:stick 2"))
  57. end
  58. end
  59. end
  60. end
  61. end
  62. if self.lastpos.x~=nil then
  63. if throwing_node_should_block_arrow(node.name) then
  64. self.object:remove()
  65. if self.player ~= "" then
  66. self.player:set_pos(self.lastpos)
  67. self.player:get_inventory():add_item("main", ItemStack("default:stick 2"))
  68. end
  69. end
  70. end
  71. self.lastpos={x=pos.x, y=pos.y, z=pos.z}
  72. end
  73. minetest.register_entity("throwing:arrow_teleport_entity", THROWING_ARROW_ENTITY)
  74. minetest.register_craft({
  75. output = 'throwing:arrow_teleport 8',
  76. recipe = {
  77. {'default:stick', 'default:stick', 'starpearl:pearl'}
  78. }
  79. })
  80. minetest.register_craft({
  81. output = 'throwing:arrow_teleport 8',
  82. recipe = {
  83. {'starpearl:pearl', 'default:stick', 'default:stick'}
  84. }
  85. })