1
0
mirror of https://github.com/chylex/Better-Controls.git synced 2025-05-31 22:34:04 +02:00

Implement option to resume sprinting after hitting an obstacle

This commit is contained in:
chylex 2020-10-17 18:07:26 +02:00
parent bec0bcb597
commit b76a65fb70
4 changed files with 30 additions and 0 deletions

View File

@ -10,6 +10,7 @@ public final class BetterControlsConfig{
private Path path; private Path path;
public boolean doubleTapForwardToSprint = true; public boolean doubleTapForwardToSprint = true;
public boolean resumeSprintingAfterHittingObstacle = false;
public boolean sneakingMovesCameraSmoothly = true; public boolean sneakingMovesCameraSmoothly = true;

View File

@ -31,6 +31,7 @@ final class ConfigSerializer implements JsonSerializer<BetterControlsConfig>, Js
final JsonObject obj = new JsonObject(); final JsonObject obj = new JsonObject();
Json.setBool(obj, "Sprint.DoubleTapForward", cfg.doubleTapForwardToSprint); Json.setBool(obj, "Sprint.DoubleTapForward", cfg.doubleTapForwardToSprint);
Json.setBool(obj, "Sprint.ResumeAfterHittingObstacle", cfg.resumeSprintingAfterHittingObstacle);
Json.setBool(obj, "Sneak.SmoothCamera", cfg.sneakingMovesCameraSmoothly); Json.setBool(obj, "Sneak.SmoothCamera", cfg.sneakingMovesCameraSmoothly);
@ -49,6 +50,7 @@ final class ConfigSerializer implements JsonSerializer<BetterControlsConfig>, Js
final JsonObject obj = json.getAsJsonObject(); final JsonObject obj = json.getAsJsonObject();
cfg.doubleTapForwardToSprint = Json.getBool(obj, "Sprint.DoubleTapForward", cfg.doubleTapForwardToSprint); cfg.doubleTapForwardToSprint = Json.getBool(obj, "Sprint.DoubleTapForward", cfg.doubleTapForwardToSprint);
cfg.resumeSprintingAfterHittingObstacle = Json.getBool(obj, "Sprint.ResumeAfterHittingObstacle", cfg.resumeSprintingAfterHittingObstacle);
cfg.sneakingMovesCameraSmoothly = Json.getBool(obj, "Sneak.SmoothCamera", cfg.sneakingMovesCameraSmoothly); cfg.sneakingMovesCameraSmoothly = Json.getBool(obj, "Sneak.SmoothCamera", cfg.sneakingMovesCameraSmoothly);

View File

@ -42,6 +42,11 @@ public class BetterControlsScreen extends GameOptionsScreen{
generateLeftSideText(y, elements, Text.of("Double Tap 'Walk Forwards' To Sprint")); generateLeftSideText(y, elements, Text.of("Double Tap 'Walk Forwards' To Sprint"));
elements.add(new BooleanValueWidget(col2(1), y, COL2_W, cfg.doubleTapForwardToSprint, value -> cfg.doubleTapForwardToSprint = value)); elements.add(new BooleanValueWidget(col2(1), y, COL2_W, cfg.doubleTapForwardToSprint, value -> cfg.doubleTapForwardToSprint = value));
y += ROW_HEIGHT;
generateLeftSideText(y, elements, Text.of("Resume Sprinting After Hitting Obstacle"));
elements.add(new BooleanValueWidget(col2(1), y, COL2_W, cfg.resumeSprintingAfterHittingObstacle, value -> cfg.resumeSprintingAfterHittingObstacle = value));
y += ROW_HEIGHT; y += ROW_HEIGHT;
return y; return y;
} }

View File

@ -34,6 +34,9 @@ public final class PlayerTicker{
// Logic // Logic
private boolean wasHittingObstacle = false;
private boolean wasSprintingBeforeHittingObstacle = false;
private boolean wasSneakingBeforeTouchingGround = false; private boolean wasSneakingBeforeTouchingGround = false;
private boolean holdingSneakWhileTouchingGround = false; private boolean holdingSneakWhileTouchingGround = false;
@ -53,6 +56,25 @@ public final class PlayerTicker{
if (flightSpeed > 0F){ if (flightSpeed > 0F){
player.abilities.setFlySpeed(flightSpeed); player.abilities.setFlySpeed(flightSpeed);
} }
if (cfg().resumeSprintingAfterHittingObstacle){
if (wasHittingObstacle != player.horizontalCollision){
if (!wasHittingObstacle){
wasSprintingBeforeHittingObstacle = player.isSprinting() || mc().options.keySprint.isPressed();
}
else if (wasSprintingBeforeHittingObstacle){
wasSprintingBeforeHittingObstacle = false;
player.setSprinting(true);
}
// collision also stops when the player lets go of movement keys
wasHittingObstacle = player.horizontalCollision;
}
}
else{
wasHittingObstacle = player.horizontalCollision;
wasSprintingBeforeHittingObstacle = false;
}
} }
public void afterSuperCall(final ClientPlayerEntity player){ public void afterSuperCall(final ClientPlayerEntity player){