flowers.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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:tulip',
  21. 'flowers:dandelion_yellow',
  22. 'flowers:chrysanthemum_green',
  23. 'flowers:geranium',
  24. 'flowers:viola',
  25. 'flowers:dandelion_white',
  26. 'flowers:tulip_black',
  27. "flowers:delphinium",
  28. "flowers:thistle",
  29. "flowers:lazarus",
  30. "flowers:mannagrass",
  31. }
  32. local chose_flower = function(pr, pos)
  33. if flowers and flowers.datas then -- Only if flowers mod exists.
  34. local which = pr:next(1, #flowers_list)
  35. local name = flowers_list[which]
  36. minetest.set_node(pos, {name=name})
  37. end
  38. end
  39. mapgen.generate_flowers = function(minp, maxp, seed)
  40. -- Don't generate underground, don't generate in highlands.
  41. if maxp.y < -50 or minp.y > 300 then
  42. return
  43. end
  44. local pr = PseudoRandom(seed + 1892)
  45. local count = pr:next(1, 3)
  46. -- 1 in 3 chance per mapchunk.
  47. if count == 1 then
  48. local xz = {x=pr:next(minp.x, maxp.x), z=pr:next(minp.z, maxp.z)}
  49. local pos, posb = find_surface(xz, minp.y, maxp.y)
  50. -- Highlands only.
  51. if pos then
  52. if pos.y < 40 then return end
  53. chose_flower(pr, pos)
  54. -- Natural-grown flowers always appear on mossy cobble.
  55. --minetest.chat_send_player("MustTest", "# Server: Placed flower @ " .. rc.pos_to_namestr(pos) .. "!")
  56. minetest.set_node(posb, {name="default:mossycobble"})
  57. end
  58. end
  59. end