/* * Decompiled with CFR 0.152. */ package com.vinlanx.explosionoverhaul.client; import com.vinlanx.explosionoverhaul.Config; import com.vinlanx.explosionoverhaul.client.LowPassConcussionEffect; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.Options; import net.minecraft.client.player.LocalPlayer; import net.minecraft.network.chat.Component; import net.minecraft.sounds.SoundSource; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.loading.FMLEnvironment; @OnlyIn(value=Dist.CLIENT) @Mod.EventBusSubscriber(modid="explosionoverhaul", value={Dist.CLIENT}) public class DeafnessConcussionEffect { public static int DELAY_TICKS = 3; public static int FADE_TO_SILENT_TICKS = 5; public static int FADE_FROM_SILENT_TICKS = 100; private static Phase phase = Phase.NONE; private static int ticksInPhase = 0; private static int phaseTicksTotal = 0; private static int silentTicks = 0; private static double baseMasterVolume = 1.0; private static float currentIntensity = 0.0f; private static float lastIntensity = 0.0f; public static boolean debugShowChat = false; public static volatile boolean enabled = true; public static boolean start(float intensity, double silentSeconds, double effectivePercent, String visibility, int intensityPercent) { LocalPlayer player; float effectiveIntensity; if (!FMLEnvironment.dist.isClient()) { return false; } if (!enabled) { return false; } float f = effectiveIntensity = (Boolean)Config.CLIENT.enableDeafness.get() != false ? intensity : 0.001f; if (effectiveIntensity < 1.0E-4f) { return false; } Minecraft mc = Minecraft.m_91087_(); if (mc == null || mc.f_91073_ == null || mc.f_91074_ == null) { return false; } Options options = mc.f_91066_; if (options == null) { return false; } baseMasterVolume = (Double)options.m_246669_(SoundSource.MASTER).m_231551_(); if (phase != Phase.NONE) { currentIntensity = Math.min(1.0f, currentIntensity + effectiveIntensity); silentTicks = Math.min(2000, silentTicks + (int)Math.round(silentSeconds * 20.0)); if (phase != Phase.SILENT) { phase = Phase.FADE_IN; ticksInPhase = 0; phaseTicksTotal = FADE_TO_SILENT_TICKS; } } else { currentIntensity = effectiveIntensity; silentTicks = Math.max(0, (int)Math.round(silentSeconds * 20.0)); phase = Phase.DELAY; ticksInPhase = 0; phaseTicksTotal = DELAY_TICKS; } lastIntensity = currentIntensity; if (debugShowChat && (player = mc.f_91074_) != null) { String msg = String.format("\u041f\u043e\u0442\u0443\u0436\u043d\u0456\u0441\u0442\u044c \u043a\u043e\u043d\u0442\u0443\u0437\u0456\u0457 %.1f%% (%s) \u2014 \u0421\u0438\u043b\u0430 \u0441\u043a\u0440\u0443\u0447\u0443\u0432\u0430\u043d\u043d\u044f %d%%, \u0427\u0430\u0441 \u0441\u043a\u0440\u0443\u0447\u0443\u0432\u0430\u043d\u043d\u044f %.1f \u0441\u0435\u043a", effectivePercent, visibility, intensityPercent, silentSeconds); player.m_5661_((Component)Component.m_237113_((String)msg).m_130940_(ChatFormatting.WHITE), false); } return true; } @SubscribeEvent public static void onClientTick(TickEvent.ClientTickEvent event) { if (event.phase != TickEvent.Phase.END) { return; } if (phase == Phase.NONE) { return; } Minecraft mc = Minecraft.m_91087_(); if (mc == null || mc.f_91066_ == null) { DeafnessConcussionEffect.resetVolume(); return; } if (mc.m_91104_()) { return; } double t = Math.min(1.0, (double)(++ticksInPhase) / (double)phaseTicksTotal); switch (phase) { case DELAY: { if (ticksInPhase < phaseTicksTotal) break; DeafnessConcussionEffect.nextPhase(Phase.FADE_IN, FADE_TO_SILENT_TICKS); break; } case FADE_IN: { double minGain = baseMasterVolume * (1.0 - (double)currentIntensity); double gain = DeafnessConcussionEffect.lerp(baseMasterVolume, minGain, DeafnessConcussionEffect.easeOutQuad(t)); DeafnessConcussionEffect.applyMasterVolume(mc, gain); if (ticksInPhase < phaseTicksTotal) break; DeafnessConcussionEffect.nextPhase(Phase.SILENT, silentTicks); break; } case SILENT: { double minGain = baseMasterVolume * (1.0 - (double)currentIntensity); DeafnessConcussionEffect.applyMasterVolume(mc, minGain); if (ticksInPhase < phaseTicksTotal) break; DeafnessConcussionEffect.nextPhase(Phase.FADE_OUT, FADE_FROM_SILENT_TICKS); break; } case FADE_OUT: { double minGain = baseMasterVolume * (1.0 - (double)currentIntensity); double gain = DeafnessConcussionEffect.lerp(minGain, baseMasterVolume, DeafnessConcussionEffect.easeInOutQuad(t)); DeafnessConcussionEffect.applyMasterVolume(mc, gain); if (ticksInPhase < phaseTicksTotal) break; DeafnessConcussionEffect.stop(); break; } } } private static void nextPhase(Phase next, int durationTicks) { phase = next; ticksInPhase = 0; phaseTicksTotal = durationTicks; } public static void stop() { DeafnessConcussionEffect.resetVolume(); phase = Phase.NONE; ticksInPhase = 0; phaseTicksTotal = 0; lastIntensity = 0.0f; } public static boolean isActive() { return phase != Phase.NONE; } private static void resetVolume() { LowPassConcussionEffect.setDeafnessGain(1.0f); } private static void applyMasterVolume(Minecraft mc, double volume) { float clamped = (float)Math.max(0.0, Math.min(1.0, volume)); LowPassConcussionEffect.setDeafnessGain(clamped); } private static double lerp(double a, double b, double t) { return a + (b - a) * t; } private static double easeOutQuad(double t) { return 1.0 - (1.0 - t) * (1.0 - t); } private static double easeInOutQuad(double t) { return t < 0.5 ? 2.0 * t * t : 1.0 - Math.pow(-2.0 * t + 2.0, 2.0) / 2.0; } private static enum Phase { NONE, DELAY, FADE_IN, SILENT, FADE_OUT; } }