mapgen.lua 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. moretrees = moretrees or {}
  2. local find_surface = function(xz, b, t)
  3. for j=t, b, -1 do
  4. local pos = {x=xz.x, y=j, z=xz.z}
  5. local n = minetest.get_node(pos).name
  6. if snow.is_snow(n) then
  7. local pb = {x=pos.x, y=pos.y-1, z=pos.z}
  8. local nb = minetest.get_node(pb).name
  9. if nb == "default:stone" then
  10. return pos, pb -- Position, position below.
  11. else
  12. break
  13. end
  14. elseif n == "default:stone" then
  15. break
  16. end
  17. end
  18. end
  19. local sapling_list = {
  20. [1] = 'moretrees:sequoia_sapling',
  21. [2] = 'moretrees:fir_sapling',
  22. [3] = 'moretrees:spruce_sapling',
  23. [4] = 'moretrees:apple_tree_sapling',
  24. [5] = 'moretrees:beech_sapling',
  25. [6] = 'moretrees:birch_sapling',
  26. [7] = 'moretrees:cedar_sapling',
  27. [8] = 'moretrees:oak_sapling',
  28. [9] = 'moretrees:palm_sapling',
  29. [10] = 'moretrees:poplar_sapling',
  30. [11] = 'moretrees:rubber_tree_sapling',
  31. [12] = 'moretrees:willow_sapling',
  32. [13] = 'moretrees:date_palm_sapling',
  33. [14] = 'moretrees:jungletree_sapling',
  34. }
  35. local chose_sapling = function(pr, pos)
  36. local which = pr:next(1, 14)
  37. local name = sapling_list[which]
  38. minetest.set_node(pos, {name=name})
  39. end
  40. moretrees.generate_flowers = function(minp, maxp, seed)
  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, 4)
  46. if count == 1 then
  47. local xz = {x=pr:next(minp.x, maxp.x), z=pr:next(minp.z, maxp.z)}
  48. local pos, posb = find_surface(xz, minp.y, maxp.y)
  49. -- Highlands only.
  50. if pos then
  51. if pos.y < 10 then return end
  52. chose_sapling(pr, pos)
  53. minetest.set_node(posb, {name="default:mossycobble"})
  54. end
  55. end
  56. end
  57. -- Register mapgen once only. Function is reloadable.
  58. if not moretrees.mapgen_registered then
  59. minetest.register_on_generated(function(minp, maxp, seed)
  60. moretrees.generate_flowers(minp, maxp, seed) end)
  61. moretrees.mapgen_registered = true
  62. end