Skip to content

Commit

Permalink
Make stick shaker fade in/out
Browse files Browse the repository at this point in the history
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
  • Loading branch information
Octol1ttle committed Sep 12, 2023
1 parent 57f10dd commit c200f49
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
9 changes: 9 additions & 0 deletions src/main/java/net/torocraft/flighthud/AlertSoundInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,13 @@ public AlertSoundInstance(SoundEvent sound, float volume, Entity entity, boolean
this.attenuationType = AttenuationType.NONE;
this.repeat = repeat;
}

public void setVolume(float volume) {
this.volume = Math.max(0, Math.min(1, volume));
}

@Override
public boolean shouldAlwaysPlay() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ else if (secondsUntilGroundImpact <= lampThreshold || secondsUntilTerrainImpact
isElytraLow = updateElytraLow(computer);
secondsUntilTerrainImpact = updateUnsafeTerrainClearance(mc.player, computer);
updateUnsafeFireworks(mc.player);
if (wereFireworksSafe && !unsafeFireworkHands.isEmpty())
fireworkCount = countSafeFireworks(mc.player);

if (flightProtectionsEnabled) { // Make corrections to flight path to ensure safety
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ public void render(DrawContext context, MinecraftClient mc) {
}
lastAutopilotState = AutoFlightManager.autoPilotEnabled;

if (FlightSafetyMonitor.isStalling && CONFIG_SETTINGS.stickShaker && computer.velocityPerSecond.y <= -10) {
playStickShaker(mc);
drawCenteredWarning(mc, context, dim.wScreen, dim.hScreen / 2 + 10, highlight, "STALL");
} else stopEvent(mc, STICK_SHAKER);
tryPlayStickShaker(mc, context);

if (FlightSafetyMonitor.secondsUntilGroundImpact <= FlightSafetyMonitor.warningThreshold || FlightSafetyMonitor.secondsUntilTerrainImpact <= FlightSafetyMonitor.warningThreshold) {
playOnce(mc, PULL_UP, 0.75f, true);
Expand Down Expand Up @@ -167,10 +164,27 @@ private void playOnce(MinecraftClient mc, SoundEvent event, float volume, boolea
}
}

private void playStickShaker(MinecraftClient mc) {
if (!activeEvents.contains(FlightStatusIndicator.STICK_SHAKER)) {
mc.getSoundManager().play(new AlertSoundInstance(FlightStatusIndicator.STICK_SHAKER, (float) 0.75, mc.player, true));
activeEvents.add(FlightStatusIndicator.STICK_SHAKER);
private void tryPlayStickShaker(MinecraftClient mc, DrawContext context) {
if (FlightSafetyMonitor.isStalling) {
if (CONFIG_SETTINGS.stickShaker) {
if (stickShakerInstance == null) {
mc.getSoundManager().play(stickShakerInstance = new AlertSoundInstance(STICK_SHAKER, 0.0f, mc.player, true));
}

stickShakerInstance.setVolume(stickShakerInstance.getVolume() + deltaTime * 2.0f);
}
drawCenteredWarning(mc, context, dim.wScreen, dim.hScreen / 2 + 10, highlight, "STALL");
return;
}

if (stickShakerInstance == null) {
return;
}

stickShakerInstance.setVolume(stickShakerInstance.getVolume() - deltaTime * 2.0f);
if (stickShakerInstance.getVolume() <= 0.0f) {
mc.getSoundManager().stop(stickShakerInstance);
stickShakerInstance = null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class LivingEntityMixin {
@Inject(method = "onDamaged", at = @At("HEAD"))
public void detectWallCollision(DamageSource damageSource, CallbackInfo ci) {
LivingEntity $this = (LivingEntity) (Object) this;
if ($this instanceof ClientPlayerEntity && damageSource.isOf(DamageTypes.FLY_INTO_WALL))
if ($this instanceof ClientPlayerEntity && damageSource.isOf(DamageTypes.FLY_INTO_WALL)) {
FlightSafetyMonitor.thrustLocked = true;
}
}
}

0 comments on commit c200f49

Please sign in to comment.