mushrooms.lua 869 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. local find_surface = function(xz, b, t)
  2. for j=b, t, 1 do
  3. local p1 = {x=xz.x, y=j, z=xz.z}
  4. local p2 = {x=xz.x, y=j+1, z=xz.z}
  5. local n1 = minetest.get_node(p1).name
  6. local n2 = minetest.get_node(p2).name
  7. if n2 == 'air' and n1 == 'default:stone' then
  8. return p2, p1
  9. end
  10. end
  11. end
  12. mapgen.generate_mushrooms = function(minp, maxp, seed)
  13. if maxp.y < -128 or minp.y > 20 then
  14. return
  15. end
  16. local pr = PseudoRandom(seed + 9488)
  17. local count = pr:next(1, 5)
  18. for j=1, count, 1 do
  19. local xz = {x=pr:next(minp.x, maxp.x), z=pr:next(minp.z, maxp.z)}
  20. local pos, posb = find_surface(xz, minp.y, maxp.y)
  21. if pos then
  22. if pr:next(1, 2) == 1 then
  23. minetest.set_node(pos, {name="flowers:mushroom_red"})
  24. else
  25. minetest.set_node(pos, {name="flowers:mushroom_brown"})
  26. end
  27. minetest.set_node(posb, {name="default:mossycobble"})
  28. end
  29. end
  30. end