Don't always update shield texture using set_properties

This commit is contained in:
NO411 2022-03-18 23:23:01 +01:00
parent 7c0a48bebf
commit 6158e4e50d
1 changed files with 105 additions and 89 deletions

View File

@ -67,6 +67,7 @@ minetest.register_entity("mcl_shields:shield_entity", {
},
_blocking = false,
_shield_number = 2,
_texture_copy = "",
on_step = function(self, dtime, moveresult)
local player = self.object:get_attach()
if not player then
@ -96,7 +97,13 @@ minetest.register_entity("mcl_shields:shield_entity", {
if shield_is_enchanted(player, i) then
shield_texture = shield_texture .. overlay
end
if self._texture_copy ~= shield_texture then
self.object:set_properties({textures = {shield_texture}})
minetest.chat_send_all("updated")
end
self._texture_copy = shield_texture
end,
})
@ -297,16 +304,7 @@ local function update_shield_entity(player, blocking, i)
end
end
minetest.register_globalstep(function(dtime)
for _, player in pairs(minetest.get_connected_players()) do
handle_blocking(player)
local blocking, shieldstack = mcl_shields.is_blocking(player)
if blocking then
local shieldhud = shield_hud[player]
if not shieldhud then
local function add_shield_hud(shieldstack, player)
local texture = hud
if mcl_enchanting.is_enchanted(shieldstack:get_name()) then
texture = texture .. overlay
@ -328,7 +326,15 @@ minetest.register_globalstep(function(dtime)
})
playerphysics.add_physics_factor(player, "speed", "shield_speed", 0.5)
set_interact(player, nil)
else
end
local function update_shield_hud(player, blocking, shieldstack)
local shieldhud = shield_hud[player]
if not shieldhud then
add_shield_hud(shieldstack, player)
return
end
local wielditem = player:hud_get_flags().wielditem
if blocking == 1 then
if not wielditem then
@ -336,13 +342,11 @@ minetest.register_globalstep(function(dtime)
player:hud_change(shieldhud, "offset", {x = -100, y = 0})
player:hud_set_flags({wielditem = true})
end
else
if wielditem then
elseif wielditem then
player:hud_change(shieldhud, "text", hud)
player:hud_change(shieldhud, "offset", {x = 100, y = 0})
player:hud_set_flags({wielditem = false})
end
end
local image = player:hud_get(shieldhud).text
local enchanted = hud .. overlay
@ -363,7 +367,17 @@ minetest.register_globalstep(function(dtime)
player:hud_change(shieldhud, "text", hud)
end
end
end
end
minetest.register_globalstep(function(dtime)
for _, player in pairs(minetest.get_connected_players()) do
handle_blocking(player)
local blocking, shieldstack = mcl_shields.is_blocking(player)
if blocking then
update_shield_hud(player, blocking, shieldstack)
else
remove_shield_hud(player)
end
@ -439,7 +453,10 @@ local function to_shield_texture(banner_texture)
end
local function craft_banner_on_shield(itemstack, player, old_craft_grid, craft_inv)
if string.find(itemstack:get_name(), "mcl_shields:shield_") then
if not string.find(itemstack:get_name(), "mcl_shields:shield_") then
return itemstack
end
local shield_stack
for i = 1, player:get_inventory():get_size("craft") do
local stack = old_craft_grid[i]
@ -449,6 +466,7 @@ local function craft_banner_on_shield(itemstack, player, old_craft_grid, craft_i
break
end
end
for i = 1, player:get_inventory():get_size("craft") do
local banner_stack = old_craft_grid[i]
local banner_name = banner_stack:get_name()
@ -467,8 +485,6 @@ local function craft_banner_on_shield(itemstack, player, old_craft_grid, craft_i
break
end
end
end
return itemstack
end
minetest.register_craft_predict(function(itemstack, player, old_craft_grid, craft_inv)