From cabc79de361144d10ffe6bf6d4675211566e730b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20M=C3=BCller?= <34514239+appgurueu@users.noreply.github.com> Date: Fri, 21 Feb 2025 09:21:21 +0100 Subject: [PATCH] Work around wrong character bone rotations on Luanti 5.11+ (#6) --- init.lua | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/init.lua b/init.lua index c1383f0..38c1574 100644 --- a/init.lua +++ b/init.lua @@ -125,6 +125,17 @@ 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) @@ -140,9 +151,17 @@ 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 - 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) + 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 end end