From 5b1bc1d1138d28ae09b8f65d507794d1d79e50c2 Mon Sep 17 00:00:00 2001 From: SpacingBat3 Date: Sat, 21 Sep 2024 00:43:43 +0200 Subject: [PATCH] compat: Improvements and fixes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Improve `unregister` params to make function invocation a bit more compact and to drop unused ones. • Fix applying NodeCore workaround and make it independent from other configuration options. --- compat/init.lua | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/compat/init.lua b/compat/init.lua index ebaa376..e62be9b 100644 --- a/compat/init.lua +++ b/compat/init.lua @@ -7,7 +7,8 @@ local function mod_loaded(name) return table.indexof(minetest.get_modnames(),name) >= 0 end -local function unregister(list,callback,...) +local function unregister(api,callback) + local list = minetest["registered_"..api.."s"] local i = table.indexof(list, callback) local fn_orig = list[#list] -- It's somewhat tricky, but hooking it like that should be safe enough @@ -20,7 +21,7 @@ local function unregister(list,callback,...) end local function callback(player) - unregister(minetest.registered_on_joinplayers,callback,player) + unregister("on_joinplayer",callback) local ObjRef = getmetatable(player) local position_api = coreanim.register_fn(player,"set_bone_position") local override_api = coreanim.register_fn(player,"set_bone_override") @@ -46,16 +47,23 @@ local function callback(player) if mod_loaded("nc_player_model") and workaround_nc then local oldfn = player.set_bone_override ObjRef.set_bone_override = function(player,bone,override) - if bone == "Head" and override and override.rotation and override.rotation.interpolation then - override.rotation.interpolation = nil + local workaround_apply = false + if bone == "Head" and override then + if override.rotation and override.rotation.interpolation then + override.rotation.interpolation = nil + end + if override.position and override.position.interpolation then + override.position.interpolation = nil + end + workaround_apply = true end - if (shim and not override_api) or bone_override then + if (shim and not override_api) or flags.set_bone_override or workaround_apply then coreanim.set_bone_override(player,bone,override) else - oldfn.set_bone_override(player,bone,override) + oldfn(player,bone,override) end end - elseif (shim and not override_api) or bone_override then + elseif (shim and not override_api) or flags.set_bone_override then ObjRef.set_bone_override = coreanim.set_bone_override end end