init.lua 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. -- Start fresh.
  2. -- Any mods wishing to register additional ores must run after this one.
  3. minetest.clear_registered_ores()
  4. minetest.clear_registered_biomes()
  5. minetest.clear_registered_decorations()
  6. mapgen = mapgen or {}
  7. mapgen.modpath = minetest.get_modpath("mapgen")
  8. mapgen.report_time = mapgen.report_time or 0
  9. mapgen.report_chunks = mapgen.report_chunks or 0
  10. local reload_or_dofile = function(name, path)
  11. if minetest.get_modpath("reload") then
  12. reload.register_file(name, path)
  13. else
  14. dofile(path)
  15. end
  16. end
  17. if not mapgen.files_registered then
  18. local mp = mapgen.modpath
  19. -- Inform players.
  20. minetest.register_on_generated(function(minp, maxp, seed)
  21. local time = os.time() -- Time since epoc in seconds.
  22. if (time - mapgen.report_time) > 60 and mapgen.report_chunks > 0 then
  23. minetest.chat_send_all("# Server: Mapgen working, expect lag. (Chunks: " .. mapgen.report_chunks .. ".)")
  24. mapgen.report_time = time
  25. mapgen.report_chunks = 0
  26. end
  27. mapgen.report_chunks = mapgen.report_chunks + 1
  28. end)
  29. -- These files are reloadable. Their functions can be changed at runtime.
  30. reload_or_dofile("mapgen:shrubs", mp .. "/shrubs.lua")
  31. reload_or_dofile("mapgen:papyrus", mp .. "/papyrus.lua")
  32. reload_or_dofile("mapgen:grass", mp .. "/grass.lua")
  33. if minetest.get_modpath("flowers") then
  34. reload_or_dofile("mapgen:flowers", mp .. "/flowers.lua")
  35. reload_or_dofile("mapgen:mushrooms", mp .. "/mushrooms.lua")
  36. end
  37. -- Ore and biome registration.
  38. dofile(mp .. "/mg_alias.lua")
  39. dofile(mp .. "/mapgen.lua")
  40. dofile(mp .. "/biome.lua")
  41. minetest.register_on_generated(function(minp, maxp, seed)
  42. mapgen.generate_dry_shrubs (minp, maxp, seed)
  43. mapgen.generate_papyrus (minp, maxp, seed)
  44. mapgen.generate_grass (minp, maxp, seed)
  45. end)
  46. if minetest.get_modpath("flowers") then
  47. minetest.register_on_generated(function(minp, maxp, seed)
  48. mapgen.generate_flowers (minp, maxp, seed)
  49. mapgen.generate_mushrooms (minp, maxp, seed)
  50. end)
  51. end
  52. mapgen.files_registered = true
  53. end