Skip to content

Commit

Permalink
Fix player teleportation bug whilst sneaking
Browse files Browse the repository at this point in the history
Only set back position when sneaking if player wasn't teleported by adding and using a bool "got_teleported" to player
it fixes #2876
  • Loading branch information
HybridDog authored and paramat committed Mar 14, 2016
1 parent 5a40a7d commit c0b6986
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/localplayer.cpp
Expand Up @@ -183,7 +183,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
*/
if (control.sneak && m_sneak_node_exists &&
!(fly_allowed && g_settings->getBool("free_move")) && !in_liquid &&
physics_override_sneak) {
physics_override_sneak && !got_teleported) {
f32 maxd = 0.5 * BS + sneak_max;
v3f lwn_f = intToFloat(m_sneak_node, BS);
position.X = rangelim(position.X, lwn_f.X-maxd, lwn_f.X+maxd);
Expand All @@ -204,6 +204,9 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
}
}

if (got_teleported)
got_teleported = false;

// this shouldn't be hardcoded but transmitted from server
float player_stepheight = touching_ground ? (BS*0.6) : (BS*0.2);

Expand Down
1 change: 1 addition & 0 deletions src/network/clientpackethandler.cpp
Expand Up @@ -552,6 +552,7 @@ void Client::handleCommand_MovePlayer(NetworkPacket* pkt)

*pkt >> pos >> pitch >> yaw;

player->got_teleported = true;
player->setPosition(pos);

infostream << "Client got TOCLIENT_MOVE_PLAYER"
Expand Down
1 change: 1 addition & 0 deletions src/player.cpp
Expand Up @@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,


Player::Player(IGameDef *gamedef, const char *name):
got_teleported(false),

This comment has been minimized.

Copy link
@nerzhul

nerzhul Mar 15, 2016

Member

This attribute should be added to LocalPlayer, it's not used by RemotePlayer => exit.

This comment has been minimized.

Copy link
@HybridDog

HybridDog May 16, 2016

Author Contributor
touching_ground(false),
in_liquid(false),
in_liquid_stable(false),
Expand Down
1 change: 1 addition & 0 deletions src/player.h
Expand Up @@ -318,6 +318,7 @@ class Player
// Use a function, if isDead can be defined by other conditions
bool isDead() { return hp == 0; }

bool got_teleported;
bool touching_ground;
// This oscillates so that the player jumps a bit above the surface
bool in_liquid;
Expand Down

0 comments on commit c0b6986

Please sign in to comment.