1
0
mirror of https://github.com/minetest/minetest_game.git synced 2024-12-23 07:10:19 +01:00

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

View File

@ -3,7 +3,12 @@
binoculars = {} 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") 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) function binoculars.update_player_property(player)
local creative_enabled = 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 creative_mode_cache
-- Only set property if necessary to avoid player mesh reload
if creative_enabled or local new_can_zoom = creative_enabled or player:get_inventory():contains_item(
player:get_inventory():contains_item("main", "binoculars:binoculars") then "main", "binoculars:binoculars")
player:set_properties({can_zoom = true}) if player:get_properties().can_zoom ~= new_can_zoom then
else player:set_properties({can_zoom = new_can_zoom})
player:set_properties({can_zoom = false})
end end
end end