2019-09-10 19:09:51 +02:00
|
|
|
-- map/init.lua
|
|
|
|
|
2017-08-15 21:59:27 +02:00
|
|
|
-- Mod global namespace
|
|
|
|
|
|
|
|
map = {}
|
|
|
|
|
|
|
|
|
2019-09-10 19:09:51 +02:00
|
|
|
-- Load support for MT game translation.
|
|
|
|
local S = minetest.get_translator("map")
|
|
|
|
|
|
|
|
|
2017-08-15 21:59:27 +02:00
|
|
|
-- Cache creative mode setting
|
|
|
|
|
|
|
|
local creative_mode_cache = minetest.settings:get_bool("creative_mode")
|
|
|
|
|
|
|
|
|
|
|
|
-- Update HUD flags
|
|
|
|
-- Global to allow overriding
|
|
|
|
|
|
|
|
function map.update_hud_flags(player)
|
|
|
|
local creative_enabled =
|
|
|
|
(creative and creative.is_enabled_for(player:get_player_name())) or
|
|
|
|
creative_mode_cache
|
|
|
|
|
|
|
|
local minimap_enabled = creative_enabled or
|
|
|
|
player:get_inventory():contains_item("main", "map:mapping_kit")
|
|
|
|
local radar_enabled = creative_enabled
|
|
|
|
|
|
|
|
player:hud_set_flags({
|
|
|
|
minimap = minimap_enabled,
|
|
|
|
minimap_radar = radar_enabled
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- Set HUD flags 'on joinplayer'
|
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
map.update_hud_flags(player)
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
-- Cyclic update of HUD flags
|
|
|
|
|
|
|
|
local function cyclic_update()
|
|
|
|
for _, player in ipairs(minetest.get_connected_players()) do
|
|
|
|
map.update_hud_flags(player)
|
|
|
|
end
|
2017-10-24 05:51:53 +02:00
|
|
|
minetest.after(5.3, cyclic_update)
|
2017-08-15 21:59:27 +02:00
|
|
|
end
|
|
|
|
|
2017-10-24 05:51:53 +02:00
|
|
|
minetest.after(5.3, cyclic_update)
|
2017-08-15 21:59:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
-- Mapping kit item
|
|
|
|
|
|
|
|
minetest.register_craftitem("map:mapping_kit", {
|
2019-09-12 19:03:10 +02:00
|
|
|
description = S("Mapping Kit") .. "\n" .. S("Use with 'Minimap' key"),
|
2017-08-15 21:59:27 +02:00
|
|
|
inventory_image = "map_mapping_kit.png",
|
|
|
|
stack_max = 1,
|
|
|
|
groups = {flammable = 3},
|
2017-10-24 05:51:53 +02:00
|
|
|
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
|
|
map.update_hud_flags(user)
|
|
|
|
end,
|
2017-08-15 21:59:27 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
-- Crafting
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "map:mapping_kit",
|
|
|
|
recipe = {
|
2019-03-18 23:20:24 +01:00
|
|
|
{"default:glass", "default:paper", "group:stick"},
|
2017-08-15 21:59:27 +02:00
|
|
|
{"default:steel_ingot", "default:paper", "default:steel_ingot"},
|
2018-09-24 21:13:01 +02:00
|
|
|
{"group:wood", "default:paper", "dye:black"},
|
2017-08-15 21:59:27 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
-- Fuel
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
type = "fuel",
|
|
|
|
recipe = "map:mapping_kit",
|
|
|
|
burntime = 5,
|
|
|
|
})
|