2019-03-08 01:22:28 +02:00
local S = minetest.get_translator ( " mcl_maps " )
2017-02-20 01:51:28 +02:00
-- Turn empty map into filled map by rightclick
local make_filled_map = function ( itemstack , placer , pointed_thing )
local new_map = ItemStack ( " mcl_maps:filled_map " )
itemstack : take_item ( )
if itemstack : is_empty ( ) then
return new_map
else
local inv = placer : get_inventory ( )
if inv : room_for_item ( " main " , new_map ) then
inv : add_item ( " main " , new_map )
else
2019-02-01 07:33:07 +02:00
minetest.add_item ( placer : get_pos ( ) , new_map )
2017-02-20 01:51:28 +02:00
end
return itemstack
end
end
minetest.register_craftitem ( " mcl_maps:empty_map " , {
2019-03-08 01:22:28 +02:00
description = S ( " Empty Map " ) ,
_doc_items_longdesc = S ( " Empty maps are not useful as maps, but they can be stacked and turned to maps which can be used. " ) ,
_doc_items_usagehelp = S ( " Rightclick to start using the map (which can't be stacked anymore). " ) ,
2017-02-20 01:51:28 +02:00
inventory_image = " mcl_maps_map_empty.png " ,
groups = { not_in_creative_inventory = 1 } ,
on_place = make_filled_map ,
on_secondary_use = make_filled_map ,
stack_max = 64 ,
} )
2020-03-12 02:55:47 +02:00
-- Checks if player is still allowed to display the minimap
local function update_minimap ( player )
local creative = minetest.settings : get_bool ( " creative_mode " )
if creative then
player : hud_set_flags ( { minimap = true , minimap_radar = true } )
else
if has_item_in_hotbar ( player , " mcl_maps:filled_map " ) then
player : hud_set_flags ( { minimap = true , minimap_radar = false } )
else
player : hud_set_flags ( { minimap = false , minimap_radar = false } )
end
end
end
-- Remind player how to use the minimap correctly
local function use_minimap ( itemstack , player , pointed_thing )
if player and player : is_player ( ) then
update_minimap ( player )
minetest.chat_send_player ( player : get_player_name ( ) , S ( " Use the minimap key to show the map. " ) )
end
end
2017-02-20 01:51:28 +02:00
-- Enables minimap if carried in hotbar.
-- If this item is NOT in the hotbar, the minimap is unavailable
-- Note: This is not at all like Minecraft right now. Minetest's minimap is pretty overpowered, it
-- has a very greatly zoomed-out version and even a radar mode
minetest.register_craftitem ( " mcl_maps:filled_map " , {
2019-03-08 01:22:28 +02:00
description = S ( " Map " ) ,
2020-02-19 05:54:17 +02:00
_tt_help = S ( " Enables minimap " ) ,
2019-03-08 02:59:45 +02:00
_doc_items_longdesc = S ( " Maps show your surroundings as you explore the world. " ) ,
2019-03-15 07:12:03 +02:00
_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 " ..
S ( " In Creative Mode, you don't need this item; the minimap is always available. " ) ,
2019-02-06 12:15:53 +02:00
groups = { tool = 1 } ,
2017-02-20 01:51:28 +02:00
inventory_image = " mcl_maps_map_filled.png^(mcl_maps_map_filled_markings.png^[colorize:#000000) " ,
stack_max = 1 ,
2020-03-12 02:55:47 +02:00
on_use = use_minimap ,
on_secondary_use = use_minimap ,
2017-02-20 01:51:28 +02:00
} )
minetest.register_craft ( {
output = " mcl_maps:filled_map " ,
recipe = {
{ " mcl_core:paper " , " mcl_core:paper " , " mcl_core:paper " } ,
{ " mcl_core:paper " , " group:compass " , " mcl_core:paper " } ,
{ " mcl_core:paper " , " mcl_core:paper " , " mcl_core:paper " } ,
}
} )
local function has_item_in_hotbar ( player , item )
-- Requirement: player carries the tool in the hotbar
local inv = player : get_inventory ( )
local hotbar = player : hud_get_hotbar_itemcount ( )
for i = 1 , hotbar do
if inv : get_stack ( " main " , i ) : get_name ( ) == item then
return true
end
end
return false
end
minetest.register_on_joinplayer ( function ( player )
update_minimap ( player )
end )
local updatetimer = 0
2017-08-31 15:59:16 +03:00
if not minetest.settings : get_bool ( " creative_mode " ) then
minetest.register_globalstep ( function ( dtime )
updatetimer = updatetimer + dtime
if updatetimer > 0.1 then
local players = minetest.get_connected_players ( )
for i = 1 , # players do
update_minimap ( players [ i ] )
end
updatetimer = updatetimer - dtime
2017-02-20 01:51:28 +02:00
end
2017-08-31 15:59:16 +03:00
end )
end