]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Define control(bits) as "unset" for entities (#11995)
authorLars Müller <34514239+appgurueu@users.noreply.github.com>
Thu, 27 Jan 2022 21:22:58 +0000 (22:22 +0100)
committerGitHub <noreply@github.com>
Thu, 27 Jan 2022 21:22:58 +0000 (22:22 +0100)
doc/lua_api.txt
src/script/lua_api/l_object.cpp

index e37567ec348e50af65500f45e6a4c5e250ad472b..faaed55e14c502e14b6d7e94246073196c14498e 100644 (file)
@@ -6716,18 +6716,21 @@ object you are working with still exists.
       `aux1`, `sneak`, `dig`, `place`, `LMB`, `RMB`, and `zoom`.
     * The fields `LMB` and `RMB` are equal to `dig` and `place` respectively,
       and exist only to preserve backwards compatibility.
+    * Returns an empty table `{}` if the object is not a player.
 * `get_player_control_bits()`: returns integer with bit packed player pressed
-  keys. Bits:
-    * 0 - up
-    * 1 - down
-    * 2 - left
-    * 3 - right
-    * 4 - jump
-    * 5 - aux1
-    * 6 - sneak
-    * 7 - dig
-    * 8 - place
-    * 9 - zoom
+  keys.
+    * Bits:
+        * 0 - up
+        * 1 - down
+        * 2 - left
+        * 3 - right
+        * 4 - jump
+        * 5 - aux1
+        * 6 - sneak
+        * 7 - dig
+        * 8 - place
+        * 9 - zoom
+    * Returns `0` (no bits set) if the object is not a player.
 * `set_physics_override(override_table)`
     * `override_table` is a table with the following fields:
         * `speed`: multiplier to default walking speed value (default: `1`)
index b177a9f7eb9f36171bf098b3357b25a624833cf2..407b48db0c251b6c56d25e79a02115ede4bb8b93 100644 (file)
@@ -1367,11 +1367,12 @@ int ObjectRef::l_get_player_control(lua_State *L)
        NO_MAP_LOCK_REQUIRED;
        ObjectRef *ref = checkobject(L, 1);
        RemotePlayer *player = getplayer(ref);
-       if (player == nullptr)
-               return 0;
 
-       const PlayerControl &control = player->getPlayerControl();
        lua_newtable(L);
+       if (player == nullptr)
+               return 1;
+       
+       const PlayerControl &control = player->getPlayerControl();
        lua_pushboolean(L, control.direction_keys & (1 << 0));
        lua_setfield(L, -2, "up");
        lua_pushboolean(L, control.direction_keys & (1 << 1));
@@ -1406,8 +1407,10 @@ int ObjectRef::l_get_player_control_bits(lua_State *L)
        NO_MAP_LOCK_REQUIRED;
        ObjectRef *ref = checkobject(L, 1);
        RemotePlayer *player = getplayer(ref);
-       if (player == nullptr)
-               return 0;
+       if (player == nullptr) {
+               lua_pushinteger(L, 0);
+               return 1;
+       }
 
        const auto &c = player->getPlayerControl();