From 0989c77037f87654382f209c709b4e17f82549a0 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 5 Nov 2021 15:46:55 +0000 Subject: [PATCH] Player: check that horizontal distance travelled is > 0 before adding exhaustion, or triggering a new chunk order closes #4548 --- src/player/Player.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/player/Player.php b/src/player/Player.php index 866cbb967..0a00b4010 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -1186,16 +1186,18 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ $this->lastLocation = $to; $this->broadcastMovement(); - $distance = sqrt((($from->x - $to->x) ** 2) + (($from->z - $to->z) ** 2)); - //TODO: check swimming (adds 0.015 exhaustion in MCPE) - if($this->isSprinting()){ - $this->hungerManager->exhaust(0.1 * $distance, PlayerExhaustEvent::CAUSE_SPRINTING); - }else{ - $this->hungerManager->exhaust(0.01 * $distance, PlayerExhaustEvent::CAUSE_WALKING); - } + $horizontalDistanceTravelled = sqrt((($from->x - $to->x) ** 2) + (($from->z - $to->z) ** 2)); + if($horizontalDistanceTravelled > 0){ + //TODO: check swimming (adds 0.015 exhaustion in MCPE) + if($this->isSprinting()){ + $this->hungerManager->exhaust(0.1 * $horizontalDistanceTravelled, PlayerExhaustEvent::CAUSE_SPRINTING); + }else{ + $this->hungerManager->exhaust(0.01 * $horizontalDistanceTravelled, PlayerExhaustEvent::CAUSE_WALKING); + } - if($this->nextChunkOrderRun > 20){ - $this->nextChunkOrderRun = 20; + if($this->nextChunkOrderRun > 20){ + $this->nextChunkOrderRun = 20; + } } }