Update helptext of obsidian
[MineClone/MineClone2.git] / mods / ITEMS / mcl_maps / init.lua
blob893e7007368a65fd7774776a22bf9ee721c6ba0e
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")
6 itemstack:take_item()
7 if itemstack:is_empty() then
8 return new_map
9 else
10 local inv = placer:get_inventory()
11 if inv:room_for_item("main", new_map) then
12 inv:add_item("main", new_map)
13 else
14 minetest.add_item(placer:get_pos(), new_map)
15 end
16 return itemstack
17 end
18 end
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,
28 stack_max = 64,
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()
35 for i=1, hotbar do
36 if inv:get_stack("main", i):get_name() == item then
37 return true
38 end
39 end
40 return false
41 end
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())
46 if creative then
47 player:hud_set_flags({minimap=true, minimap_radar = true})
48 else
49 if has_item_in_hotbar(player, "mcl_maps:filled_map") then
50 player:hud_set_flags({minimap = true, minimap_radar = false})
51 else
52 player:hud_set_flags({minimap = false, minimap_radar = false})
53 end
54 end
55 end
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."))
62 end
63 end
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)",
77 stack_max = 1,
79 on_use = use_minimap,
80 on_secondary_use = use_minimap,
83 minetest.register_craft({
84 output = "mcl_maps:filled_map",
85 recipe = {
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)
94 end)
96 local updatetimer = 0
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()
102 for i=1, #players do
103 update_minimap(players[i])
105 updatetimer = updatetimer - dtime
107 end)