From e40f25f1fbaa206fe229002d8608f729a1d0f268 Mon Sep 17 00:00:00 2001 From: paramat Date: Tue, 15 Aug 2017 20:59:27 +0100 Subject: [PATCH] Minimap: Add 'map' mod with mapping kit item to enable minimap In survival mode, use of the minimap requires the mapping kit item. Minimap radar mode is always disabled in survival mode. Minimap and minimap radar mode will be automatically enabled in creative mode and for any player with the 'creative' privilege. The 'map.update_hud_flags()' function is global so can be redefined by a mod for alternative behaviour. --- mods/map/README.txt | 44 ++++++++++++++ mods/map/depends.txt | 3 + mods/map/init.lua | 81 ++++++++++++++++++++++++++ mods/map/license.txt | 60 +++++++++++++++++++ mods/map/textures/map_mapping_kit.png | Bin 0 -> 763 bytes 5 files changed, 188 insertions(+) create mode 100644 mods/map/README.txt create mode 100644 mods/map/depends.txt create mode 100644 mods/map/init.lua create mode 100644 mods/map/license.txt create mode 100644 mods/map/textures/map_mapping_kit.png diff --git a/mods/map/README.txt b/mods/map/README.txt new file mode 100644 index 00000000..60422654 --- /dev/null +++ b/mods/map/README.txt @@ -0,0 +1,44 @@ +Minetest Game mod: map +====================== +See license.txt for license information. + +Authors of source code +---------------------- +paramat (MIT) + +Authors of media (textures) +--------------------------- +TumeniNodes (CC BY-SA 3.0): + map_mapping_kit.png (map) + +paramat (CC BY-SA 3.0): + map_mapping_kit.png (compass and pen) + +Crafting +-------- +map:mapping_kit + +default:glass G +default:paper P +default:stick S +default:steel_ingot I +default:wood W +dye:black D + +GPS +IPI +WPD + +Usage +----- +In survival mode, use of the minimap requires the mapping kit item in your +inventory. +Once crafted, to instantly enable, 'use' (left click) the item, otherwise the +minimap will be automatically enabled a few seconds later. +Minimap radar mode is always disabled in survival mode. + +Minimap and minimap radar mode will be automatically enabled in creative mode +and for any player with the 'creative' privilege. + +The 'map.update_hud_flags()' function is global so can be redefined by a mod for +alternative behaviour. diff --git a/mods/map/depends.txt b/mods/map/depends.txt new file mode 100644 index 00000000..4b15f6a3 --- /dev/null +++ b/mods/map/depends.txt @@ -0,0 +1,3 @@ +default +dye +creative? diff --git a/mods/map/init.lua b/mods/map/init.lua new file mode 100644 index 00000000..4dbc1bb6 --- /dev/null +++ b/mods/map/init.lua @@ -0,0 +1,81 @@ +-- Mod global namespace + +map = {} + + +-- Cache creative mode setting + +local creative_mode_cache = minetest.settings:get_bool("creative_mode") + + +-- Update HUD flags +-- Global to allow overriding + +function map.update_hud_flags(player) + local creative_enabled = + (creative and creative.is_enabled_for(player:get_player_name())) or + creative_mode_cache + + local minimap_enabled = creative_enabled or + player:get_inventory():contains_item("main", "map:mapping_kit") + local radar_enabled = creative_enabled + + player:hud_set_flags({ + minimap = minimap_enabled, + minimap_radar = radar_enabled + }) +end + + +-- Set HUD flags 'on joinplayer' + +minetest.register_on_joinplayer(function(player) + map.update_hud_flags(player) +end) + + +-- Cyclic update of HUD flags + +local function cyclic_update() + for _, player in ipairs(minetest.get_connected_players()) do + map.update_hud_flags(player) + end + minetest.after(7, cyclic_update) +end + +minetest.after(7, cyclic_update) + + +-- Mapping kit item + +minetest.register_craftitem("map:mapping_kit", { + description = "Mapping Kit", + inventory_image = "map_mapping_kit.png", + stack_max = 1, + groups = {flammable = 3}, + -- For instant update of HUD flags + on_use = function(itemstack, user, pointed_thing) + map.update_hud_flags(user) + end, +}) + + +-- Crafting + +minetest.register_craft({ + output = "map:mapping_kit", + recipe = { + {"default:glass", "default:paper", "default:stick"}, + {"default:steel_ingot", "default:paper", "default:steel_ingot"}, + {"default:wood", "default:paper", "dye:black"}, + } +}) + + +-- Fuel + +minetest.register_craft({ + type = "fuel", + recipe = "map:mapping_kit", + burntime = 5, +}) diff --git a/mods/map/license.txt b/mods/map/license.txt new file mode 100644 index 00000000..a89f59c4 --- /dev/null +++ b/mods/map/license.txt @@ -0,0 +1,60 @@ +License of source code +---------------------- + +The MIT License (MIT) +Copyright (C) 2017 paramat + +Permission is hereby granted, free of charge, to any person obtaining a copy of this +software and associated documentation files (the "Software"), to deal in the Software +without restriction, including without limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of the Software, and to permit +persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or +substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + +For more details: +https://opensource.org/licenses/MIT + + +Licenses of media (textures) +---------------------------- + +Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) +Copyright (C) 2017 TumeniNodes +Copyright (C) 2017 paramat + +You are free to: +Share — copy and redistribute the material in any medium or format. +Adapt — remix, transform, and build upon the material for any purpose, even commercially. +The licensor cannot revoke these freedoms as long as you follow the license terms. + +Under the following terms: + +Attribution — You must give appropriate credit, provide a link to the license, and +indicate if changes were made. You may do so in any reasonable manner, but not in any way +that suggests the licensor endorses you or your use. + +ShareAlike — If you remix, transform, or build upon the material, you must distribute +your contributions under the same license as the original. + +No additional restrictions — You may not apply legal terms or technological measures that +legally restrict others from doing anything the license permits. + +Notices: + +You do not have to comply with the license for elements of the material in the public +domain or where your use is permitted by an applicable exception or limitation. +No warranties are given. The license may not give you all of the permissions necessary +for your intended use. For example, other rights such as publicity, privacy, or moral +rights may limit how you use the material. + +For more details: +http://creativecommons.org/licenses/by-sa/3.0/ diff --git a/mods/map/textures/map_mapping_kit.png b/mods/map/textures/map_mapping_kit.png new file mode 100644 index 0000000000000000000000000000000000000000..015b878ad5e89994fb63b90c058a7d9e6d0ddb27 GIT binary patch literal 763 zcmVj3g=svTWG;tmJ)vkXqHZ~(ZaAlJHKlMmrEoo?aXzPV zKBaR(rF255bUvtbL8){o@UFQY{#E&&7f}2p=r&bZ_}o3)TV6IrftrueATOV)2w^at$on0fY+^d z*{yQet$5h3cG9nc(yxQju!GXDgVV5r+pu@jv4z~Rchs_m)U$-$vUb?EhTgV(+_r+* zw}#)ifZ(`+*}0D2xrX7ng5bM^;Jb?4yprO)gWBy1l%b4rTmg>x!?$Dg?(3|ejo$t|}@6w*t)z$ISp7GS5 z@YJI5)ui&*qw?3J^Vp{J*r)T^sPx&W-{0Tv?CAgh|CF1oxc~qF0d!JMQvg8b*k%9# z0OUzTK~xyiV_;x#E@gm%a!W9!6&jS7Q&v%!92BDI4HDqt=HwNXm6PJLAtr=KY7}%Iu8I|%X>*}ksBV8F-m>85;r?7J5ws&{6 zR^@tu1lSl^r^y%hPMpxwSnLN@p`;|wRnR+Wa&L2i4@dwA%-u5D`ujR+GCZIHPQm%L zO)U*2;f@SbJ0U9k6Vi*aqI_)_rh*+Nq^N6VVe4S1E+Gu&+oz?(#l}QOhs9?ag9QYY t#WYM^-0id_6+{fcUXg}*pHGc}0RU;tGDu-GPyYY_002ovPDHLkV1oS_i(CKz literal 0 HcmV?d00001