papyrus.lua 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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_papyrus = function(minp, maxp, seed)
  19. -- Don't generate underground, don't generate in highlands.
  20. if maxp.y < -50 or minp.y > 300 then
  21. return
  22. end
  23. local pr = PseudoRandom(seed + 1596)
  24. local count = pr:next(1, 10)
  25. -- 1 in 10 chance per mapchunk.
  26. if count == 1 then
  27. local xz = {x=pr:next(minp.x, maxp.x), z=pr:next(minp.z, maxp.z)}
  28. local pos, posb = find_surface(xz, minp.y, maxp.y)
  29. -- Highlands only.
  30. if pos then
  31. if pos.y < 40 then return end
  32. minetest.set_node(pos, {name="default:papyrus"})
  33. minetest.set_node(posb, {name="default:mossycobble"})
  34. end
  35. end
  36. end