From 08c60cfc30563d0a6042d8bf2692deba06ac26cf Mon Sep 17 00:00:00 2001 From: paramat Date: Mon, 30 Oct 2017 20:06:05 +0000 Subject: [PATCH] Binoculars: Only set property if necessary to reduce mesh reloading --- mods/binoculars/init.lua | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/mods/binoculars/init.lua b/mods/binoculars/init.lua index cd07ef9b..153044ae 100644 --- a/mods/binoculars/init.lua +++ b/mods/binoculars/init.lua @@ -3,7 +3,12 @@ binoculars = {} --- Cache creative mode setting +-- 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") @@ -13,14 +18,13 @@ local creative_mode_cache = minetest.settings:get_bool("creative_mode") function binoculars.update_player_property(player) local creative_enabled = - (creative and creative.is_enabled_for(player:get_player_name())) or + (creative_mod 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}) + -- 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}) end end -- 2.25.1