flowers.lua 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. local find_surface = function(xz, b, t)
  2. for j=t, b, -1 do
  3. local pos = {x=xz.x, y=j, z=xz.z}
  4. local n = minetest.get_node(pos).name
  5. if snow.is_snow(n) then
  6. local pb = {x=pos.x, y=pos.y-1, z=pos.z}
  7. local nb = minetest.get_node(pb).name
  8. if nb == "default:stone" then
  9. return pos, pb -- Position, position below.
  10. else
  11. break
  12. end
  13. elseif n == "default:stone" then
  14. break
  15. end
  16. end
  17. end
  18. local flowers_list = {
  19. 'flowers:rose',
  20. 'flowers:rose_white',
  21. 'flowers:zinnia_red',
  22. 'flowers:tulip',
  23. 'flowers:dandelion_yellow',
  24. 'flowers:chrysanthemum_green',
  25. 'flowers:geranium',
  26. 'flowers:viola',
  27. 'flowers:foxglove_pink',
  28. "flowers:bluebell",
  29. "flowers:snapdragon",
  30. "flowers:forgetmenot",
  31. "flowers:daylily",
  32. "flowers:poppy_orange",
  33. "flowers:iris_black",
  34. "flowers:jack",
  35. "flowers:lupine_purple",
  36. 'flowers:dandelion_white',
  37. 'flowers:tulip_black',
  38. "flowers:delphinium",
  39. "flowers:lockspur",
  40. "flowers:thistle",
  41. "flowers:lazarus",
  42. "flowers:mannagrass",
  43. }
  44. local chose_flower = function(pr, pos)
  45. if flowers and flowers.datas then -- Only if flowers mod exists.
  46. local which = pr:next(1, #flowers_list)
  47. local name = flowers_list[which]
  48. minetest.set_node(pos, {name=name})
  49. end
  50. end
  51. mapgen.generate_flowers = function(minp, maxp, seed)
  52. -- Don't generate underground, don't generate in highlands.
  53. if maxp.y < -50 or minp.y > 300 then
  54. return
  55. end
  56. local pr = PseudoRandom(seed + 1892)
  57. local count = pr:next(1, 3)
  58. -- 1 in 3 chance per mapchunk.
  59. if count == 1 then
  60. local xz = {x=pr:next(minp.x, maxp.x), z=pr:next(minp.z, maxp.z)}
  61. local pos, posb = find_surface(xz, minp.y, maxp.y)
  62. -- Highlands only.
  63. if pos then
  64. if pos.y < 40 then return end
  65. chose_flower(pr, pos)
  66. -- Natural-grown flowers always appear on mossy cobble.
  67. --minetest.chat_send_player("MustTest", "# Server: Placed flower @ " .. rc.pos_to_namestr(pos) .. "!")
  68. minetest.set_node(posb, {name="default:mossycobble"})
  69. end
  70. end
  71. end