1 -- Turn empty map into filled map by rightclick
2 local make_filled_map
= function(itemstack
, placer
, pointed_thing
)
3 local new_map
= ItemStack("mcl_maps:filled_map")
5 if itemstack
:is_empty() then
8 local inv
= placer
:get_inventory()
9 if inv
:room_for_item("main", new_map
) then
10 inv
:add_item("main", new_map
)
12 minetest
.add_item(placer
:getpos(), new_map
)
18 minetest
.register_craftitem("mcl_maps:empty_map", {
19 description
= "Empty Map",
20 _doc_items_longdesc
= "Empty maps are not useful as maps, but they can be stacked and turned to maps which can be used.",
21 _doc_items_usagehelp
= "Rightclick to start using the map (which can't be stacked anymore).",
22 inventory_image
= "mcl_maps_map_empty.png",
23 groups
= { not_in_creative_inventory
= 1 },
24 on_place
= make_filled_map
,
25 on_secondary_use
= make_filled_map
,
29 -- Enables minimap if carried in hotbar.
30 -- If this item is NOT in the hotbar, the minimap is unavailable
31 -- Note: This is not at all like Minecraft right now. Minetest's minimap is pretty overpowered, it
32 -- has a very greatly zoomed-out version and even a radar mode
33 minetest
.register_craftitem("mcl_maps:filled_map", {
35 _doc_items_longdesc
= "Maps show your surroundings as you explore the world. They can even show you the world like a radar. MAGIC!\nNote: Maps are subject to change in future versions of MineClone 2.",
36 _doc_items_usagehelp
= "Hold the map in any of the hotbar slots. This allows you to access the minimap by pressing the minimap key ([F9] by default).\nIn Creative Mode, you don't need this item; the minimap is always available.",
37 inventory_image
= "mcl_maps_map_filled.png^(mcl_maps_map_filled_markings.png^[colorize:#000000)",
41 minetest
.register_craft({
42 output
= "mcl_maps:filled_map",
44 { "mcl_core:paper", "mcl_core:paper", "mcl_core:paper" },
45 { "mcl_core:paper", "group:compass", "mcl_core:paper" },
46 { "mcl_core:paper", "mcl_core:paper", "mcl_core:paper" },
50 local function has_item_in_hotbar(player
, item
)
51 -- Requirement: player carries the tool in the hotbar
52 local inv
= player
:get_inventory()
53 local hotbar
= player
:hud_get_hotbar_itemcount()
55 if inv
:get_stack("main", i
):get_name() == item
then
62 -- Checks if player is still allowed to display the minimap
63 local function update_minimap(player
)
64 if minetest
.settings
:get_bool("creative_mode") or has_item_in_hotbar(player
, "mcl_maps:filled_map") then
65 player
:hud_set_flags({minimap
= true})
67 player
:hud_set_flags({minimap
= false})
71 minetest
.register_on_joinplayer(function(player
)
72 update_minimap(player
)
76 if not minetest
.settings
:get_bool("creative_mode") then
77 minetest
.register_globalstep(function(dtime
)
78 updatetimer
= updatetimer
+ dtime
79 if updatetimer
> 0.1 then
80 local players
= minetest
.get_connected_players()
82 update_minimap(players
[i
])
84 updatetimer
= updatetimer
- dtime