Skip to content
Permalink
Browse files

Binoculars: Only set property if necessary to reduce mesh reloading

  • Loading branch information...
paramat committed Oct 30, 2017
1 parent 9596d00 commit 08c60cfc30563d0a6042d8bf2692deba06ac26cf
Showing with 12 additions and 8 deletions.
  1. +12 −8 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

0 comments on commit 08c60cf

Please sign in to comment.
You can’t perform that action at this time.