3 Commits

Author SHA1 Message Date
0b6bbe47e6 Merge remote-tracking branch 'upstream/master' into nalc-1.2-dev 2020-06-20 15:55:02 +02:00
e293ee8ece Merge branch 'master' of yunohost.local:minetest-mods/playeranim into nalc-1.2-dev 2019-12-22 14:40:00 +01:00
bb7d0c3057 Corrige avertissement de la variable globale player_api
- Teste l'existence de la variable globale player_api avant de la lire
- Ajoute un message de chargement du mod dans le journal "action"
2018-12-24 01:05:20 +01:00

View File

@ -22,17 +22,10 @@ end
-- stop player_api from messing stuff up (since 5.3)
if minetest.global_exists("player_api") then
minetest.register_on_mods_loaded(function()
for _, model in pairs(player_api.registered_models) do
if model.animations then
for _, animation in pairs(model.animations) do
animation.x = 0
animation.y = 0
end
end
end
end)
for _, v in pairs(player_api.registered_models["character.b3d"].animations) do
v.x = 0
v.y = 0
end
minetest.register_on_joinplayer(function(player)
player:set_local_animation(nil, nil, nil, nil, 0)
end)
@ -125,17 +118,6 @@ minetest.register_on_joinplayer(function(player)
players_animation_data:init_player(player)
end)
-- HACK work around https://github.com/luanti-org/luanti/issues/15692
-- Scales corresponding to default perfect 180° rotations in the character b3d model
local bone_workaround_scales = {
Body = vector.new(-1, 1, -1),
Arm_Left = vector.new(1, -1, -1),
Arm_Right = vector.new(1, -1, -1),
Leg_Left = vector.new(1, -1, -1),
Leg_Right = vector.new(1, -1, -1),
Cape = vector.new(1, -1, -1),
}
local vector_add, vector_equals = vector.add, vector.equals
local function rotate_bone(player, bone, rotation, position_optional)
local previous_rotation = players_animation_data:get_bone_rotation(player, bone)
@ -151,17 +133,9 @@ local function rotate_bone(player, bone, rotation, position_optional)
or not previous_position
or not vector_equals(rotation, previous_rotation)
or not vector_equals(position, previous_position) then
if player.set_bone_override then -- Luanti 5.9+
player:set_bone_override(bone, {
position = {vec = position, absolute = true},
rotation = {vec = rotation:apply(math.rad), absolute = true},
scale = {vec = bone_workaround_scales[bone], absolute = true},
})
else
player:set_bone_position(bone, position, rotation)
players_animation_data:set_bone_rotation(player, bone, rotation)
players_animation_data:set_bone_position(player, bone, position)
end
player:set_bone_position(bone, position, rotation)
players_animation_data:set_bone_rotation(player, bone, rotation)
players_animation_data:set_bone_position(player, bone, position)
end
end
@ -280,14 +254,7 @@ local function rotate_body_and_head(player)
if #yaw_history > BODY_ROTATION_DELAY then
local body_yaw = table_remove(yaw_history, 1)
local player_yaw = player:get_look_horizontal()
-- Get the difference and normalize it to [-180,180) range.
-- This will give the shortest rotation between head and body angles.
local angle = ((player_yaw - body_yaw + 3.0*math_pi) % (2.0*math_pi)) - math_pi
-- Arbitrary limit of the head turn angle
local limit = math_pi*0.3 -- value from 0 to pi, less than 0.45*pi looks good
-- Clamp the value to the limit
angle = math.max(math.min(angle, limit), -limit)
return math_deg(angle)
return math_deg(player_yaw - body_yaw)
end
return 0
end)()
@ -300,15 +267,7 @@ end
local function animate_player(player, dtime)
local data = get_animation(player)
if not data then
-- Minetest Engine workaround for 5.6.0-dev and older
-- minetest.register_globalstep may call to this function before the player is
-- initialized by minetest.register_on_joinplayer in player_api
return
end
local animation = data.animation
local animation = get_animation(player).animation
-- Yaw history
if animation == "lay" or animation == "sit" then
@ -357,3 +316,5 @@ minetest.register_globalstep(function(dtime)
animate_player(player, dtime)
end
end)
minetest.log("action", "[playeranim] loaded.")