2
0

init.lua 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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, tool = 1},
  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. })