init.lua 1.5 KB

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