mirror of
https://github.com/luanti-org/minetest_game.git
synced 2025-05-21 06:43:17 -04:00
Do not set properties if no change of collisionbox
This commit is contained in:
parent
fc86bf5a5f
commit
4c11937f81
1 changed files with 16 additions and 8 deletions
|
@ -68,9 +68,10 @@ function player_api.set_textures(player, textures)
|
||||||
end
|
end
|
||||||
|
|
||||||
function player_api.set_animation(player, anim_name, speed)
|
function player_api.set_animation(player, anim_name, speed)
|
||||||
-- Return if animation already applied to player
|
-- Return if no change of animation
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
if player_anim[name] == anim_name then
|
local old_anim_name = player_anim[name]
|
||||||
|
if anim_name == old_anim_name then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local model = player_model[name] and models[player_model[name]]
|
local model = player_model[name] and models[player_model[name]]
|
||||||
|
@ -80,16 +81,23 @@ function player_api.set_animation(player, anim_name, speed)
|
||||||
local anim = model.animations[anim_name]
|
local anim = model.animations[anim_name]
|
||||||
player_anim[name] = anim_name
|
player_anim[name] = anim_name
|
||||||
player:set_animation(anim, speed or model.animation_speed, animation_blend)
|
player:set_animation(anim, speed or model.animation_speed, animation_blend)
|
||||||
-- Set animation-dependent properties
|
-- Set animation-dependent collisionbox and eye_height
|
||||||
local eyeh
|
local old_cbox = model.collisionbox[old_anim_name] or model.collisionbox
|
||||||
|
local new_cbox = model.collisionbox[anim_name] or model.collisionbox
|
||||||
|
-- Return if no change of collisionbox
|
||||||
|
-- Assumes eye_height does not change if collisionbox does not change
|
||||||
|
if table.concat(new_cbox) == table.concat(old_cbox) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local new_eyeh
|
||||||
if type(model.eye_height) == "table" then
|
if type(model.eye_height) == "table" then
|
||||||
eyeh = model.eye_height[anim_name]
|
new_eyeh = model.eye_height[anim_name]
|
||||||
else -- number
|
else -- number
|
||||||
eyeh = model.eye_height
|
new_eyeh = model.eye_height
|
||||||
end
|
end
|
||||||
player:set_properties({
|
player:set_properties({
|
||||||
collisionbox = model.collisionbox[anim_name] or model.collisionbox,
|
collisionbox = new_cbox,
|
||||||
eye_height = eyeh,
|
eye_height = new_eyeh,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue