init.lua 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. butterflying = {
  2. flies = {
  3. "butterflies:butterfly_white",
  4. "butterflies:butterfly_red",
  5. "butterflies:butterfly_violet",
  6. }
  7. }
  8. -- function butterflying.register_fly(name)
  9. -- table.insert(butterflying.flies, name)
  10. -- end
  11. minetest.register_abm({
  12. nodenames = {"group:flower"},
  13. interval = 30,
  14. chance = 120,
  15. action = function(pos, node)
  16. pos.y = pos.y + 1
  17. local n = minetest.get_node(pos)
  18. if n.name == "air" then
  19. minetest.set_node(pos, {name=butterflying.flies[math.random(#butterflying.flies)]})
  20. end
  21. end,
  22. })
  23. minetest.register_abm({
  24. nodenames = butterflying.flies,
  25. interval = 10,
  26. chance = 10,
  27. action = function(pos, node)
  28. local h = math.floor(math.random() * 1.98)
  29. local airs = minetest.find_nodes_in_area(
  30. {x=pos.x-1, y=pos.y-1, z=pos.z-1},
  31. {x=pos.x+1, y=pos.y+h, z=pos.z+1},
  32. {"air"}
  33. )
  34. if #airs == 0 then
  35. return
  36. end
  37. local to = airs[math.random(#airs)]
  38. minetest.swap_node(to, node)
  39. minetest.set_node(pos, {name="air"})
  40. end,
  41. })
  42. minetest.register_abm({
  43. nodenames = {
  44. "default:junglegrass",
  45. "default:grass_5",
  46. "default:fern_3",
  47. },
  48. interval = 45,
  49. chance = 320,
  50. action = function(pos, node)
  51. pos.y = pos.y + 1
  52. local n = minetest.get_node(pos)
  53. if n.name == "air" then
  54. minetest.set_node(pos, {name="fireflies:firefly"})
  55. end
  56. end,
  57. })
  58. minetest.register_abm({
  59. nodenames = "fireflies:firefly",
  60. interval = 10,
  61. chance = 10,
  62. action = function(pos, node)
  63. local h = math.floor(math.random() * 1.5)
  64. local airs = minetest.find_nodes_in_area(
  65. {x=pos.x-1, y=pos.y-1, z=pos.z-1},
  66. {x=pos.x+1, y=pos.y+h, z=pos.z+1},
  67. {"air"}
  68. )
  69. if #airs == 0 then
  70. return
  71. end
  72. local to = airs[math.random(#airs)]
  73. minetest.swap_node(to, node)
  74. minetest.set_node(pos, {name="air"})
  75. end,
  76. })