init.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. minetest.register_craftitem("orb_of_ice:orb_of_ice", {
  2. description = "Orb of Ice\nMana: 15",
  3. inventory_image = "orb_of_ice_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_ice:icicle")
  16. obj:set_rotation({
  17. x = -player:get_look_vertical(),
  18. y = player:get_look_horizontal(),
  19. z = 0
  20. })
  21. obj:setvelocity({
  22. x = dir.x * 20,
  23. y = dir.y * 20,
  24. z = dir.z * 20
  25. })
  26. obj:get_luaentity()._owner = name
  27. end
  28. end
  29. })
  30. minetest.register_craft({
  31. output = "orb_of_ice:orb_of_ice",
  32. recipe = {
  33. {"", "default:glass", ""},
  34. {"default:glass", "gems_sapphire:sapphire", "default:glass"},
  35. {"", "default:glass", ""},
  36. }
  37. })
  38. minetest.register_entity("orb_of_ice:icicle", {
  39. physical = false,
  40. visual = "mesh",
  41. mesh = "orb_of_ice_icicle.obj",
  42. textures = {"orb_of_ice_icicle.png"},
  43. collisionbox = {-0.1,-0.1,-0.1,0.1,0.1,0.1},
  44. pointable = false,
  45. _owner = "",
  46. on_step = function(self, dtime)
  47. local pos = self.object:get_pos()
  48. pos = vector.round(pos)
  49. local node = minetest.get_node(pos)
  50. if node.name ~= "air" then
  51. if node.name == "default:water_source" or
  52. node.name == "default:water_flowing" or
  53. node.name == "default:river_water_source" or
  54. node.name == "default:river_water_flowing" then
  55. minetest.place_node(pos, {name="default:ice"})
  56. end
  57. self.object:remove()
  58. end
  59. minetest.add_particlespawner({
  60. amount = 10,
  61. time = 0.10,
  62. minpos = {
  63. x = pos.x - 0.1,
  64. y = pos.y - 0.1,
  65. z = pos.z - 0.1
  66. },
  67. maxpos = {
  68. x = pos.x + 0.1,
  69. y = pos.y + 0.1,
  70. z = pos.z + 0.1
  71. },
  72. minexptime = 0.1,
  73. maxexptime = 0.2,
  74. minsize = 0.50,
  75. maxsize = 0.50,
  76. collisiondetection = false,
  77. vertical = false,
  78. texture = "orb_of_ice_particle.png",
  79. })
  80. local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1)
  81. for k, obj in pairs(objs) do
  82. if obj:get_luaentity() ~= nil then
  83. local obj_name = obj:get_luaentity().name
  84. if obj_name ~= "orb_of_ice:icicle" and obj_name ~= "__builtin:item" and obj_name ~= "mobs_monster:mese_arrow" and obj_name ~= "mobs_monster:fireball" then
  85. obj:punch(self.object, 1.0, {
  86. full_punch_interval = 1.0,
  87. damage_groups = {fleshy = 3},
  88. }, nil)
  89. self.object:remove()
  90. end
  91. elseif obj:is_player() and obj:get_player_name() ~= self._owner then
  92. obj:punch(self.object, 1.0, {
  93. full_punch_interval = 1.0,
  94. damage_groups = {fleshy = 3},
  95. }, nil)
  96. self.object:remove()
  97. end
  98. end
  99. end
  100. })