shrubs.lua 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. mapgen.generate_dry_shrubs = function(minp, maxp, seed)
  19. -- Don't generate underground, don't generate in highlands.
  20. if maxp.y < -50 or minp.y > 50 then
  21. return
  22. end
  23. local pr = PseudoRandom(seed + 819423)
  24. local count = pr:next(1, 20)
  25. for j=1, count, 1 do
  26. local xz = {x=pr:next(minp.x, maxp.x), z=pr:next(minp.z, maxp.z)}
  27. local pos, posb = find_surface(xz, minp.y, maxp.y)
  28. if pos then
  29. minetest.set_node(pos, {name="default:dry_shrub"})
  30. if pr:next(1, 20) == 1 then
  31. minetest.set_node(posb, {name="default:mossycobble"})
  32. else
  33. minetest.set_node(posb, {name="default:cobble"})
  34. end
  35. end
  36. end
  37. end