1 local S
= minetest
.get_translator("mcl_maps")
3 -- Turn empty map into filled map by rightclick
4 local make_filled_map
= function(itemstack
, placer
, pointed_thing
)
5 local new_map
= ItemStack("mcl_maps:filled_map")
7 if itemstack
:is_empty() then
10 local inv
= placer
:get_inventory()
11 if inv
:room_for_item("main", new_map
) then
12 inv
:add_item("main", new_map
)
14 minetest
.add_item(placer
:get_pos(), new_map
)
20 minetest
.register_craftitem("mcl_maps:empty_map", {
21 description
= S("Empty Map"),
22 _doc_items_longdesc
= S("Empty maps are not useful as maps, but they can be stacked and turned to maps which can be used."),
23 _doc_items_usagehelp
= S("Rightclick to start using the map (which can't be stacked anymore)."),
24 inventory_image
= "mcl_maps_map_empty.png",
25 groups
= { not_in_creative_inventory
= 1 },
26 on_place
= make_filled_map
,
27 on_secondary_use
= make_filled_map
,
31 local function has_item_in_hotbar(player
, item
)
32 -- Requirement: player carries the tool in the hotbar
33 local inv
= player
:get_inventory()
34 local hotbar
= player
:hud_get_hotbar_itemcount()
36 if inv
:get_stack("main", i
):get_name() == item
then
43 -- Checks if player is still allowed to display the minimap
44 local function update_minimap(player
)
45 local creative
= minetest
.is_creative_enabled(player
:get_player_name())
47 player
:hud_set_flags({minimap
=true, minimap_radar
= true})
49 if has_item_in_hotbar(player
, "mcl_maps:filled_map") then
50 player
:hud_set_flags({minimap
= true, minimap_radar
= false})
52 player
:hud_set_flags({minimap
= false, minimap_radar
= false})
57 -- Remind player how to use the minimap correctly
58 local function use_minimap(itemstack
, player
, pointed_thing
)
59 if player
and player
:is_player() then
60 update_minimap(player
)
61 minetest
.chat_send_player(player
:get_player_name(), S("Use the minimap key to show the map."))
65 -- Enables minimap if carried in hotbar.
66 -- If this item is NOT in the hotbar, the minimap is unavailable
67 -- Note: This is not at all like Minecraft right now. Minetest's minimap is pretty overpowered, it
68 -- has a very greatly zoomed-out version and even a radar mode
69 minetest
.register_craftitem("mcl_maps:filled_map", {
70 description
= S("Map"),
71 _tt_help
= S("Enables minimap"),
72 _doc_items_longdesc
= S("Maps show your surroundings as you explore the world."),
73 _doc_items_usagehelp
= S("Hold the map in any of the hotbar slots. This allows you to access the minimap by pressing the minimap key (see controls settings).").."\n"..
74 S("In Creative Mode, you don't need this item; the minimap is always available."),
75 groups
= { tool
= 1 },
76 inventory_image
= "mcl_maps_map_filled.png^(mcl_maps_map_filled_markings.png^[colorize:#000000)",
80 on_secondary_use
= use_minimap
,
83 minetest
.register_craft({
84 output
= "mcl_maps:filled_map",
86 { "mcl_core:paper", "mcl_core:paper", "mcl_core:paper" },
87 { "mcl_core:paper", "group:compass", "mcl_core:paper" },
88 { "mcl_core:paper", "mcl_core:paper", "mcl_core:paper" },
92 minetest
.register_on_joinplayer(function(player
)
93 update_minimap(player
)
97 if not minetest
.is_creative_enabled("") then
98 minetest
.register_globalstep(function(dtime
)
99 updatetimer
= updatetimer
+ dtime
100 if updatetimer
> 0.1 then
101 local players
= minetest
.get_connected_players()
103 update_minimap(players
[i
])
105 updatetimer
= updatetimer
- dtime