2017-05-16 19:47:12 +02:00
|
|
|
|
|
|
|
--
|
2015-09-01 17:15:24 +02:00
|
|
|
-- Map handling
|
2017-05-16 19:47:12 +02:00
|
|
|
--
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2019-08-28 17:31:41 +02:00
|
|
|
local S = minetest.get_translator("nav")
|
|
|
|
|
2019-06-23 21:47:41 +02:00
|
|
|
-- Based on Minetest Game's map mod, licensed under MIT License.
|
|
|
|
|
2019-08-29 23:03:59 +02:00
|
|
|
nav.map = {}
|
2019-06-23 21:47:41 +02:00
|
|
|
|
|
|
|
-- Cache creative mode setting
|
|
|
|
|
|
|
|
local creative_mode_cache = minetest.settings:get_bool("creative_mode")
|
|
|
|
|
|
|
|
|
|
|
|
-- Update HUD flags
|
|
|
|
-- Global to allow overriding
|
|
|
|
|
2019-08-29 23:03:59 +02:00
|
|
|
function nav.map.update_hud_flags(player)
|
2019-06-23 21:47:41 +02:00
|
|
|
local creative_enabled =
|
2019-08-29 01:47:17 +02:00
|
|
|
(minetest.global_exists("creative") and creative.is_enabled_for(player:get_player_name())) or
|
2019-06-23 21:47:41 +02:00
|
|
|
creative_mode_cache
|
|
|
|
|
|
|
|
local minimap_enabled = creative_enabled or
|
|
|
|
player:get_inventory():contains_item("main", "nav:map")
|
|
|
|
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)
|
2019-08-29 23:03:59 +02:00
|
|
|
nav.map.update_hud_flags(player)
|
2019-06-23 21:47:41 +02:00
|
|
|
end)
|
|
|
|
|
2019-08-29 23:03:59 +02:00
|
|
|
-- Update HUD flags on inventory change. Sadly, this function is not exhaustive and doesn't capture all
|
|
|
|
-- inventory changes (such as changes by Lua).
|
|
|
|
|
|
|
|
minetest.register_on_player_inventory_action(function(player, action, inventory, inventory_info)
|
|
|
|
if action == "move" then
|
|
|
|
local stack_from = inventory:get_stack(inventory_info.from_list, inventory_info.from_index)
|
|
|
|
local stack_to = inventory:get_stack(inventory_info.to_list, inventory_info.to_index)
|
|
|
|
if stack_from:get_name() == "nav:map" or stack_to:get_name() == "nav:map" then
|
|
|
|
nav.map.update_hud_flags(player)
|
|
|
|
end
|
|
|
|
elseif action == "put" or action == "take" then
|
|
|
|
if inventory_info.stack:get_name() == "nav:map" then
|
|
|
|
nav.map.update_hud_flags(player)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
2019-06-23 21:47:41 +02:00
|
|
|
|
2019-08-29 23:03:59 +02:00
|
|
|
-- Cyclic update of HUD flags. Required because register_on_player_inventory_action does not
|
|
|
|
-- capture all changes.
|
2019-06-23 21:47:41 +02:00
|
|
|
|
|
|
|
local function cyclic_update()
|
|
|
|
for _, player in ipairs(minetest.get_connected_players()) do
|
2019-08-29 23:03:59 +02:00
|
|
|
nav.map.update_hud_flags(player)
|
2019-06-23 21:47:41 +02:00
|
|
|
end
|
|
|
|
minetest.after(5.3, cyclic_update)
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.after(5.3, cyclic_update)
|
|
|
|
|
|
|
|
|
2017-05-16 19:47:12 +02:00
|
|
|
-- Items
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_craftitem(
|
2015-10-02 22:58:37 +02:00
|
|
|
"nav:map",
|
|
|
|
{
|
2019-08-28 17:31:41 +02:00
|
|
|
description = S("Map"),
|
2019-12-05 10:30:46 +01:00
|
|
|
_tt_help = S("Carry this item and view the map with the 'minimap' key"),
|
2015-10-02 22:58:37 +02:00
|
|
|
inventory_image = "nav_inventory.png",
|
|
|
|
wield_image = "nav_inventory.png",
|
|
|
|
stack_max = 1,
|
2019-06-23 21:47:41 +02:00
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
2019-08-29 23:24:35 +02:00
|
|
|
minetest.chat_send_player(user:get_player_name(), minetest.colorize("#FFFF00", S("Use the minimap key to show the map.")))
|
2019-08-29 23:03:59 +02:00
|
|
|
nav.map.update_hud_flags(user)
|
2019-06-23 21:47:41 +02:00
|
|
|
end,
|
2017-05-16 19:47:12 +02:00
|
|
|
})
|
2015-10-02 22:58:37 +02:00
|
|
|
|
2017-05-16 19:47:12 +02:00
|
|
|
-- Crafting
|
|
|
|
|
|
|
|
crafting.register_craft(
|
2015-09-01 17:15:24 +02:00
|
|
|
{
|
|
|
|
output = "nav:map",
|
2017-05-16 19:47:12 +02:00
|
|
|
items = {
|
|
|
|
"default:stick 6",
|
|
|
|
"default:paper 3",
|
2015-09-01 17:15:24 +02:00
|
|
|
}
|
2017-05-16 19:47:12 +02:00
|
|
|
})
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
|
2015-10-25 22:18:54 +01:00
|
|
|
-- Achievements
|
|
|
|
|
|
|
|
achievements.register_achievement(
|
|
|
|
"navigator",
|
|
|
|
{
|
2019-08-28 17:31:41 +02:00
|
|
|
title = S("Navigator"),
|
2019-09-02 14:54:29 +02:00
|
|
|
description = S("Craft a map."),
|
2015-10-25 22:18:54 +01:00
|
|
|
times = 1,
|
|
|
|
craftitem = "nav:map",
|
2017-05-16 19:47:12 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
default.log("map", "loaded")
|