From 6cba5705dd24a3266cbfc729af0a96b06234fc34 Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Mon, 2 Mar 2026 01:21:56 +0800 Subject: fix: fix sprinting --- Minecraft.Client/LocalPlayer.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'Minecraft.Client/LocalPlayer.cpp') diff --git a/Minecraft.Client/LocalPlayer.cpp b/Minecraft.Client/LocalPlayer.cpp index aabd6a2b..ed286cd9 100644 --- a/Minecraft.Client/LocalPlayer.cpp +++ b/Minecraft.Client/LocalPlayer.cpp @@ -274,11 +274,13 @@ void LocalPlayer::aiStep() if (changingDimensionDelay > 0) changingDimensionDelay--; bool wasJumping = input->jumping; float runTreshold = 0.8f; + float sprintForward = input->sprintForward; - bool wasRunning = input->ya >= runTreshold; + bool wasRunning = sprintForward >= runTreshold; //input->tick( dynamic_pointer_cast( shared_from_this() ) ); // 4J-PB - make it a localplayer input->tick( this ); + sprintForward = input->sprintForward; if (isUsingItem()) { input->xa *= 0.2f; @@ -302,9 +304,20 @@ void LocalPlayer::aiStep() // world with low food, then reload it in creative. if(abilities.mayfly || isAllowedToFly() ) enoughFoodToSprint = true; + bool forwardEnoughToTriggerSprint = sprintForward >= runTreshold; + bool forwardReturnedToDeadzone = sprintForward == 0.0f; + bool forwardEnoughToContinueSprint = sprintForward >= runTreshold; + +#ifdef _WINDOWS64 + if (GetXboxPad() == 0 && input->usingKeyboardMovement) + { + forwardEnoughToContinueSprint = sprintForward > 0.0f; + } +#endif + #ifdef _WINDOWS64 // Keyboard sprint: Ctrl held while moving forward - if (GetXboxPad() == 0 && KMInput.IsKeyDown(VK_CONTROL) && input->ya > 0.0f && + if (GetXboxPad() == 0 && input->usingKeyboardMovement && KMInput.IsKeyDown(VK_CONTROL) && sprintForward > 0.0f && enoughFoodToSprint && !isUsingItem() && !hasEffect(MobEffect::blindness) && onGround) { if (!isSprinting()) setSprinting(true); @@ -314,7 +327,7 @@ void LocalPlayer::aiStep() // 4J - altered this slightly to make sure that the joypad returns to below returnTreshold in between registering two movements up to runThreshold if (onGround && !isSprinting() && enoughFoodToSprint && !isUsingItem() && !hasEffect(MobEffect::blindness)) { - if( !wasRunning && input->ya >= runTreshold ) + if( !wasRunning && forwardEnoughToTriggerSprint ) { if (sprintTriggerTime == 0) { @@ -331,7 +344,7 @@ void LocalPlayer::aiStep() } } } - else if( ( sprintTriggerTime > 0 ) && ( input->ya == 0.0f ) ) // ya of 0.0f here signifies that we have returned to the deadzone + else if( ( sprintTriggerTime > 0 ) && forwardReturnedToDeadzone ) // zero sprintForward here signifies that we have returned to the deadzone { sprintTriggerRegisteredReturn = true; } @@ -339,7 +352,7 @@ void LocalPlayer::aiStep() if (isSneaking()) sprintTriggerTime = 0; // 4J-PB - try not stopping sprint on collision //if (isSprinting() && (input->ya < runTreshold || horizontalCollision || !enoughFoodToSprint)) - if (isSprinting() && (input->ya < runTreshold || !enoughFoodToSprint)) + if (isSprinting() && (!forwardEnoughToContinueSprint || !enoughFoodToSprint || isSneaking() || isUsingItem())) { setSprinting(false); } @@ -1622,4 +1635,3 @@ void LocalPlayer::SetPlayerAdditionalModelParts(vectorpAdditionalMo { m_pAdditionalModelParts=pAdditionalModelParts; } - -- cgit v1.2.3