From 2824e4bb7c4e16c512c2d9a6260e1751516317cb Mon Sep 17 00:00:00 2001 From: paramat Date: Sun, 26 Nov 2017 04:40:59 +0000 Subject: [PATCH] Binoculars: Update to use 'zoom_fov' player property In survival mode, zoom is disabled, the binoculars item is needed to allow a zoom with a 10 degree FOV, realistic for compact binoculars. Creative mode or per-player creative privilege allows a zoom with a 15 degree field of view (the default MT engine zoom FOV). --- mods/binoculars/README.txt | 10 ++++++---- mods/binoculars/init.lua | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/mods/binoculars/README.txt b/mods/binoculars/README.txt index 3b90b4c4..0c65f6ea 100644 --- a/mods/binoculars/README.txt +++ b/mods/binoculars/README.txt @@ -24,12 +24,14 @@ O_O Usage ----- -In survival mode, use of zoom requires the binoculars item in your inventory. +In survival mode, use of zoom requires the binoculars item in your inventory, +they will allow a 10 degree field of view. 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. +effect, however to instantly allow the use of this zoom 'use' (leftclick) the +item. -Zoom is automatically allowed in creative mode and for any player with the -'creative' privilege. +Zoom with a field of view of 15 degrees 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/init.lua b/mods/binoculars/init.lua index 153044ae..0b43a061 100644 --- a/mods/binoculars/init.lua +++ b/mods/binoculars/init.lua @@ -4,12 +4,8 @@ binoculars = {} -- Detect creative mod - local creative_mod = minetest.get_modpath("creative") - - -- Cache creative mode setting as fallback if creative mod not present - local creative_mode_cache = minetest.settings:get_bool("creative_mode") @@ -20,11 +16,18 @@ function binoculars.update_player_property(player) local creative_enabled = (creative_mod and creative.is_enabled_for(player:get_player_name())) or creative_mode_cache + local new_zoom_fov = 0 + + if player:get_inventory():contains_item( + "main", "binoculars:binoculars") then + new_zoom_fov = 10 + elseif creative_enabled then + new_zoom_fov = 15 + end + -- Only set property if necessary to avoid player mesh reload - local new_can_zoom = creative_enabled or player:get_inventory():contains_item( - "main", "binoculars:binoculars") - if player:get_properties().can_zoom ~= new_can_zoom then - player:set_properties({can_zoom = new_can_zoom}) + if player:get_properties().zoom_fov ~= new_zoom_fov then + player:set_properties({zoom_fov = new_zoom_fov}) end end -- 2.25.1