init.lua 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. -- Biome library mod by VanessaE
  2. --
  3. -- I got the temperature map idea from "hmmmm", values used for it came from
  4. -- Splizard's snow mod.
  5. --
  6. biome_lib = {}
  7. biome_lib.modpath = minetest.get_modpath("biome_lib")
  8. -- Boilerplate to support localized strings if intllib mod is installed.
  9. local S
  10. if minetest.global_exists("intllib") then
  11. if intllib.make_gettext_pair then
  12. S = intllib.make_gettext_pair()
  13. else
  14. S = intllib.Getter()
  15. end
  16. else
  17. S = function(s) return s end
  18. end
  19. biome_lib.intllib = S
  20. local c1 = minetest.settings:get("biome_lib_default_grow_through_nodes")
  21. biome_lib.default_grow_through_nodes = {["air"] = true}
  22. if c1 then
  23. for _, i in ipairs(tableize(c1)) do
  24. biome_lib.default_grow_through_nodes[i] = true
  25. end
  26. else
  27. biome_lib.default_grow_through_nodes["default:snow"] = true
  28. end
  29. local c2 = minetest.settings:get("biome_lib_default_water_nodes")
  30. biome_lib.default_water_nodes = {}
  31. if c2 then
  32. for _, i in ipairs(tableize(c2)) do
  33. biome_lib.default_water_nodes[i] = true
  34. end
  35. else
  36. biome_lib.default_water_nodes["default:water_source"] = true
  37. biome_lib.default_water_nodes["default:water_flowing"] = true
  38. biome_lib.default_water_nodes["default:river_water_source"] = true
  39. biome_lib.default_water_nodes["default:river_water_flowing"] = true
  40. end
  41. local c3 = minetest.settings:get("biome_lib_default_wet_surfaces")
  42. local c4 = minetest.settings:get("biome_lib_default_ground_nodes")
  43. local c5 = minetest.settings:get("biome_lib_default_grow_nodes")
  44. biome_lib.default_wet_surfaces = c3 and tableize(c3) or {"default:dirt", "default:dirt_with_grass", "default:sand"}
  45. biome_lib.default_ground_nodes = c4 and tableize(c4) or {"default:dirt_with_grass"}
  46. biome_lib.default_grow_nodes = c5 and tableize(c5) or {"default:dirt_with_grass"}
  47. biome_lib.debug_log_level = tonumber(minetest.settings:get("biome_lib_debug_log_level")) or 0
  48. local rr = tonumber(minetest.settings:get("biome_lib_queue_ratio")) or -200
  49. biome_lib.queue_ratio = 100 - rr
  50. biome_lib.entries_per_step = math.max(-rr, 1)
  51. -- the timer that manages the block timeout is in microseconds, but the timer
  52. -- that manages the queue wakeup call has to be in seconds, and works best if
  53. -- it takes a fraction of the block timeout interval.
  54. local t = tonumber(minetest.settings:get("biome_lib_block_timeout")) or 300
  55. biome_lib.block_timeout = t * 1000000
  56. -- we don't want the wakeup function to trigger TOO often,
  57. -- in case the user's block timeout setting is really low
  58. biome_lib.block_queue_wakeup_time = math.min(t/2, math.max(20, t/10))
  59. -- the actual important stuff starts here ;-)
  60. dofile(biome_lib.modpath .. "/api.lua")
  61. dofile(biome_lib.modpath .. "/search_functions.lua")
  62. dofile(biome_lib.modpath .. "/growth.lua")
  63. dofile(biome_lib.modpath .. "/compat.lua")
  64. minetest.after(0.01, function()
  65. -- report the final registration results and enable the active block queue stuff
  66. local n = #biome_lib.actionslist_aircheck + #biome_lib.actionslist_no_aircheck
  67. biome_lib.dbg("All mapgen registrations completed.", 0)
  68. if n > 0 then
  69. biome_lib.dbg("Total items/actions to handle manually: "..n.." ("..#biome_lib.actionslist_no_aircheck.." without air checks)", 0)
  70. biome_lib.dbg("Total surface types to handle manually: "..#biome_lib.surfaceslist_aircheck + #biome_lib.surfaceslist_no_aircheck, 0)
  71. else
  72. biome_lib.dbg("There are no \"handle manually\" items/actions registered,", 0)
  73. biome_lib.dbg("so the mapblock queue will not be not used this session.", 0)
  74. end
  75. biome_lib.dbg("Items sent to the engine's decorations handler: "..#biome_lib.registered_decorations, 0)
  76. biome_lib.dbg("Elevation range: "..biome_lib.mapgen_elevation_limit.min.." to "..string.format("%+d", biome_lib.mapgen_elevation_limit.max).." meters.", 0)
  77. if n > 0 then
  78. dofile(biome_lib.modpath .. "/block_queue_checks.lua")
  79. end
  80. end)