feat: sprintable horse and boats

This commit is contained in:
Lord_Cambion 2026-04-14 17:33:07 +02:00
parent 02cac98645
commit 02ea52926c
3 changed files with 24 additions and 10 deletions

View file

@ -252,7 +252,7 @@ void LocalPlayer::aiStep()
bool forwardEnoughToContinueSprint = input->ya >= runTreshold;
// 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 ((onGround || isRiding()) && !isSprinting() && enoughFoodToSprint && !isUsingItem() && !hasEffect(MobEffect::blindness))
{
if( !wasRunning && forwardEnoughToTriggerSprint )
{
@ -278,7 +278,7 @@ void LocalPlayer::aiStep()
}
if (isSneaking()) sprintTriggerTime = 0;
#ifdef _WINDOWS64
if (input->sprinting && !isSprinting() && onGround && enoughFoodToSprint && !isUsingItem() && !hasEffect(MobEffect::blindness) && !isSneaking())
if (input->sprinting && !isSprinting() && (onGround || isRiding()) && enoughFoodToSprint && !isUsingItem() && !hasEffect(MobEffect::blindness) && !isSneaking())
{
setSprinting(true);
}

View file

@ -277,24 +277,36 @@ void Boat::tick()
shared_ptr<LivingEntity> livingRider = dynamic_pointer_cast<LivingEntity>(rider.lock());
double forward = livingRider->yya;
if (forward > 0)
if (forward != 0)
{
double riderXd = -sin(livingRider->yRot * PI / 180);
double riderZd = cos(livingRider->yRot * PI / 180);
xd += riderXd * acceleration * 0.05f;
zd += riderZd * acceleration * 0.05f;
float mult = livingRider->isSprinting() ? 2.0f : 1.0f;
float moveFactor = (float)forward;
if (forward < 0) moveFactor *= 0.5f; // Move slower backwards
xd += riderXd * acceleration * 0.05f * mult * moveFactor;
zd += riderZd * acceleration * 0.05f * mult * moveFactor;
}
}
double curSpeed = sqrt(xd * xd + zd * zd);
if (curSpeed > MAX_SPEED)
double maxSpeed = MAX_SPEED;
if (rider.lock() != nullptr && rider.lock()->instanceof(eTYPE_LIVINGENTITY))
{
double ratio = MAX_SPEED / curSpeed;
shared_ptr<LivingEntity> livingRider = dynamic_pointer_cast<LivingEntity>(rider.lock());
if (livingRider->isSprinting())
{
maxSpeed *= 1.5;
}
}
if (curSpeed > maxSpeed)
{
double ratio = maxSpeed / curSpeed;
xd *= ratio;
zd *= ratio;
curSpeed = MAX_SPEED;
curSpeed = maxSpeed;
}
if (curSpeed > lastSpeed && acceleration < MAX_ACCELERATION)

View file

@ -1416,7 +1416,9 @@ void EntityHorse::travel(float xa, float ya)
flyingSpeed = getSpeed() * .1f;
if (!level->isClientSide)
{
setSpeed(static_cast<float>(getAttribute(SharedMonsterAttributes::MOVEMENT_SPEED)->getValue()));
float speed = static_cast<float>(getAttribute(SharedMonsterAttributes::MOVEMENT_SPEED)->getValue());
if (livingRider->isSprinting()) speed *= 1.3f;
setSpeed(speed);
Animal::travel(xa, ya);
}