init.lua 1.5 KB

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