Binoculars: Only set property if necessary to reduce mesh reloading

This commit is contained in:
paramat 2017-10-30 20:06:05 +00:00 committed by paramat
parent 9596d00a18
commit 08c60cfc30

@ -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