Skip to content

Commit e40f25f

Browse files
committed
Minimap: Add 'map' mod with mapping kit item to enable minimap
In survival mode, use of the minimap requires the mapping kit item. Minimap radar mode is always disabled in survival mode. Minimap and minimap radar mode will be automatically enabled in creative mode and for any player with the 'creative' privilege. The 'map.update_hud_flags()' function is global so can be redefined by a mod for alternative behaviour.
1 parent 3611af1 commit e40f25f

File tree

5 files changed

+188
-0
lines changed

5 files changed

+188
-0
lines changed

mods/map/README.txt

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Minetest Game mod: map
2+
======================
3+
See license.txt for license information.
4+
5+
Authors of source code
6+
----------------------
7+
paramat (MIT)
8+
9+
Authors of media (textures)
10+
---------------------------
11+
TumeniNodes (CC BY-SA 3.0):
12+
map_mapping_kit.png (map)
13+
14+
paramat (CC BY-SA 3.0):
15+
map_mapping_kit.png (compass and pen)
16+
17+
Crafting
18+
--------
19+
map:mapping_kit
20+
21+
default:glass G
22+
default:paper P
23+
default:stick S
24+
default:steel_ingot I
25+
default:wood W
26+
dye:black D
27+
28+
GPS
29+
IPI
30+
WPD
31+
32+
Usage
33+
-----
34+
In survival mode, use of the minimap requires the mapping kit item in your
35+
inventory.
36+
Once crafted, to instantly enable, 'use' (left click) the item, otherwise the
37+
minimap will be automatically enabled a few seconds later.
38+
Minimap radar mode is always disabled in survival mode.
39+
40+
Minimap and minimap radar mode will be automatically enabled in creative mode
41+
and for any player with the 'creative' privilege.
42+
43+
The 'map.update_hud_flags()' function is global so can be redefined by a mod for
44+
alternative behaviour.

mods/map/depends.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
default
2+
dye
3+
creative?

mods/map/init.lua

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
-- Mod global namespace
2+
3+
map = {}
4+
5+
6+
-- Cache creative mode setting
7+
8+
local creative_mode_cache = minetest.settings:get_bool("creative_mode")
9+
10+
11+
-- Update HUD flags
12+
-- Global to allow overriding
13+
14+
function map.update_hud_flags(player)
15+
local creative_enabled =
16+
(creative and creative.is_enabled_for(player:get_player_name())) or
17+
creative_mode_cache
18+
19+
local minimap_enabled = creative_enabled or
20+
player:get_inventory():contains_item("main", "map:mapping_kit")
21+
local radar_enabled = creative_enabled
22+
23+
player:hud_set_flags({
24+
minimap = minimap_enabled,
25+
minimap_radar = radar_enabled
26+
})
27+
end
28+
29+
30+
-- Set HUD flags 'on joinplayer'
31+
32+
minetest.register_on_joinplayer(function(player)
33+
map.update_hud_flags(player)
34+
end)
35+
36+
37+
-- Cyclic update of HUD flags
38+
39+
local function cyclic_update()
40+
for _, player in ipairs(minetest.get_connected_players()) do
41+
map.update_hud_flags(player)
42+
end
43+
minetest.after(7, cyclic_update)
44+
end
45+
46+
minetest.after(7, cyclic_update)
47+
48+
49+
-- Mapping kit item
50+
51+
minetest.register_craftitem("map:mapping_kit", {
52+
description = "Mapping Kit",
53+
inventory_image = "map_mapping_kit.png",
54+
stack_max = 1,
55+
groups = {flammable = 3},
56+
-- For instant update of HUD flags
57+
on_use = function(itemstack, user, pointed_thing)
58+
map.update_hud_flags(user)
59+
end,
60+
})
61+
62+
63+
-- Crafting
64+
65+
minetest.register_craft({
66+
output = "map:mapping_kit",
67+
recipe = {
68+
{"default:glass", "default:paper", "default:stick"},
69+
{"default:steel_ingot", "default:paper", "default:steel_ingot"},
70+
{"default:wood", "default:paper", "dye:black"},
71+
}
72+
})
73+
74+
75+
-- Fuel
76+
77+
minetest.register_craft({
78+
type = "fuel",
79+
recipe = "map:mapping_kit",
80+
burntime = 5,
81+
})

mods/map/license.txt

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
License of source code
2+
----------------------
3+
4+
The MIT License (MIT)
5+
Copyright (C) 2017 paramat
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy of this
8+
software and associated documentation files (the "Software"), to deal in the Software
9+
without restriction, including without limitation the rights to use, copy, modify, merge,
10+
publish, distribute, sublicense, and/or sell copies of the Software, and to permit
11+
persons to whom the Software is furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all copies or
14+
substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
17+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
18+
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
19+
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21+
DEALINGS IN THE SOFTWARE.
22+
23+
For more details:
24+
https://opensource.org/licenses/MIT
25+
26+
27+
Licenses of media (textures)
28+
----------------------------
29+
30+
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
31+
Copyright (C) 2017 TumeniNodes
32+
Copyright (C) 2017 paramat
33+
34+
You are free to:
35+
Share — copy and redistribute the material in any medium or format.
36+
Adapt — remix, transform, and build upon the material for any purpose, even commercially.
37+
The licensor cannot revoke these freedoms as long as you follow the license terms.
38+
39+
Under the following terms:
40+
41+
Attribution — You must give appropriate credit, provide a link to the license, and
42+
indicate if changes were made. You may do so in any reasonable manner, but not in any way
43+
that suggests the licensor endorses you or your use.
44+
45+
ShareAlike — If you remix, transform, or build upon the material, you must distribute
46+
your contributions under the same license as the original.
47+
48+
No additional restrictions — You may not apply legal terms or technological measures that
49+
legally restrict others from doing anything the license permits.
50+
51+
Notices:
52+
53+
You do not have to comply with the license for elements of the material in the public
54+
domain or where your use is permitted by an applicable exception or limitation.
55+
No warranties are given. The license may not give you all of the permissions necessary
56+
for your intended use. For example, other rights such as publicity, privacy, or moral
57+
rights may limit how you use the material.
58+
59+
For more details:
60+
http://creativecommons.org/licenses/by-sa/3.0/

mods/map/textures/map_mapping_kit.png

763 Bytes
Loading

0 commit comments

Comments
 (0)