Files
fabric-client
src
build.gradle
ExpSafe-1.1.1.jar
settings.gradle
Code
18 1,687
fabric-client/src/main/java/com/kodari/guardianfox/client/GuardianFoxClient.java
package com.kodari.guardianfox.client;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.RenderTickCounter;
public final class GuardianFoxClient implements ClientModInitializer {
private static final int IDLE = -1;
private static final int DEATH = 0;
private static final int HEAVEN = 1;
private static final int REVIVAL = 2;
private static final int WHITEOUT = 3;
private static final int EYES_CLOSED = 4;
private static final long REVIVAL_SPIN_MILLIS = 5_000L;
private static int mode = IDLE;
private static long animationStartedAt;
private static long cameraSpinStartedAt;
private static float cameraSpinInitialYaw;
private static float initialPitch;
@Override
public void onInitializeClient() {
PayloadTypeRegistry.playS2C().register(RevivalVisualPayload.ID, RevivalVisualPayload.CODEC);
ClientPlayNetworking.registerGlobalReceiver(RevivalVisualPayload.ID, (payload, context) ->
context.client().execute(() -> startAnimation(payload.state())));
ClientTickEvents.END_CLIENT_TICK.register(GuardianFoxClient::tick);
HudRenderCallback.EVENT.register(GuardianFoxClient::renderOverlay);
}
private static void startAnimation(byte state) {
MinecraftClient client = MinecraftClient.getInstance();
mode = state;
animationStartedAt = System.currentTimeMillis();
if (client.player != null) {
if (state == REVIVAL) {
cameraSpinStartedAt = animationStartedAt;
cameraSpinInitialYaw = client.player.getYaw();
} else if (state == DEATH) {
cameraSpinStartedAt = 0L;
initialPitch = client.player.getPitch();
} else if (state == HEAVEN) {
cameraSpinStartedAt = 0L;
}
}
}
private static void tick(MinecraftClient client) {
if (client.player == null) {
return;
}
long elapsed = System.currentTimeMillis() - animationStartedAt;
if (cameraSpinStartedAt > 0L) {
long spinElapsed = System.currentTimeMillis() - cameraSpinStartedAt;
if (spinElapsed >= REVIVAL_SPIN_MILLIS) {
cameraSpinStartedAt = 0L;
} else {
float progress = spinElapsed / (float) REVIVAL_SPIN_MILLIS;
client.player.setYaw(cameraSpinInitialYaw + 360.0f * progress);
}
}
if (mode == DEATH) {
float progress = clamp(elapsed / 850.0f);
client.player.setPitch(initialPitch + (82.0f - initialPitch) * progress);
if (elapsed >= 1_400L) {
mode = EYES_CLOSED;
}
} else if (mode == REVIVAL) {
if (elapsed >= REVIVAL_SPIN_MILLIS) {
mode = IDLE;
}
} else if (mode == HEAVEN && elapsed >= 1_500L) {
mode = IDLE;
} else if (mode == WHITEOUT && elapsed >= 1_800L) {
mode = IDLE;
}
}
private static void renderOverlay(DrawContext context, RenderTickCounter tickCounter) {
if (mode == IDLE) {
return;
}
MinecraftClient client = MinecraftClient.getInstance();
int width = client.getWindow().getScaledWidth();
int height = client.getWindow().getScaledHeight();
long elapsed = System.currentTimeMillis() - animationStartedAt;
if (mode == DEATH) {
drawLids(context, width, height, clamp(elapsed / 850.0f));
} else if (mode == EYES_CLOSED) {
context.fill(0, 0, width, height, 0xFF080611);
drawOrbit(context, width, height, elapsed, 0xBBAF8CFF);
} else if (mode == HEAVEN) {
float opening = smoothstep(clamp((elapsed - 120L) / 1_150.0f));
drawLids(context, width, height, 1.0f - opening);
if (elapsed < 180L) {
int alpha = (int) (150 * (1.0f - elapsed / 180.0f));
context.fill(0, 0, width, height, (alpha << 24) | 0x00FFFFFF);
}
drawOrbit(context, width, height, elapsed, 0x88FFF1B8);
} else if (mode == REVIVAL) {
context.fill(0, 0, width, height, 0x25130830);
drawOrbit(context, width, height, elapsed, 0xD9E6C8FF);
} else if (mode == WHITEOUT) {
float alpha = elapsed < 220L ? elapsed / 220.0f
: elapsed < 1_100L ? 1.0f : 1.0f - (elapsed - 1_100L) / 700.0f;
int opacity = Math.max(0, Math.min(255, (int) (255 * alpha)));
context.fill(0, 0, width, height, (opacity << 24) | 0x00FFFFFF);
}
}
private static void drawLids(DrawContext context, int width, int height, float closed) {
int cover = Math.max(0, Math.min(height / 2, (int) (height * 0.5f * closed)));
context.fill(0, 0, width, cover, 0xFF080611);
context.fill(0, height - cover, width, height, 0xFF080611);
}
private static void drawOrbit(DrawContext context, int width, int height, long elapsed, int color) {
double centerX = width / 2.0;
double centerY = height / 2.0;
for (int i = 0; i < 48; i++) {
double angle = i * Math.PI * 2.0 / 48.0 + elapsed * 0.0025;
double radius = 18.0 + (i % 6) * 8.0 + Math.sin(elapsed * 0.004 + i) * 5.0;
int x = (int) (centerX + Math.cos(angle) * radius);
int y = (int) (centerY + Math.sin(angle) * radius * 0.65);
context.fill(x, y, x + 3, y + 3, color);
}
}
private static float smoothstep(float value) {
float clamped = clamp(value);
return clamped * clamped * (3.0f - 2.0f * clamped);
}
private static float clamp(float value) {
return Math.max(0.0f, Math.min(1.0f, value));
}
}