init.lua 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. minetest.register_craftitem("orb_of_fire:orb_of_fire", {
  2. description = "Orb of Fire\nMana: 15",
  3. inventory_image = "orb_of_fire_orb.png",
  4. on_use = function(itemstack, player, pointed_thing)
  5. local name = player:get_player_name()
  6. local players_mana = hbmana.get(name)
  7. if players_mana >= 15 then
  8. hbmana.set(name, players_mana - 15)
  9. local player_pos = player:get_pos()
  10. local dir = player:get_look_dir()
  11. obj = minetest.add_entity({
  12. x = player_pos.x,
  13. y = player_pos.y + 1.5,
  14. z = player_pos.z
  15. }, "orb_of_fire:fire_ball")
  16. obj:setvelocity({
  17. x = dir.x * 15,
  18. y = dir.y * 15,
  19. z = dir.z * 15
  20. })
  21. obj:get_luaentity()._owner = name
  22. end
  23. end
  24. })
  25. minetest.register_craft({
  26. output = "orb_of_fire:orb_of_fire",
  27. recipe = {
  28. {"", "default:glass", ""},
  29. {"default:glass", "gems_ruby:ruby", "default:glass"},
  30. {"", "default:glass", ""},
  31. }
  32. })
  33. minetest.register_entity("orb_of_fire:fire_ball", {
  34. physical = false,
  35. visual = "sprite",
  36. visual_size = {x=0.5, y=0.5},
  37. textures = {"orb_of_fire_fire_ball.png"},
  38. collisionbox = {-0.1,-0.1,-0.1,0.1,0.1,0.1},
  39. pointable = false,
  40. _owner = "",
  41. on_step = function(self, dtime)
  42. local pos = self.object:get_pos()
  43. if minetest.get_node(pos).name ~= "air" then
  44. local node_above_pos = {
  45. x = pos.x,
  46. y = pos.y + 1,
  47. z = pos.z
  48. }
  49. local node_next_to_pos_1 = {
  50. x = pos.x + 1,
  51. y = pos.y,
  52. z = pos.z
  53. }
  54. local node_next_to_pos_2 = {
  55. x = pos.x - 1,
  56. y = pos.y,
  57. z = pos.z
  58. }
  59. local node_next_to_pos_3 = {
  60. x = pos.x,
  61. y = pos.y,
  62. z = pos.z + 1
  63. }
  64. local node_next_to_pos_4 = {
  65. x = pos.x,
  66. y = pos.y,
  67. z = pos.z - 1
  68. }
  69. if minetest.get_node(node_above_pos).name == "air" then
  70. minetest.place_node(node_above_pos, {name="fire:basic_flame"})
  71. elseif minetest.get_node(node_next_to_pos_1).name == "air" then
  72. minetest.place_node(node_next_to_pos_1, {name="fire:basic_flame"})
  73. elseif minetest.get_node(node_next_to_pos_2).name == "air" then
  74. minetest.place_node(node_next_to_pos_2, {name="fire:basic_flame"})
  75. elseif minetest.get_node(node_next_to_pos_3).name == "air" then
  76. minetest.place_node(node_next_to_pos_3, {name="fire:basic_flame"})
  77. elseif minetest.get_node(node_next_to_pos_4).name == "air" then
  78. minetest.place_node(node_next_to_pos_4, {name="fire:basic_flame"})
  79. end
  80. self.object:remove()
  81. end
  82. minetest.add_particlespawner({
  83. amount = 30,
  84. time = 0.10,
  85. minpos = {
  86. x = pos.x - 0.1,
  87. y = pos.y - 0.1,
  88. z = pos.z - 0.1
  89. },
  90. maxpos = {
  91. x = pos.x + 0.1,
  92. y = pos.y + 0.1,
  93. z = pos.z + 0.1
  94. },
  95. minexptime = 0.1,
  96. maxexptime = 0.2,
  97. minsize = 0.50,
  98. maxsize = 0.50,
  99. collisiondetection = false,
  100. vertical = false,
  101. texture = "orb_of_fire_particle.png",
  102. })
  103. local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
  104. for k, obj in pairs(objs) do
  105. if obj:get_luaentity() ~= nil then
  106. local obj_name = obj:get_luaentity().name
  107. if obj_name ~= "orb_of_fire:fire_ball" and obj_name ~= "__builtin:item" and obj_name ~= "mobs_monster:mese_arrow" and obj_name ~= "mobs_monster:fireball" then
  108. obj:punch(self.object, 1.0, {
  109. full_punch_interval = 1.0,
  110. damage_groups = {fleshy = 3},
  111. }, nil)
  112. self.object:remove()
  113. end
  114. elseif obj:is_player() and obj:get_player_name() ~= self._owner then
  115. obj:punch(self.object, 1.0, {
  116. full_punch_interval = 1.0,
  117. damage_groups = {fleshy = 3},
  118. }, nil)
  119. self.object:remove()
  120. end
  121. end
  122. end
  123. })