Fix player teleportation bug whilst sneaking
authorHybridDog <ovvv@web.de>
Mon, 4 Jan 2016 16:21:33 +0000 (17:21 +0100)
committerparamat <mat.gregory@virginmedia.com>
Mon, 14 Mar 2016 08:44:28 +0000 (08:44 +0000)
Only set back position when sneaking if player wasn't teleported by adding and using a bool "got_teleported" to player
it fixes #2876

src/localplayer.cpp
src/network/clientpackethandler.cpp
src/player.cpp
src/player.h

index 0c94582aaa2be85186d8b88e5c7993427460aa39..dbd8c4a6113856c71400865ba153a0ef12eab1a2 100644 (file)
@@ -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);
@@ -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);
 
index a49bbe1675fb3c33d39c70c0fc653471b7edc2b7..28d147d38e3356622d5ebb54ee97618e3a70194b 100644 (file)
@@ -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"
index 623dde230e929bde78f1016859392729e2c17e7e..5949712a50c8673c01ad33dc666185e76bb30487 100644 (file)
@@ -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),
        touching_ground(false),
        in_liquid(false),
        in_liquid_stable(false),
index 50267c72cb01d6b3365710fa10dfdb54c4618dc9..b317cda4fbeaf3035c102365bb2fe3f2f6b3c04b 100644 (file)
@@ -318,6 +318,7 @@ public:
        // 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;