generated from MrSphay/codex-agent-repository-kit
Decompile upstream Explosion Overhaul 0.2.3.0
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.vinlanx.explosionoverhaul.client;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(value=Dist.CLIENT)
|
||||
public class CameraShakeConcussionEffect {
|
||||
private static final int FADE_IN_TICKS = 40;
|
||||
private static final int FADE_OUT_TICKS = 40;
|
||||
private static Phase phase = Phase.IDLE;
|
||||
private static int ticksInPhase = 0;
|
||||
private static int holdTicks = 0;
|
||||
private static float currentIntensity = 0.0f;
|
||||
private static float targetIntensity = 0.0f;
|
||||
private static float lastYawOffset = 0.0f;
|
||||
private static float lastPitchOffset = 0.0f;
|
||||
|
||||
public static boolean isActive() {
|
||||
return phase != Phase.IDLE;
|
||||
}
|
||||
|
||||
public static void start(int seconds, float intensity) {
|
||||
int newHoldTicks = Mth.m_14045_((int)seconds, (int)1, (int)100) * 20;
|
||||
float newIntensity = Math.max(0.0f, intensity);
|
||||
if (phase != Phase.IDLE) {
|
||||
targetIntensity += newIntensity;
|
||||
holdTicks = Math.min(2000, holdTicks + newHoldTicks);
|
||||
if (phase == Phase.FADE_OUT) {
|
||||
phase = Phase.HOLD;
|
||||
ticksInPhase = 0;
|
||||
}
|
||||
} else {
|
||||
targetIntensity = newIntensity;
|
||||
holdTicks = newHoldTicks;
|
||||
ticksInPhase = 0;
|
||||
phase = Phase.FADE_IN;
|
||||
currentIntensity = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
public static void onClientTick() {
|
||||
Minecraft mc = Minecraft.m_91087_();
|
||||
if (mc.m_91104_()) {
|
||||
return;
|
||||
}
|
||||
LocalPlayer player = mc.f_91074_;
|
||||
if (player == null) {
|
||||
CameraShakeConcussionEffect.stop();
|
||||
return;
|
||||
}
|
||||
player.m_19884_((double)(-lastYawOffset), (double)(-lastPitchOffset));
|
||||
lastYawOffset = 0.0f;
|
||||
lastPitchOffset = 0.0f;
|
||||
if (phase == Phase.IDLE) {
|
||||
return;
|
||||
}
|
||||
++ticksInPhase;
|
||||
switch (phase) {
|
||||
case FADE_IN: {
|
||||
float t = (float)ticksInPhase / 40.0f;
|
||||
currentIntensity = CameraShakeConcussionEffect.easeInOutCubic(t) * targetIntensity;
|
||||
if (ticksInPhase < 40) break;
|
||||
phase = Phase.HOLD;
|
||||
ticksInPhase = 0;
|
||||
break;
|
||||
}
|
||||
case HOLD: {
|
||||
currentIntensity = targetIntensity;
|
||||
if (ticksInPhase < holdTicks) break;
|
||||
phase = Phase.FADE_OUT;
|
||||
ticksInPhase = 0;
|
||||
break;
|
||||
}
|
||||
case FADE_OUT: {
|
||||
float t = (float)ticksInPhase / 40.0f;
|
||||
currentIntensity = targetIntensity * CameraShakeConcussionEffect.easeInOutCubic(1.0f - t);
|
||||
if (ticksInPhase < 40) break;
|
||||
CameraShakeConcussionEffect.stop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (currentIntensity > 0.0f) {
|
||||
CameraShakeConcussionEffect.applySway(player, (float)player.f_19797_ + mc.m_91296_());
|
||||
}
|
||||
}
|
||||
|
||||
private static void applySway(LocalPlayer player, float totalTicks) {
|
||||
float horizontalSway = Mth.m_14031_((float)(totalTicks * 0.04f)) * 1.5f + Mth.m_14031_((float)(totalTicks * 0.025f)) * 1.0f;
|
||||
float verticalSway = Mth.m_14089_((float)(totalTicks * 0.035f)) * 0.8f + Mth.m_14031_((float)(totalTicks * 0.015f)) * 0.5f;
|
||||
float yawChange = horizontalSway * currentIntensity * 50.0f;
|
||||
float pitchChange = verticalSway * currentIntensity * 30.0f;
|
||||
player.m_19884_((double)yawChange, (double)pitchChange);
|
||||
lastYawOffset = yawChange;
|
||||
lastPitchOffset = pitchChange;
|
||||
}
|
||||
|
||||
public static void stop() {
|
||||
phase = Phase.IDLE;
|
||||
ticksInPhase = 0;
|
||||
holdTicks = 0;
|
||||
currentIntensity = 0.0f;
|
||||
targetIntensity = 0.0f;
|
||||
lastYawOffset = 0.0f;
|
||||
lastPitchOffset = 0.0f;
|
||||
}
|
||||
|
||||
private static float easeInOutCubic(float t) {
|
||||
return t < 0.5f ? 4.0f * t * t * t : 1.0f - (float)Math.pow(-2.0f * t + 2.0f, 3.0) / 2.0f;
|
||||
}
|
||||
|
||||
private static enum Phase {
|
||||
IDLE,
|
||||
FADE_IN,
|
||||
HOLD,
|
||||
FADE_OUT;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user