2020-06-13 13:41:56 +02:00
|
|
|
-- Arguments
|
|
|
|
-- chunk: The chunk coordinate conversion API
|
|
|
|
-- audio: The audio playback API
|
|
|
|
-- map_formspec: The map display API
|
2020-06-10 13:02:46 +02:00
|
|
|
local chunk, audio, map_formspec = ...;
|
2020-06-09 01:49:23 +02:00
|
|
|
|
2020-02-16 18:55:07 +01:00
|
|
|
local MAXINT = 2147483647;
|
|
|
|
|
2020-06-13 15:08:01 +02:00
|
|
|
minetest.register_privilege("cartographer", {
|
|
|
|
description = "Allows use of the /map command to view local area maps",
|
2020-06-13 15:48:06 +02:00
|
|
|
give_to_singleplayer = false,
|
2020-06-13 15:08:01 +02:00
|
|
|
give_to_admin = true,
|
|
|
|
});
|
|
|
|
|
2020-04-21 13:29:30 +02:00
|
|
|
-- /map <detail> <scale> -- Displays a regional map around the player
|
2020-04-11 20:02:12 +02:00
|
|
|
-- (Optional)detail: Specifies the map's detail level. Defaults to the highest
|
|
|
|
-- available detail.
|
2020-04-21 13:29:30 +02:00
|
|
|
-- (Optional)scale: Specifies the map's scale. Defaults to 1.
|
2020-02-16 18:55:07 +01:00
|
|
|
minetest.register_chatcommand("map", {
|
2020-04-21 13:29:30 +02:00
|
|
|
params = "[<detail>] [<scale>]",
|
2020-06-13 15:08:01 +02:00
|
|
|
description = "Display a mapo of the local area",
|
|
|
|
privs = { cartographer = true },
|
2020-04-21 13:29:30 +02:00
|
|
|
func = function(name, param)
|
|
|
|
local detail, scale = param:match("(%d*) (%d*)");
|
|
|
|
|
|
|
|
if detail then
|
|
|
|
detail = tonumber(detail);
|
2020-04-26 16:21:24 +02:00
|
|
|
else
|
|
|
|
detail = MAXINT;
|
2020-04-21 13:29:30 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if scale then
|
|
|
|
scale = tonumber(scale);
|
2020-04-26 16:21:24 +02:00
|
|
|
else
|
|
|
|
scale = 1;
|
2020-02-16 18:55:07 +01:00
|
|
|
end
|
|
|
|
|
2020-06-10 13:06:59 +02:00
|
|
|
local player = minetest.get_player_by_name(name);
|
|
|
|
local pos = player:get_pos();
|
|
|
|
local player_x = math.floor((chunk.to(pos.x) / scale) + 0.5);
|
|
|
|
local player_z = math.floor((chunk.to(pos.z) / scale) + 0.5);
|
|
|
|
|
2020-06-10 13:02:46 +02:00
|
|
|
audio.play_feedback("cartographer_open_map", player);
|
2020-06-10 13:06:59 +02:00
|
|
|
minetest.show_formspec(name, "map", map_formspec.from_coords(player_x, player_z, 40, 40, detail, scale, true));
|
2020-02-16 18:55:07 +01:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
-- TODO: Remove before release
|
|
|
|
minetest.register_chatcommand("scan", {
|
|
|
|
func = function(name)
|
|
|
|
local player = minetest.get_player_by_name(name);
|
|
|
|
local pos = player:get_pos();
|
|
|
|
|
|
|
|
local b = minetest.get_biome_data(pos).biome;
|
|
|
|
minetest.chat_send_all(minetest.get_biome_name(b));
|
|
|
|
end,
|
|
|
|
})
|