Files
Explosion-Overhaul/src/main/java/com/vinlanx/explosionoverhaul/client/DeafnessConcussionEffect.java

62 lines
2.0 KiB
Java
Raw Normal View History

2026-05-04 12:09:37 +02:00
package com.vinlanx.explosionoverhaul.client;
import net.minecraft.client.Minecraft;
public class DeafnessConcussionEffect {
public static boolean debugShowChat = false;
public static volatile boolean enabled = true;
2026-05-09 14:18:13 +02:00
private static int ticksRemaining;
private static int totalTicks;
private static float intensity;
2026-05-04 12:09:37 +02:00
public static boolean start(float intensity, double silentSeconds, double effectivePercent, String visibility, int intensityPercent) {
2026-05-09 14:18:13 +02:00
if (!enabled) {
return false;
}
DeafnessConcussionEffect.intensity = Math.max(DeafnessConcussionEffect.intensity, intensity);
totalTicks = Math.max(1, (int)Math.round(Math.max(1.0, silentSeconds) * 20.0));
ticksRemaining = Math.max(ticksRemaining, totalTicks);
LowPassConcussionEffect.setDeafnessGain((float)Math.max(0.18, 1.0 - intensity * 0.75));
return true;
2026-05-04 12:09:37 +02:00
}
public static void stop() {
2026-05-09 14:18:13 +02:00
ticksRemaining = 0;
intensity = 0.0f;
resetVolume();
2026-05-04 12:09:37 +02:00
}
public static boolean isActive() {
2026-05-09 14:18:13 +02:00
return enabled && ticksRemaining > 0 && intensity > 0.01f;
2026-05-04 12:09:37 +02:00
}
2026-05-06 23:46:53 +02:00
public static void resetVolume() {
2026-05-09 14:18:13 +02:00
LowPassConcussionEffect.setDeafnessGain(1.0f);
2026-05-04 12:09:37 +02:00
}
2026-05-06 23:46:53 +02:00
public static void applyMasterVolume(Minecraft mc, double volume) {
2026-05-04 12:09:37 +02:00
}
2026-05-09 14:18:13 +02:00
public static void onClientTick() {
if (ticksRemaining <= 0) {
stop();
return;
}
--ticksRemaining;
double remaining = ticksRemaining / Math.max(1.0, totalTicks);
LowPassConcussionEffect.setDeafnessGain((float)Math.max(0.18, lerp(1.0, 1.0 - intensity * 0.75, easeOutQuad(remaining))));
}
2026-05-06 23:46:53 +02:00
public static double lerp(double a, double b, double t) {
2026-05-04 12:09:37 +02:00
return a + (b - a) * t;
}
2026-05-06 23:46:53 +02:00
public static double easeOutQuad(double t) {
2026-05-04 12:09:37 +02:00
return 1.0 - (1.0 - t) * (1.0 - t);
}
2026-05-06 23:46:53 +02:00
public static double easeInOutQuad(double t) {
2026-05-04 12:09:37 +02:00
return t < 0.5 ? 2.0 * t * t : 1.0 - Math.pow(-2.0 * t + 2.0, 2.0) / 2.0;
}
}