grass.lua 1.5 KB

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