Skip to content

Commit c0b6986

Browse files
HybridDogparamat
authored andcommitted
Fix player teleportation bug whilst sneaking
Only set back position when sneaking if player wasn't teleported by adding and using a bool "got_teleported" to player it fixes #2876
1 parent 5a40a7d commit c0b6986

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed

src/localplayer.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
183183
*/
184184
if (control.sneak && m_sneak_node_exists &&
185185
!(fly_allowed && g_settings->getBool("free_move")) && !in_liquid &&
186-
physics_override_sneak) {
186+
physics_override_sneak && !got_teleported) {
187187
f32 maxd = 0.5 * BS + sneak_max;
188188
v3f lwn_f = intToFloat(m_sneak_node, BS);
189189
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,
204204
}
205205
}
206206

207+
if (got_teleported)
208+
got_teleported = false;
209+
207210
// this shouldn't be hardcoded but transmitted from server
208211
float player_stepheight = touching_ground ? (BS*0.6) : (BS*0.2);
209212

src/network/clientpackethandler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ void Client::handleCommand_MovePlayer(NetworkPacket* pkt)
552552

553553
*pkt >> pos >> pitch >> yaw;
554554

555+
player->got_teleported = true;
555556
player->setPosition(pos);
556557

557558
infostream << "Client got TOCLIENT_MOVE_PLAYER"

src/player.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3333

3434

3535
Player::Player(IGameDef *gamedef, const char *name):
36+
got_teleported(false),
3637
touching_ground(false),
3738
in_liquid(false),
3839
in_liquid_stable(false),

src/player.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ class Player
318318
// Use a function, if isDead can be defined by other conditions
319319
bool isDead() { return hp == 0; }
320320

321+
bool got_teleported;
321322
bool touching_ground;
322323
// This oscillates so that the player jumps a bit above the surface
323324
bool in_liquid;

0 commit comments

Comments
 (0)