1
0
Fork 0

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