Define control(bits) as "unset" for entities (#11995)

This commit is contained in:
Lars Müller 2022-01-27 22:22:58 +01:00 committed by GitHub
parent 48e508052a
commit fe0b2d02bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 16 deletions

View File

@ -6716,18 +6716,21 @@ object you are working with still exists.
`aux1`, `sneak`, `dig`, `place`, `LMB`, `RMB`, and `zoom`. `aux1`, `sneak`, `dig`, `place`, `LMB`, `RMB`, and `zoom`.
* The fields `LMB` and `RMB` are equal to `dig` and `place` respectively, * The fields `LMB` and `RMB` are equal to `dig` and `place` respectively,
and exist only to preserve backwards compatibility. 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 * `get_player_control_bits()`: returns integer with bit packed player pressed
keys. Bits: keys.
* 0 - up * Bits:
* 1 - down * 0 - up
* 2 - left * 1 - down
* 3 - right * 2 - left
* 4 - jump * 3 - right
* 5 - aux1 * 4 - jump
* 6 - sneak * 5 - aux1
* 7 - dig * 6 - sneak
* 8 - place * 7 - dig
* 9 - zoom * 8 - place
* 9 - zoom
* Returns `0` (no bits set) if the object is not a player.
* `set_physics_override(override_table)` * `set_physics_override(override_table)`
* `override_table` is a table with the following fields: * `override_table` is a table with the following fields:
* `speed`: multiplier to default walking speed value (default: `1`) * `speed`: multiplier to default walking speed value (default: `1`)

View File

@ -1367,11 +1367,12 @@ int ObjectRef::l_get_player_control(lua_State *L)
NO_MAP_LOCK_REQUIRED; NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1); ObjectRef *ref = checkobject(L, 1);
RemotePlayer *player = getplayer(ref); RemotePlayer *player = getplayer(ref);
if (player == nullptr)
return 0;
const PlayerControl &control = player->getPlayerControl();
lua_newtable(L); lua_newtable(L);
if (player == nullptr)
return 1;
const PlayerControl &control = player->getPlayerControl();
lua_pushboolean(L, control.direction_keys & (1 << 0)); lua_pushboolean(L, control.direction_keys & (1 << 0));
lua_setfield(L, -2, "up"); lua_setfield(L, -2, "up");
lua_pushboolean(L, control.direction_keys & (1 << 1)); 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; NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1); ObjectRef *ref = checkobject(L, 1);
RemotePlayer *player = getplayer(ref); RemotePlayer *player = getplayer(ref);
if (player == nullptr) if (player == nullptr) {
return 0; lua_pushinteger(L, 0);
return 1;
}
const auto &c = player->getPlayerControl(); const auto &c = player->getPlayerControl();