Player: check that horizontal distance travelled is > 0 before adding exhaustion, or triggering a new chunk order

closes #4548
This commit is contained in:
Dylan K. Taylor 2021-11-05 15:46:55 +00:00
parent 5107d0df4e
commit 0989c77037
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -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;
}
}
}