diff options
author | SmallJoker <SmallJoker@users.noreply.github.com> | 2020-11-10 21:02:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-10 21:02:53 +0100 |
commit | fca4db4184ac054c53446c0960ec578ebc6b5857 (patch) | |
tree | d47685dde19e906b5aa2868c90c7e71da9720c43 /src | |
parent | 97aefe9b81414fa560d1ff37a3060266ac9735a9 (diff) | |
download | minetest-fca4db4184ac054c53446c0960ec578ebc6b5857.tar.gz minetest-fca4db4184ac054c53446c0960ec578ebc6b5857.tar.bz2 minetest-fca4db4184ac054c53446c0960ec578ebc6b5857.zip |
ObjectRef: Re-add legacy code for set_physics_override (#10585)
These arguments are used at least by MTG beds and homedecor_common. A deprecation warning is shown to safely remove it in a future release.
Diffstat (limited to 'src')
-rw-r--r-- | src/script/lua_api/l_object.cpp | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index a6a7c05f9..bc59bd55c 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -1413,20 +1413,34 @@ int ObjectRef::l_set_physics_override(lua_State *L) if (playersao == nullptr) return 0; - luaL_checktype(L, 2, LUA_TTABLE); - playersao->m_physics_override_speed = getfloatfield_default( - L, 2, "speed", playersao->m_physics_override_speed); - playersao->m_physics_override_jump = getfloatfield_default( - L, 2, "jump", playersao->m_physics_override_jump); - playersao->m_physics_override_gravity = getfloatfield_default( - L, 2, "gravity", playersao->m_physics_override_gravity); - playersao->m_physics_override_sneak = getboolfield_default( - L, 2, "sneak", playersao->m_physics_override_sneak); - playersao->m_physics_override_sneak_glitch = getboolfield_default( - L, 2, "sneak_glitch", playersao->m_physics_override_sneak_glitch); - playersao->m_physics_override_new_move = getboolfield_default( - L, 2, "new_move", playersao->m_physics_override_new_move); - playersao->m_physics_override_sent = false; + if (lua_istable(L, 2)) { + bool modified = false; + modified |= getfloatfield(L, 2, "speed", playersao->m_physics_override_speed); + modified |= getfloatfield(L, 2, "jump", playersao->m_physics_override_jump); + modified |= getfloatfield(L, 2, "gravity", playersao->m_physics_override_gravity); + modified |= getboolfield(L, 2, "sneak", playersao->m_physics_override_sneak); + modified |= getboolfield(L, 2, "sneak_glitch", playersao->m_physics_override_sneak_glitch); + modified |= getboolfield(L, 2, "new_move", playersao->m_physics_override_new_move); + if (modified) + playersao->m_physics_override_sent = false; + } else { + // old, non-table format + // TODO: Remove this code after version 5.4.0 + log_deprecated(L, "Deprecated use of set_physics_override(num, num, num)"); + + if (!lua_isnil(L, 2)) { + playersao->m_physics_override_speed = lua_tonumber(L, 2); + playersao->m_physics_override_sent = false; + } + if (!lua_isnil(L, 3)) { + playersao->m_physics_override_jump = lua_tonumber(L, 3); + playersao->m_physics_override_sent = false; + } + if (!lua_isnil(L, 4)) { + playersao->m_physics_override_gravity = lua_tonumber(L, 4); + playersao->m_physics_override_sent = false; + } + } return 0; } |