From cc371ac726305cfca64fad257b2c5cd37afd80cb Mon Sep 17 00:00:00 2001 From: paramat Date: Wed, 30 Aug 2017 02:37:43 +0100 Subject: [PATCH] Add binoculars mod with binoculars item to allow zoom Uses the new player object property 'can zoom'. In survival mode, use of zoom requires the binoculars item in inventory. Zoom is automatically allowed in creative mode and for players with the 'creative' privilege. The binoculars.update_player_property() function is global so can be redefined by a mod for alternative behaviour. --- mods/binoculars/README.txt | 35 +++++++++ mods/binoculars/depends.txt | 2 + mods/binoculars/init.lua | 69 ++++++++++++++++++ mods/binoculars/license.txt | 59 +++++++++++++++ .../textures/binoculars_binoculars.png | Bin 0 -> 219 bytes 5 files changed, 165 insertions(+) create mode 100644 mods/binoculars/README.txt create mode 100644 mods/binoculars/depends.txt create mode 100644 mods/binoculars/init.lua create mode 100644 mods/binoculars/license.txt create mode 100644 mods/binoculars/textures/binoculars_binoculars.png diff --git a/mods/binoculars/README.txt b/mods/binoculars/README.txt new file mode 100644 index 00000000..3b90b4c4 --- /dev/null +++ b/mods/binoculars/README.txt @@ -0,0 +1,35 @@ +Minetest Game mod: binoculars +============================= +See license.txt for license information. + +Authors of source code +---------------------- +paramat (MIT) + +Authors of media (textures) +--------------------------- +paramat (CC BY-SA 3.0): + binoculars_binoculars.png + +Crafting +-------- +binoculars:binoculars + +default:obsidian_glass O +default:bronze_ingot B + +O_O +BBB +O_O + +Usage +----- +In survival mode, use of zoom requires the binoculars item in your inventory. +It can take up to 5 seconds for adding to or removal from inventory to have an +effect, however to instantly allow the use of zoom 'use' (leftclick) the item. + +Zoom is automatically allowed in creative mode and for any player with the +'creative' privilege. + +The 'binoculars.update_player_property()' function is global so can be +redefined by a mod for alternative behaviour. diff --git a/mods/binoculars/depends.txt b/mods/binoculars/depends.txt new file mode 100644 index 00000000..1f737c12 --- /dev/null +++ b/mods/binoculars/depends.txt @@ -0,0 +1,2 @@ +default +creative? diff --git a/mods/binoculars/init.lua b/mods/binoculars/init.lua new file mode 100644 index 00000000..050605c1 --- /dev/null +++ b/mods/binoculars/init.lua @@ -0,0 +1,69 @@ +-- Mod global namespace + +binoculars = {} + + +-- Cache creative mode setting + +local creative_mode_cache = minetest.settings:get_bool("creative_mode") + + +-- Update player property +-- Global to allow overriding + +function binoculars.update_player_property(player) + local creative_enabled = + (creative and creative.is_enabled_for(player:get_player_name())) or + creative_mode_cache + + if creative_enabled or + player:get_inventory():contains_item("main", "binoculars:binoculars") then + player:set_properties({can_zoom = true}) + else + player:set_properties({can_zoom = false}) + end +end + + +-- Set player property 'on joinplayer' + +minetest.register_on_joinplayer(function(player) + binoculars.update_player_property(player) +end) + + +-- Cyclic update of player property + +local function cyclic_update() + for _, player in ipairs(minetest.get_connected_players()) do + binoculars.update_player_property(player) + end + minetest.after(4.7, cyclic_update) +end + +minetest.after(4.7, cyclic_update) + + +-- Binoculars item + +minetest.register_craftitem("binoculars:binoculars", { + description = "Binoculars", + inventory_image = "binoculars_binoculars.png", + stack_max = 1, + + on_use = function(itemstack, user, pointed_thing) + binoculars.update_player_property(user) + end, +}) + + +-- Crafting + +minetest.register_craft({ + output = "binoculars:binoculars", + recipe = { + {"default:obsidian_glass", "", "default:obsidian_glass"}, + {"default:bronze_ingot", "default:bronze_ingot", "default:bronze_ingot"}, + {"default:obsidian_glass", "", "default:obsidian_glass"}, + } +}) diff --git a/mods/binoculars/license.txt b/mods/binoculars/license.txt new file mode 100644 index 00000000..f3aefda1 --- /dev/null +++ b/mods/binoculars/license.txt @@ -0,0 +1,59 @@ +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 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/binoculars/textures/binoculars_binoculars.png b/mods/binoculars/textures/binoculars_binoculars.png new file mode 100644 index 0000000000000000000000000000000000000000..5803d48f3b7b3b0cb5864680aa56d0b9e2e7a1ef GIT binary patch literal 219 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPHF4e$wZP0TD25D<`8Gt|-%bN8~W zu8HZY@$IYgo!ynUW@g3lEmMwdn|gU$$<-Yhzn|<9xR84YsFATG$S;_|;n|HeAScGt z#W95AdU8So^FD5YGZS(S