From 22c5f0f41eab57db93d7762e8c19840c05f59363 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 20 Feb 2017 00:51:28 +0100 Subject: [PATCH] Add a map imitation The map item just enables the minimap. It's pretty overpowered at the moment. --- mods/ITEMS/mcl_maps/init.lua | 81 ++++++++++++++++++ mods/ITEMS/mcl_maps/mod.conf | 1 + .../mcl_maps/textures/mcl_maps_map_empty.png | Bin 0 -> 274 bytes .../mcl_maps/textures/mcl_maps_map_filled.png | Bin 0 -> 274 bytes .../textures/mcl_maps_map_filled_markings.png | Bin 0 -> 15348 bytes mods/PLAYER/mcl_player/init.lua | 3 +- 6 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 mods/ITEMS/mcl_maps/init.lua create mode 100644 mods/ITEMS/mcl_maps/mod.conf create mode 100644 mods/ITEMS/mcl_maps/textures/mcl_maps_map_empty.png create mode 100644 mods/ITEMS/mcl_maps/textures/mcl_maps_map_filled.png create mode 100644 mods/ITEMS/mcl_maps/textures/mcl_maps_map_filled_markings.png diff --git a/mods/ITEMS/mcl_maps/init.lua b/mods/ITEMS/mcl_maps/init.lua new file mode 100644 index 000000000..e36a5abc8 --- /dev/null +++ b/mods/ITEMS/mcl_maps/init.lua @@ -0,0 +1,81 @@ +-- 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 + minetest.add_item(placer:getpos(), new_map) + end + return itemstack + end +end + +minetest.register_craftitem("mcl_maps:empty_map", { + description = "Empty Map", + 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, +}) + +-- 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", { + description = "Map", + inventory_image = "mcl_maps_map_filled.png^(mcl_maps_map_filled_markings.png^[colorize:#000000)", + stack_max = 1, +}) + +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 + +-- Checks if player is still allowed to display the minimap +local function update_minimap(player) + if has_item_in_hotbar(player, "mcl_maps:filled_map") then + player:hud_set_flags({minimap = true}) + else + player:hud_set_flags({minimap = false}) + end +end + +minetest.register_on_joinplayer(function(player) + update_minimap(player) +end) + +local updatetimer = 0 +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 + end +end) diff --git a/mods/ITEMS/mcl_maps/mod.conf b/mods/ITEMS/mcl_maps/mod.conf new file mode 100644 index 000000000..44c4becf0 --- /dev/null +++ b/mods/ITEMS/mcl_maps/mod.conf @@ -0,0 +1 @@ +name = mcl_maps diff --git a/mods/ITEMS/mcl_maps/textures/mcl_maps_map_empty.png b/mods/ITEMS/mcl_maps/textures/mcl_maps_map_empty.png new file mode 100644 index 0000000000000000000000000000000000000000..9b5aa7d6786c4d438b26fc52c4330300000ab766 GIT binary patch literal 274 zcmV+t0qy>YP)QD@YPF zn3d?`CvY4Is--7SdtZ4q9wn#`qGl`Q^x)|lKqS1i?%}RB^hltakOUXo&@17|(ctPv zWJ!1gEV#K7N)lEHW{ZtJ3&s}J;0PExjG6?}Ug0;QSvgj~)P0~yM1biVQ51Op8Et_U YH+FwY(|~K_rvLx|07*qoM6N<$f(!?72LJ#7 literal 0 HcmV?d00001 diff --git a/mods/ITEMS/mcl_maps/textures/mcl_maps_map_filled.png b/mods/ITEMS/mcl_maps/textures/mcl_maps_map_filled.png new file mode 100644 index 0000000000000000000000000000000000000000..9b5aa7d6786c4d438b26fc52c4330300000ab766 GIT binary patch literal 274 zcmV+t0qy>YP)QD@YPF zn3d?`CvY4Is--7SdtZ4q9wn#`qGl`Q^x)|lKqS1i?%}RB^hltakOUXo&@17|(ctPv zWJ!1gEV#K7N)lEHW{ZtJ3&s}J;0PExjG6?}Ug0;QSvgj~)P0~yM1biVQ51Op8Et_U YH+FwY(|~K_rvLx|07*qoM6N<$f(!?72LJ#7 literal 0 HcmV?d00001 diff --git a/mods/ITEMS/mcl_maps/textures/mcl_maps_map_filled_markings.png b/mods/ITEMS/mcl_maps/textures/mcl_maps_map_filled_markings.png new file mode 100644 index 0000000000000000000000000000000000000000..4f7e08cc18b32c907a4f5632d9db555da58f5472 GIT binary patch literal 15348 zcmeI3O^n+_6o996#m|-^)E`mxWYQM#=h%*8C$W-rx0@}yK(@;^(A^5Do!FDCwTW$P zr^zlLs?tjjAcPP?s0a2?ZspbkDiQ?*q7teAsT=^offE%HpmG2SRL0JqGn*Z)XeBOV z~Z5`b`3INzTJyn>)-(2v%^LG5{t*rckzwUCT7CZp9Y!BX> zz}shc0iazrOY{DG@kvd$>v3qYWR0BEX25QiocYL zjRyg_`Qj`$VY`S^;wrC8a)L``;*yd{q?3Zo5@%p2-MeLP#WdJcIX^Eg!ac%iGg-()Ck7p6;5C zZ`u|Y_=RP=;pbwpAW-k>?5pnd0$E;%9i}L>pd(0eQ5a@q=sg>!;nu>X8M=UKsE#b( z!*}MZEw+DCuC2(ZeW~~VzC!{=z8n*p`ks0@&rcEK|0jZD=j-nm_wf3aCJ0! z0&iu{u-*G+rJtMuPl0CLwWF4~j#;2-n}tWAouMq=t2W^x=-Y0|wrlz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