grass.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 plants = {
  19. "default:junglegrass",
  20. "default:coarsegrass",
  21. "default:dry_grass_5",
  22. "default:grass_5",
  23. "pumpkin:plant_8",
  24. "tomato:plant_7",
  25. "carrot:plant_8",
  26. "blueberries:plant_4",
  27. "raspberries:plant_4",
  28. "potatoes:potato_4",
  29. "cucumber:cucumber_4",
  30. }
  31. mapgen.generate_grass = function(minp, maxp, seed)
  32. -- Don't generate underground, don't generate in highlands.
  33. if maxp.y < -50 or minp.y > 300 then
  34. return
  35. end
  36. local pr = PseudoRandom(seed + 6402)
  37. local count = pr:next(1, 2)
  38. -- 1 in 2 chance per mapchunk.
  39. if count == 1 then
  40. local xz = {x=pr:next(minp.x, maxp.x), z=pr:next(minp.z, maxp.z)}
  41. local pos, posb = find_surface(xz, minp.y, maxp.y)
  42. -- Highlands only.
  43. if pos then
  44. if pos.y < 10 then return end
  45. local which = plants[pr:next(1, #plants)]
  46. --if which == "default:coarsegrass" then
  47. -- minetest.chat_send_all(minetest.pos_to_string(pos))
  48. --end
  49. minetest.set_node(posb, {name="default:mossycobble"})
  50. minetest.set_node(pos, {name=which})
  51. end
  52. end
  53. end