init.lua 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. local reload_or_dofile = function(name, path)
  9. if minetest.get_modpath("reload") then
  10. reload.register_file(name, path)
  11. else
  12. dofile(path)
  13. end
  14. end
  15. if not minetest.is_singleplayer() then
  16. if not mapgen.chat_registered then
  17. -- Set up vars.
  18. mapgen.report_time = mapgen.report_time or 0
  19. mapgen.report_chunks = mapgen.report_chunks or 0
  20. local function notify_chat(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(
  24. "# Server: Mapgen working, expect lag. (Chunks: " ..
  25. mapgen.report_chunks .. ".)")
  26. mapgen.report_time = time
  27. mapgen.report_chunks = 0
  28. end
  29. mapgen.report_chunks = mapgen.report_chunks + 1
  30. end
  31. -- Inform players periodically.
  32. minetest.register_on_generated(notify_chat)
  33. mapgen.chat_registered = true
  34. end
  35. end
  36. if not mapgen.files_registered then
  37. local mp = mapgen.modpath
  38. -- These files are reloadable. Their functions can be changed at runtime.
  39. reload_or_dofile("mapgen:shrubs", mp .. "/shrubs.lua")
  40. reload_or_dofile("mapgen:papyrus", mp .. "/papyrus.lua")
  41. reload_or_dofile("mapgen:grass", mp .. "/grass.lua")
  42. if minetest.get_modpath("flowers") then
  43. reload_or_dofile("mapgen:flowers", mp .. "/flowers.lua")
  44. reload_or_dofile("mapgen:mushrooms", mp .. "/mushrooms.lua")
  45. end
  46. -- Ore and biome registration.
  47. dofile(mp .. "/mg_alias.lua")
  48. dofile(mp .. "/mapgen.lua")
  49. dofile(mp .. "/biome.lua")
  50. minetest.register_on_generated(function(minp, maxp, seed)
  51. mapgen.generate_dry_shrubs(minp, maxp, seed)
  52. mapgen.generate_papyrus(minp, maxp, seed)
  53. mapgen.generate_grass(minp, maxp, seed)
  54. end)
  55. if minetest.get_modpath("flowers") then
  56. minetest.register_on_generated(function(minp, maxp, seed)
  57. mapgen.generate_flowers(minp, maxp, seed)
  58. mapgen.generate_mushrooms(minp, maxp, seed)
  59. end)
  60. end
  61. mapgen.files_registered = true
  62. end