init.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. local version = {major = 0, minor = 0, revison = 8}
  2. vm_lighting_wand = {}
  3. while not vm_lighting_wand.loaded do
  4. local MT = minetest
  5. local creative_mode_cache = MT.settings:get_bool("creative_mode")
  6. local modname = MT.get_current_modname()
  7. local modpath = MT.get_modpath(modname)
  8. local enable_command = MT.settings:get_bool(modname .. "_command", false)
  9. local give_on_new = MT.settings:get_bool(modname .. "_give_on_new", false)
  10. local log_lvls = {"none", "error", "warning", "action", "info", "verbose"}
  11. local logger = function(log, level)
  12. level = level or "action"
  13. if not log_lvls[level] then
  14. level = "action"
  15. end
  16. MT.log(level, "[" .. modname .. "] " .. log)
  17. end
  18. local include = function(name)
  19. return dofile(modpath .. "/" .. name .. ".lua")
  20. end
  21. logger("Hello minetest", "action")
  22. -- Mods Global table
  23. vm_lighting_wand = {
  24. version = version,
  25. locate = MT.get_translator(modname),
  26. modname = modname,
  27. logger = logger,
  28. fsbuilder = include("core/fsbuilder"),
  29. round = function(value, decimals)
  30. if not value or value <= 0 then
  31. return 0
  32. end
  33. if decimals and decimals > 0 then
  34. local mult = 10 ^ decimals
  35. return math.floor(value * mult + 0.5) / mult
  36. end
  37. return math.ceil(math.floor(value + 0.5))
  38. end,
  39. is_creative_mode = function(player)
  40. return creative_mode_cache or MT.check_player_privs(player:get_player_name(), {creative = true})
  41. end
  42. }
  43. -- Wand "features"
  44. include("core/wand") -- on_use()
  45. include("core/power") -- Power API
  46. include("core/levels") -- Configure Levels
  47. include("core/gui") -- on_use() "2nd"
  48. include("core/effects") -- sound/particles
  49. include("core/ignored") -- Add a Node,Group or Drawtype to the ignore lists
  50. include("core/pointed_node") -- get pointed_node in the world
  51. include("core/detached") -- detached inventory to add "power"
  52. include("core/crafting") -- means to add a crafting recipe from the config file
  53. -- Only load the cmd if its enabled
  54. if enable_command then
  55. include("core/commands")
  56. end
  57. -- Configure "features"
  58. include("config")
  59. -- add Nodes and wand tool
  60. include("tools")
  61. include("nodes")
  62. --!config.lua can override this if set.
  63. -- try set a recipe if not already set
  64. if not vm_lighting_wand.has_valid_recipe() then
  65. -- Minetest game
  66. if MT.get_modpath("default") then
  67. vm_lighting_wand.set_crafting_items("default:meselamp", "default:obsidian")
  68. end
  69. -- Mineclone2
  70. if MT.get_modpath("mcl_core") and MT.get_modpath("mcl_nether") then
  71. vm_lighting_wand.set_crafting_items("mcl_nether:glowstone", "mcl_core:obsidian")
  72. end
  73. -- Hades Revisited
  74. if MT.get_modpath("hades_core") and MT.get_modpath("glowcrystals") then
  75. vm_lighting_wand.set_crafting_items("glowcrystals:glowcrystal_block", "hades_core:obsidian")
  76. end
  77. end
  78. -- try Register a crafting recipe if it was set
  79. vm_lighting_wand.add_crafting_recipe()
  80. -- give a new player a free wand, if enabled
  81. if give_on_new then
  82. MT.register_on_newplayer(
  83. function(player)
  84. local item = vm_lighting_wand.tool
  85. local inv = player:get_inventory()
  86. if inv:room_for_item("main", item) then
  87. inv:add_item("main", item)
  88. else
  89. MT.add_item(player:get_pos(), item)
  90. end
  91. end
  92. )
  93. end
  94. -- dont allow water to replace this nodes, this is only a test for so doesnt matter if the mods are installed or not
  95. vm_lighting_wand.add_ignored_onlighting("default:lava_source")
  96. vm_lighting_wand.add_ignored_onlighting("mcl_core:lava_source")
  97. vm_lighting_wand.add_ignored_onlighting("hades_core:lava_source")
  98. -- escape the loop
  99. vm_lighting_wand.loaded = true
  100. end