summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_object.cpp
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2020-10-04 00:33:45 +0100
committerGitHub <noreply@github.com>2020-10-04 00:33:45 +0100
commit3250b37e32f264db04c1ca449d9feefc22fd38b7 (patch)
tree9cb544e2e9df867bdc83f86c60d7fd912e0d0fe1 /src/script/lua_api/l_object.cpp
parent41a6136f774a30364b6d3fd2042c9dbeb34f2109 (diff)
downloadminetest-3250b37e32f264db04c1ca449d9feefc22fd38b7.tar.gz
minetest-3250b37e32f264db04c1ca449d9feefc22fd38b7.tar.bz2
minetest-3250b37e32f264db04c1ca449d9feefc22fd38b7.zip
Deprecate get_player_velocity and add_player_velocity (#10173)
Diffstat (limited to 'src/script/lua_api/l_object.cpp')
-rw-r--r--src/script/lua_api/l_object.cpp82
1 files changed, 37 insertions, 45 deletions
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index 24667e769..303b1175b 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -863,12 +863,21 @@ int ObjectRef::l_add_velocity(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
- LuaEntitySAO *co = getluaobject(ref);
- if (!co)
+ v3f vel = checkFloatPos(L, 2);
+
+ ServerActiveObject *obj = getobject(ref);
+ if (obj == nullptr)
return 0;
- v3f pos = checkFloatPos(L, 2);
- // Do it
- co->addVelocity(pos);
+
+ if (obj->getType() == ACTIVEOBJECT_TYPE_LUAENTITY) {
+ LuaEntitySAO *co = dynamic_cast<LuaEntitySAO*>(obj);
+ co->addVelocity(vel);
+ } else if (obj->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
+ PlayerSAO *player = dynamic_cast<PlayerSAO*>(obj);
+ player->setMaxSpeedOverride(vel);
+ getServer(L)->SendPlayerSpeed(player->getPeerID(), vel);
+ }
+
return 0;
}
@@ -877,11 +886,23 @@ int ObjectRef::l_get_velocity(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
- LuaEntitySAO *co = getluaobject(ref);
- if (co == NULL) return 0;
- // Do it
- v3f v = co->getVelocity();
- pushFloatPos(L, v);
+
+ ServerActiveObject *obj = getobject(ref);
+ if (obj == nullptr)
+ return 0;
+
+ if (obj->getType() == ACTIVEOBJECT_TYPE_LUAENTITY) {
+ LuaEntitySAO *co = dynamic_cast<LuaEntitySAO*>(obj);
+ v3f v = co->getVelocity();
+ pushFloatPos(L, v);
+ return 1;
+ } else if (obj->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
+ RemotePlayer *player = dynamic_cast<PlayerSAO*>(obj)->getPlayer();
+ push_v3f(L, player->getSpeed() / BS);
+ return 1;
+ }
+
+ lua_pushnil(L);
return 1;
}
@@ -1082,38 +1103,6 @@ int ObjectRef::l_get_player_name(lua_State *L)
return 1;
}
-// get_player_velocity(self)
-int ObjectRef::l_get_player_velocity(lua_State *L)
-{
- NO_MAP_LOCK_REQUIRED;
- ObjectRef *ref = checkobject(L, 1);
- RemotePlayer *player = getplayer(ref);
- if (player == NULL) {
- lua_pushnil(L);
- return 1;
- }
- // Do it
- push_v3f(L, player->getSpeed() / BS);
- return 1;
-}
-
-// add_player_velocity(self, {x=num, y=num, z=num})
-int ObjectRef::l_add_player_velocity(lua_State *L)
-{
- NO_MAP_LOCK_REQUIRED;
- ObjectRef *ref = checkobject(L, 1);
- v3f vel = checkFloatPos(L, 2);
-
- PlayerSAO *co = getplayersao(ref);
- if (!co)
- return 0;
-
- // Do it
- co->setMaxSpeedOverride(vel);
- getServer(L)->SendPlayerSpeed(co->getPeerID(), vel);
- return 0;
-}
-
// get_look_dir(self)
int ObjectRef::l_get_look_dir(lua_State *L)
{
@@ -2288,10 +2277,14 @@ luaL_Reg ObjectRef::methods[] = {
luamethod(ObjectRef, get_properties),
luamethod(ObjectRef, set_nametag_attributes),
luamethod(ObjectRef, get_nametag_attributes),
- // LuaEntitySAO-only
+
luamethod_aliased(ObjectRef, set_velocity, setvelocity),
luamethod(ObjectRef, add_velocity),
+ {"add_player_velocity", ObjectRef::l_add_velocity},
luamethod_aliased(ObjectRef, get_velocity, getvelocity),
+ {"get_player_velocity", ObjectRef::l_get_velocity},
+
+ // LuaEntitySAO-only
luamethod_aliased(ObjectRef, set_acceleration, setacceleration),
luamethod_aliased(ObjectRef, get_acceleration, getacceleration),
luamethod_aliased(ObjectRef, set_yaw, setyaw),
@@ -2307,8 +2300,7 @@ luaL_Reg ObjectRef::methods[] = {
luamethod(ObjectRef, is_player),
luamethod(ObjectRef, is_player_connected),
luamethod(ObjectRef, get_player_name),
- luamethod(ObjectRef, get_player_velocity),
- luamethod(ObjectRef, add_player_velocity),
+
luamethod(ObjectRef, get_look_dir),
luamethod(ObjectRef, get_look_pitch),
luamethod(ObjectRef, get_look_yaw),