spawn.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. local flowers = beautiflowers.flowers
  2. --[[Amount of flowers that you want to be generated
  3. 5 = normal
  4. less than 5= just a little
  5. more than 5 = a lot of flowers
  6. ]]--
  7. local FLOWERS_AMOUNT = 5
  8. --Maximun height that you want to spawn flowers (min 1, max 30000)
  9. local MAX_HEIGHT = 30000
  10. local function register_pasto(name)
  11. minetest.register_decoration({
  12. name = "beautiflowers:"..name,
  13. deco_type = "simple",
  14. place_on = {"default:dirt_with_grass","default:dirt"},
  15. sidelen = 16,
  16. noise_params = {
  17. offset = -0.03,
  18. scale = 0.07,
  19. spread = {x = 100, y = 100, z = 100},
  20. seed = 1602,
  21. octaves = 3,
  22. persist = 1,
  23. },
  24. y_max = 30000,
  25. y_min = 1,
  26. decoration = "beautiflowers:"..name,
  27. spawn_by = "default:dirt_with_grass"
  28. })
  29. end
  30. local function register_bonsai(name)
  31. minetest.register_decoration({
  32. name = "beautiflowers:"..name,
  33. deco_type = "simple",
  34. place_on = {"default:stone","default:cobble","default:mossycobble"},
  35. sidelen = 16,
  36. noise_params = {
  37. offset = -0.006,
  38. scale = 0.07,
  39. spread = {x = 250, y = 250, z = 250},
  40. seed = 2,
  41. octaves = 3,
  42. persist = 0.66,
  43. },
  44. y_max = 30000,
  45. y_min = 30,
  46. decoration = "beautiflowers:"..name,
  47. })
  48. end
  49. local function register_flower(name)
  50. local fill = (FLOWERS_AMOUNT/16000)
  51. minetest.register_decoration({
  52. name = "beautiflowers:"..name,
  53. deco_type = "simple",
  54. place_on = {"default:dirt_with_grass"},
  55. sidelen = 16,
  56. fill_ratio = fill,
  57. y_max = MAX_HEIGHT,
  58. y_min = 1,
  59. decoration = "beautiflowers:"..name,
  60. })
  61. end
  62. function beautiflowers.bonsai_spread(pos, node)
  63. if minetest.get_node_light(pos, 0.5) > 3 then
  64. if minetest.get_node_light(pos, nil) == 15 then
  65. minetest.remove_node(pos)
  66. end
  67. return
  68. end
  69. local positions = minetest.find_nodes_in_area_under_air(
  70. {x = pos.x - 1, y = pos.y - 2, z = pos.z - 1},
  71. {x = pos.x + 1, y = pos.y + 1, z = pos.z + 1},
  72. {"group:stone"})
  73. if #positions == 0 then
  74. return
  75. end
  76. local pos2 = positions[math.random(#positions)]
  77. pos2.y = pos2.y + 1
  78. if minetest.get_node_light(pos2, 0.5) <= 3 then
  79. minetest.set_node(pos2, {name = node.name})
  80. end
  81. end
  82. minetest.register_abm({
  83. label = "Bonsai spread",
  84. nodenames = {"beautiflowers:bonsai_1","beautiflowers:bonsai_2","beautiflowers:bonsai_3","beautiflowers:bonsai_4","beautiflowers:bonsai_5"},
  85. interval = 11,
  86. chance = 150,
  87. action = function(...)
  88. beautiflowers.bonsai_spread(...)
  89. end,
  90. })
  91. for i = 1, #flowers do
  92. local name = unpack(flowers[i])
  93. local aux = unpack(name:split("_"))
  94. if aux == "pasto" then
  95. register_pasto(name)
  96. else
  97. if aux == "bonsai" then
  98. register_bonsai(name)
  99. else
  100. register_flower(name)
  101. end
  102. end
  103. end