init.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. -- map/init.lua
  2. -- Mod global namespace
  3. map = {}
  4. -- Load support for MT game translation.
  5. local S = minetest.get_translator("map")
  6. -- Cache creative mode setting
  7. local creative_mode_cache = minetest.settings:get_bool("creative_mode")
  8. -- Update HUD flags
  9. -- Global to allow overriding
  10. function map.update_hud_flags(player)
  11. local creative_enabled =
  12. (creative and creative.is_enabled_for(player:get_player_name())) or
  13. creative_mode_cache
  14. local minimap_enabled = creative_enabled or
  15. player:get_inventory():contains_item("main", "map:mapping_kit")
  16. local radar_enabled = creative_enabled
  17. player:hud_set_flags({
  18. minimap = minimap_enabled,
  19. minimap_radar = radar_enabled
  20. })
  21. end
  22. -- Set HUD flags 'on joinplayer'
  23. minetest.register_on_joinplayer(function(player)
  24. map.update_hud_flags(player)
  25. end)
  26. -- Cyclic update of HUD flags
  27. local function cyclic_update()
  28. for _, player in ipairs(minetest.get_connected_players()) do
  29. map.update_hud_flags(player)
  30. end
  31. minetest.after(5.3, cyclic_update)
  32. end
  33. minetest.after(5.3, cyclic_update)
  34. -- Mapping kit item
  35. minetest.register_craftitem("map:mapping_kit", {
  36. description = S("Mapping Kit") .. "\n" .. S("Use with 'Minimap' key"),
  37. inventory_image = "map_mapping_kit.png",
  38. stack_max = 1,
  39. groups = {flammable = 3},
  40. on_use = function(itemstack, user, pointed_thing)
  41. map.update_hud_flags(user)
  42. end,
  43. })
  44. -- Crafting
  45. minetest.register_craft({
  46. output = "map:mapping_kit",
  47. recipe = {
  48. {"default:glass", "default:paper", "group:stick"},
  49. {"default:steel_ingot", "default:paper", "default:steel_ingot"},
  50. {"group:wood", "default:paper", "dye:black"},
  51. }
  52. })
  53. -- Fuel
  54. minetest.register_craft({
  55. type = "fuel",
  56. recipe = "map:mapping_kit",
  57. burntime = 5,
  58. })