shrubs.lua 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. local name = "default:dry_shrub"
  30. if math.random(1, 2) == 1 then
  31. name = "default:dry_shrub2"
  32. end
  33. minetest.set_node(pos, {name=name})
  34. if pr:next(1, 20) == 1 then
  35. minetest.set_node(posb, {name="default:mossycobble"})
  36. else
  37. minetest.set_node(posb, {name="default:cobble"})
  38. end
  39. end
  40. end
  41. end