diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/GTNHLibConfig.java b/src/main/java/com/gtnewhorizon/gtnhlib/GTNHLibConfig.java index bb9fee53..2e032e92 100644 --- a/src/main/java/com/gtnewhorizon/gtnhlib/GTNHLibConfig.java +++ b/src/main/java/com/gtnewhorizon/gtnhlib/GTNHLibConfig.java @@ -86,11 +86,26 @@ public class GTNHLibConfig { @Config.RangeInt(min = -100, max = 100) public static int titleIconOffsetY; - @Config.Comment("Icon animation style during fade-in: none, fly_in, spin") + @Config.Comment("Icon animation style: none, fly_in, rise, slide, zoom, pop, spin, spin_reverse, bounce, wobble, swing, slam, tada") @Config.DefaultString("fly_in") public static String titleIconAnimation; @Config.Comment("Enable particle effects with title displays") @Config.DefaultBoolean(true) public static boolean enableTitleParticles; + + @Config.Comment("Cinematic completion effect tier: 0 = none, 3 = hyperspace, 4 = singularity, 5 = warp, 6 = lightspeed") + @Config.DefaultInt(0) + @Config.RangeInt(min = 0, max = 6) + public static int titleEffectTier; + + @Config.Comment("Horizontal offset of the title block from screen center, in pixels. Negative = left, positive = right.") + @Config.DefaultInt(0) + @Config.RangeInt(min = -1000, max = 1000) + public static int titleOffsetX; + + @Config.Comment("Vertical offset of the title block from screen center, in pixels. Negative = higher, positive = lower.") + @Config.DefaultInt(0) + @Config.RangeInt(min = -1000, max = 1000) + public static int titleOffsetY; } diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/client/title/TitleAPI.java b/src/main/java/com/gtnewhorizon/gtnhlib/client/title/TitleAPI.java index 6040ef33..9c604ac4 100644 --- a/src/main/java/com/gtnewhorizon/gtnhlib/client/title/TitleAPI.java +++ b/src/main/java/com/gtnewhorizon/gtnhlib/client/title/TitleAPI.java @@ -25,6 +25,16 @@ public class TitleAPI { public static final int ICON_ANIM_NONE = 0; public static final int ICON_ANIM_FLY_IN = 1; public static final int ICON_ANIM_SPIN = 2; + public static final int ICON_ANIM_RISE = 3; + public static final int ICON_ANIM_SLIDE = 4; + public static final int ICON_ANIM_ZOOM = 5; + public static final int ICON_ANIM_POP = 6; + public static final int ICON_ANIM_BOUNCE = 7; + public static final int ICON_ANIM_WOBBLE = 8; + public static final int ICON_ANIM_SWING = 9; + public static final int ICON_ANIM_SLAM = 10; + public static final int ICON_ANIM_TADA = 11; + public static final int ICON_ANIM_SPIN_REVERSE = 12; private static final TitleAPI INSTANCE = new TitleAPI(); @@ -53,8 +63,14 @@ public class TitleAPI { @Getter private static int iconAnimation = ICON_ANIM_DEFAULT; @Getter + private static int titleOffsetX = Integer.MIN_VALUE; + @Getter + private static int titleOffsetY = Integer.MIN_VALUE; + @Getter private static int particleEffect; @Getter + private static int effectTier; + @Getter private static ItemStack confettiIcon; @Getter private static int particleCount = -1; @@ -100,11 +116,22 @@ public class TitleAPI { iconAnimation = animation; } + /** Offset the whole title block from screen center, in pixels. {@code Integer.MIN_VALUE} = use client config. */ + public static void setTitlePosition(int x, int y) { + titleOffsetX = x; + titleOffsetY = y; + } + /** Set particle effect. Use {@code TitleParticleSystem.PARTICLE_*} constants. */ public static void setParticleEffect(int effect) { particleEffect = effect; } + /** Set the cinematic effect tier (0 = none .. 5 = warp). Use {@code TitleEffectSystem.EFFECT_*} constants. */ + public static void setEffectTier(int t) { + effectTier = t; + } + /** Set the item used for item confetti particles. Null = use main title icon. */ public static void setConfettiIcon(ItemStack stack) { confettiIcon = stack; @@ -141,11 +168,15 @@ public class TitleAPI { titleScale = 0; subtitleScale = 0; iconAnimation = ICON_ANIM_DEFAULT; + titleOffsetX = Integer.MIN_VALUE; + titleOffsetY = Integer.MIN_VALUE; particleEffect = 0; + effectTier = 0; confettiIcon = null; particleCount = -1; titleTime = 0; TitleParticleSystem.clear(); + TitleEffectSystem.clear(); FMLCommonHandler.instance().bus().unregister(INSTANCE); MinecraftForge.EVENT_BUS.unregister(INSTANCE); } diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/client/title/TitleEffectSystem.java b/src/main/java/com/gtnewhorizon/gtnhlib/client/title/TitleEffectSystem.java new file mode 100644 index 00000000..d8eba07f --- /dev/null +++ b/src/main/java/com/gtnewhorizon/gtnhlib/client/title/TitleEffectSystem.java @@ -0,0 +1,393 @@ +package com.gtnewhorizon.gtnhlib.client.title; + +import java.util.Random; + +import net.minecraft.client.renderer.Tessellator; + +import org.lwjgl.opengl.GL11; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +/** + * Screen-space cinematic "completion" effects in 5 escalating tiers, drawn with 2D Tessellator primitives only (no + * GLSL, so it never fights Iris/shaderpacks). Driven by seconds-since-shown so each tier plays a short timeline. All + * alpha is multiplied by the title's fade and flashes are capped, with a shape cue paired to every colour for + * accessibility. + */ +@SideOnly(Side.CLIENT) +public class TitleEffectSystem { + + public static final int EFFECT_NONE = 0; + // 1 and 2 (spark, burst) were removed; numbers kept so 3-6 stay stable + public static final int EFFECT_HYPERSPACE = 3; + public static final int EFFECT_SINGULARITY = 4; + public static final int EFFECT_WARP = 5; + public static final int EFFECT_LIGHTSPEED = 6; + + private static final Random rand = new Random(); + private static final int N = 220; + private static final float[] angle = new float[N]; + private static final float[] seed = new float[N]; + + private static int tier = 0; + private static float cx, cy, sw, sh, maxR; + private static boolean spawned = false; + + // Per-frame feedback the renderer applies to the whole title block, so text + icon shake/punch with the effect. + private static float shakeX = 0F, shakeY = 0F, scalePulse = 1F; + + public static float getShakeX() { + return shakeX; + } + + public static float getShakeY() { + return shakeY; + } + + public static float getScalePulse() { + return scalePulse; + } + + public static void spawn(int effectTier, float centerX, float centerY, int screenW, int screenH) { + tier = effectTier; + cx = centerX; + cy = centerY; + sw = screenW; + sh = screenH; + maxR = (float) Math.sqrt((double) screenW * screenW + (double) screenH * screenH) * 0.5F; + spawned = tier > 0; + if (!spawned) return; + for (int i = 0; i < N; i++) { + angle[i] = (float) (rand.nextFloat() * Math.PI * 2.0); + seed[i] = rand.nextFloat(); + } + } + + public static void clear() { + tier = 0; + spawned = false; + } + + /** + * Driven by the notification lifecycle so the effect builds during fade-in, sustains through the stay, and climaxes + * on fade-out. + * + * @param t01 progress over the whole notification, 0 at appear -> 1 at gone. + * @param fInEnd fraction of the lifetime where fade-in ends. + * @param fOutStart fraction where fade-out begins. + * @param ga the title's current fade alpha, 0..1. + */ + public static void render(float t01, float fInEnd, float fOutStart, float ga) { + shakeX = 0F; + shakeY = 0F; + scalePulse = 1F; + if (!spawned || tier <= 0 || ga <= 0F) return; + + float build = ramp(t01, 0F, fInEnd); + float sustain = clamp01((t01 - fInEnd) / Math.max(0.0001F, fOutStart - fInEnd)); + float climax = ramp(t01, fOutStart, 1F); + + // the "jump": shake + scale-punch right as the title starts leaving, for the heavy tiers + float jump = 0F; + float shakeAmp = 18F, pulseAmp = 0.18F; + if (tier == EFFECT_WARP) { + jump = bell(climax, 0.18F, 0.18F); + } else if (tier == EFFECT_SINGULARITY) { + jump = bell(climax, 0.12F, 0.12F); + } else if (tier == EFFECT_LIGHTSPEED) { + // the "punch it" lunge happens at the snap, right as the title settles in + jump = bell(sustain, 0.06F, 0.12F); + shakeAmp = 9F; + pulseAmp = 0.3F; + } + if (jump > 0F) { + shakeX = (rand.nextFloat() - 0.5F) * shakeAmp * jump; + shakeY = (rand.nextFloat() - 0.5F) * shakeAmp * jump; + scalePulse = 1F + pulseAmp * jump; + } + + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glDisable(GL11.GL_ALPHA_TEST); + GL11.glDepthMask(false); + GL11.glEnable(GL11.GL_BLEND); + GL11.glPushMatrix(); + GL11.glTranslatef(shakeX, shakeY, 0F); + + switch (tier) { + case EFFECT_HYPERSPACE -> renderHyperspace(t01, build, sustain, climax, ga); + case EFFECT_SINGULARITY -> renderSingularity(t01, build, sustain, climax, ga); + case EFFECT_WARP -> renderWarp(t01, build, sustain, climax, ga); + case EFFECT_LIGHTSPEED -> renderLightspeed(t01, build, sustain, climax, ga); + default -> {} + } + + GL11.glPopMatrix(); + GL11.glDepthMask(true); + GL11.glEnable(GL11.GL_ALPHA_TEST); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glColor4f(1F, 1F, 1F, 1F); + } + + // ---- tiers ---- + + private static void renderHyperspace(float t01, float build, float sustain, float climax, float ga) { + float on = Math.min(1F, build * 2F + sustain) * (1F - climax); + normalBlend(); + drawQuad(0, 0, sw, sh, 0.01F, 0.03F, 0.12F, 0.4F * Math.min(1F, build + sustain) * (1F - climax * 0.6F) * ga); + + additive(); + beginQuads(); + float swirl = t01 * 1.2F; + for (int i = 0; i < 160; i++) { + float speed = 0.6F + 1.2F * seed[i]; + float phase = (t01 * speed + seed[i]) % 1F; + float ang = angle[i] + swirl + phase * 0.5F; + float rIn = phase * maxR * 1.2F; + float rOut = rIn + lerp(80F, 360F, phase); + // bright across most of the streak; only the very ends taper + float vis = clamp01(phase * 6F) * clamp01((1F - phase) * 4F); + float al = vis * on * ga; + if (al <= 0F) continue; + streakAt(cx, cy, ang, rIn, rOut, 3.5F, 0.7F, 0.85F, 1F, 0F, al); + } + end(); + + // collapse flash as it releases + float flash = bell(climax, 0.2F, 0.2F) * 0.35F * ga; + if (flash > 0F) { + additive(); + drawGlow(cx, cy, maxR, 0.6F, 0.8F, 1F, flash); + } + } + + private static void renderSingularity(float t01, float build, float sustain, float climax, float ga) { + normalBlend(); + drawQuad(0, 0, sw, sh, 0.02F, 0F, 0.04F, 0.6F * Math.min(1F, build + sustain) * (1F - climax * 0.5F) * ga); + + // accretion: matter spirals INWARD through build + sustain + float spin = t01 * 2F; + float on = Math.min(1F, build * 2F + sustain) * (1F - climax); + additive(); + beginQuads(); + for (int i = 0; i < 130; i++) { + float speed = 0.4F + 0.8F * seed[i]; + float phase = 1F - ((t01 * speed + seed[i]) % 1F); // 1 at rim -> 0 at core + float rOut = phase * maxR; + float rIn = Math.min(maxR, rOut + lerp(40F, 120F, 1F - phase)); + float al = (1F - phase) * (1F - phase) * 0.85F * on * ga; + if (al <= 0F) continue; + streakAt(cx, cy, angle[i] + spin, rIn, rOut, 3F, 0.6F, 0.35F, 1F, 0F, al); + } + end(); + additive(); + drawGlow(cx, cy, lerp(40F, 120F, sustain), 1F, 0.6F, 1F, 0.3F * on * ga); + + // implosion flash + outward blast on the climax + float flash = bell(climax, 0.15F, 0.15F) * 0.42F * ga; + if (flash > 0F) { + additive(); + drawGlow(cx, cy, maxR * 0.9F, 1F, 0.75F, 1F, flash); + } + float blast = ramp(climax, 0.15F, 0.7F); + if (blast > 0F && blast < 1F) { + additive(); + beginQuads(); + for (int i = 0; i < 140; i++) { + float rIn = blast * maxR * (0.4F + 0.6F * seed[i]); + float rOut = rIn + lerp(40F, 120F, blast); + float al = (1F - blast) * 0.9F * ga; + if (al <= 0F) continue; + streakAt(cx, cy, angle[i], rIn, rOut, 3F, 0.75F, 0.3F, 1F, 0F, al); + } + end(); + float rr = lerp(20F, maxR, blast); + drawRing(cx - 8F, cy, rr, 3F, 1F, 0.2F, 0.2F, (1F - blast) * 0.6F * ga); + drawRing(cx + 8F, cy, rr, 3F, 0.3F, 0.5F, 1F, (1F - blast) * 0.6F * ga); + } + } + + private static void renderWarp(float t01, float build, float sustain, float climax, float ga) { + // darken to deep space so the stretching stars blaze + normalBlend(); + drawQuad( + 0, + 0, + sw, + sh, + 0.01F, + 0.02F, + 0.08F, + 0.62F * Math.min(1F, build * 1.5F + sustain) * (1F - climax * 0.4F) * ga); + + additive(); + beginQuads(); + for (int i = 0; i < 200; i++) { + float speed = 0.5F + 1.0F * seed[i]; + float phase = (t01 * speed * (1F + climax * 2F) + seed[i]) % 1F; + float r = phase * maxR * 1.4F; + // points (charge) -> long streaks (warp) -> longest (the jump) + float lenFactor = 0.15F + 0.85F * build + climax * 1.2F; + float rIn = Math.max(0F, r - lerp(8F, 360F, phase) * lenFactor); + float bright = (0.6F + 0.4F * seed[i]) * Math.min(1F, build * 2.5F) * ga; + if (bright <= 0F) continue; + streakAt(cx, cy, angle[i], rIn, r, lerp(2.5F, 4.5F, phase), 0.8F, 0.9F, 1F, 0.1F * bright, bright); + } + end(); + + // the jump: bright flash + shockwave (shake + scale-punch are applied in render()) + float flash = bell(climax, 0.18F, 0.18F) * 0.45F * ga; + if (flash > 0F) { + additive(); + drawQuad(0, 0, sw, sh, 0.85F, 0.92F, 1F, flash); + } + float ringP = ramp(climax, 0.05F, 0.5F); + if (ringP > 0F && ringP < 1F) { + additive(); + drawRing(cx, cy, lerp(20F, maxR * 1.2F, ringP), 5F, 0.8F, 0.9F, 1F, (1F - ringP) * 0.8F * ga); + } + additive(); + drawGlow(cx, cy, maxR * 0.9F, 0.2F, 0.45F, 1F, 0.12F * sustain * (1F - climax) * ga); + } + + private static void renderLightspeed(float t01, float build, float sustain, float climax, float ga) { + // deep space backdrop + normalBlend(); + drawQuad( + 0, + 0, + sw, + sh, + 0F, + 0.01F, + 0.05F, + 0.66F * Math.min(1F, build * 1.5F + sustain) * (1F - climax * 0.4F) * ga); + + // stars sit as points during the charge, then SNAP into long streaks the instant it settles + float snap = clamp01(sustain / 0.12F); + float lenFactor = 0.04F + 0.96F * snap + climax * 0.8F; + additive(); + beginQuads(); + for (int i = 0; i < 220; i++) { + float speed = 0.6F + 1.0F * seed[i]; + float phase = (t01 * speed * (1F + snap + climax * 1.5F) + seed[i]) % 1F; + float r = phase * maxR * 1.5F; + float rIn = Math.max(0F, r - lerp(6F, 440F, phase) * lenFactor); + float bright = (0.7F + 0.3F * seed[i]) * Math.min(1F, build * 2F + 0.25F) * (1F - climax * 0.3F) * ga; + if (bright <= 0F) continue; + streakAt(cx, cy, angle[i], rIn, r, lerp(1.8F, 4F, phase), 0.95F, 0.97F, 1F, 0.12F * bright, bright); + } + end(); + + // the white snap-flash at the punch + float flash = bell(sustain, 0.05F, 0.1F) * 0.5F * ga; + if (flash > 0F) { + additive(); + drawQuad(0, 0, sw, sh, 1F, 1F, 1F, flash); + } + } + + // ---- primitives ---- + + private static void additive() { + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE); + } + + private static void normalBlend() { + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + } + + private static void beginQuads() { + Tessellator t = Tessellator.instance; + t.startDrawingQuads(); + } + + private static void end() { + Tessellator.instance.draw(); + } + + /** Radial streak quad with a per-end alpha gradient. Call between beginQuads()/end(). */ + private static void streakAt(float ox, float oy, float ang, float rIn, float rOut, float hw, float r, float g, + float b, float aIn, float aOut) { + Tessellator t = Tessellator.instance; + float dx = (float) Math.cos(ang), dy = (float) Math.sin(ang); + float px = -dy, py = dx; + float ix = ox + dx * rIn, iy = oy + dy * rIn; + float oxx = ox + dx * rOut, oyy = oy + dy * rOut; + t.setColorRGBA_F(r, g, b, aIn); + t.addVertex(ix + px * hw, iy + py * hw, 0); + t.addVertex(ix - px * hw, iy - py * hw, 0); + t.setColorRGBA_F(r, g, b, aOut); + t.addVertex(oxx - px * hw, oyy - py * hw, 0); + t.addVertex(oxx + px * hw, oyy + py * hw, 0); + } + + private static void drawQuad(float x1, float y1, float x2, float y2, float r, float g, float b, float a) { + if (a <= 0F) return; + Tessellator t = Tessellator.instance; + t.startDrawingQuads(); + t.setColorRGBA_F(r, g, b, a); + t.addVertex(x1, y2, 0); + t.addVertex(x2, y2, 0); + t.addVertex(x2, y1, 0); + t.addVertex(x1, y1, 0); + t.draw(); + } + + private static void drawRing(float ox, float oy, float radius, float thickness, float r, float g, float b, + float a) { + if (a <= 0F || radius <= 0F) return; + Tessellator t = Tessellator.instance; + t.startDrawingQuads(); + t.setColorRGBA_F(r, g, b, a); + int segs = 48; + float inner = radius - thickness; + for (int i = 0; i < segs; i++) { + float a0 = (float) (i * Math.PI * 2.0 / segs); + float a1 = (float) ((i + 1) * Math.PI * 2.0 / segs); + float c0 = (float) Math.cos(a0), s0 = (float) Math.sin(a0); + float c1 = (float) Math.cos(a1), s1 = (float) Math.sin(a1); + t.addVertex(ox + c0 * inner, oy + s0 * inner, 0); + t.addVertex(ox + c0 * radius, oy + s0 * radius, 0); + t.addVertex(ox + c1 * radius, oy + s1 * radius, 0); + t.addVertex(ox + c1 * inner, oy + s1 * inner, 0); + } + t.draw(); + } + + private static void drawGlow(float ox, float oy, float radius, float r, float g, float b, float aCenter) { + if (aCenter <= 0F || radius <= 0F) return; + Tessellator t = Tessellator.instance; + t.startDrawing(GL11.GL_TRIANGLE_FAN); + t.setColorRGBA_F(r, g, b, aCenter); + t.addVertex(ox, oy, 0); + t.setColorRGBA_F(r, g, b, 0F); + int segs = 32; + for (int i = 0; i <= segs; i++) { + float a = (float) (i * Math.PI * 2.0 / segs); + t.addVertex(ox + (float) Math.cos(a) * radius, oy + (float) Math.sin(a) * radius, 0); + } + t.draw(); + } + + // ---- timeline helpers ---- + + private static float clamp01(float x) { + return x < 0F ? 0F : (x > 1F ? 1F : x); + } + + private static float ramp(float t, float t0, float t1) { + return clamp01((t - t0) / (t1 - t0)); + } + + private static float lerp(float a, float b, float t) { + return a + (b - a) * t; + } + + /** Triangular pulse peaking at {@code center} with half-width {@code half}; 0 outside. */ + private static float bell(float t, float center, float half) { + float d = Math.abs(t - center) / half; + return d >= 1F ? 0F : 1F - d; + } +} diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/client/title/TitleRenderer.java b/src/main/java/com/gtnewhorizon/gtnhlib/client/title/TitleRenderer.java index 07c30edd..4041f681 100644 --- a/src/main/java/com/gtnewhorizon/gtnhlib/client/title/TitleRenderer.java +++ b/src/main/java/com/gtnewhorizon/gtnhlib/client/title/TitleRenderer.java @@ -51,10 +51,15 @@ public class TitleRenderer { return; } - float fadeInProgress = -1.0F; - if (fadeIn > 0 && titleTime > fadeOut + stay) { - float elapsed = (float) total - f; - fadeInProgress = MathHelper.clamp_float(elapsed / (float) fadeIn, 0.0F, 1.0F); + // Animation progress: 0 = fully entering, 1 = settled. During fade-out it runs 1 -> 0 so the + // exit replays the entrance in reverse (spin in clockwise -> spin out counter-clockwise, etc.). + float animQ; + if (titleTime > fadeOut + stay) { + animQ = fadeIn > 0 ? MathHelper.clamp_float(((float) total - f) / (float) fadeIn, 0.0F, 1.0F) : 1.0F; + } else if (titleTime <= fadeOut) { + animQ = fadeOut > 0 ? MathHelper.clamp_float(f / (float) fadeOut, 0.0F, 1.0F) : 1.0F; + } else { + animQ = 1.0F; } int color = 0xFFFFFF | (alpha << 24); @@ -63,24 +68,44 @@ public class TitleRenderer { float apiSubtitleScale = TitleAPI.getSubtitleScale(); float sScale = apiSubtitleScale > 0 ? apiSubtitleScale : GTNHLibConfig.subtitleScale; + int apiOffX = TitleAPI.getTitleOffsetX(); + int apiOffY = TitleAPI.getTitleOffsetY(); + int originX = width / 2 + (apiOffX != Integer.MIN_VALUE ? apiOffX : GTNHLibConfig.titleOffsetX); + int originY = height / 2 + (apiOffY != Integer.MIN_VALUE ? apiOffY : GTNHLibConfig.titleOffsetY); + + int apiTier = TitleAPI.getEffectTier(); + int effectTier = apiTier > 0 ? apiTier : GTNHLibConfig.titleEffectTier; + if (title != lastTitle) { lastTitle = title; int pe = TitleAPI.getParticleEffect(); if (pe != TitleParticleSystem.PARTICLE_NONE) { - TitleParticleSystem.spawn(pe, width / 2, height / 2, TitleAPI.getIcon()); + TitleParticleSystem.spawn(pe, originX, originY, TitleAPI.getIcon()); } + TitleEffectSystem.spawn(effectTier, originX, originY, width, height); } TitleParticleSystem.render(partialTicks); + float t01 = total > 0 ? MathHelper.clamp_float((total - f) / (float) total, 0.0F, 1.0F) : 1.0F; + float fInEnd = total > 0 ? (float) fadeIn / (float) total : 0.0F; + float fOutStart = total > 0 ? (float) (fadeIn + stay) / (float) total : 1.0F; + TitleEffectSystem.render(t01, fInEnd, fOutStart, alpha / 255.0F); + + // the effect can shake + scale-punch the whole title block on a "jump" + float shakeX = TitleEffectSystem.getShakeX(); + float shakeY = TitleEffectSystem.getShakeY(); + float pulse = TitleEffectSystem.getScalePulse(); + tScale *= pulse; + sScale *= pulse; GL11.glPushMatrix(); - GL11.glTranslatef((float) (width / 2), (float) (height / 2), 0.0F); + GL11.glTranslatef((float) originX + shakeX, (float) originY + shakeY, 0.0F); GL11.glEnable(GL11.GL_BLEND); ItemStack icon = TitleAPI.getIcon(); if (icon != null && GTNHLibConfig.showTitleIcon) { - renderIcon(mc, icon, tScale, alpha, fadeInProgress); + renderIcon(mc, icon, tScale, alpha, animQ); } GL11.glEnable(GL11.GL_DEPTH_TEST); @@ -113,11 +138,21 @@ public class TitleRenderer { return switch (GTNHLibConfig.titleIconAnimation) { case "fly_in" -> TitleAPI.ICON_ANIM_FLY_IN; case "spin" -> TitleAPI.ICON_ANIM_SPIN; + case "spin_reverse" -> TitleAPI.ICON_ANIM_SPIN_REVERSE; + case "rise" -> TitleAPI.ICON_ANIM_RISE; + case "slide" -> TitleAPI.ICON_ANIM_SLIDE; + case "zoom" -> TitleAPI.ICON_ANIM_ZOOM; + case "pop" -> TitleAPI.ICON_ANIM_POP; + case "bounce" -> TitleAPI.ICON_ANIM_BOUNCE; + case "wobble" -> TitleAPI.ICON_ANIM_WOBBLE; + case "swing" -> TitleAPI.ICON_ANIM_SWING; + case "slam" -> TitleAPI.ICON_ANIM_SLAM; + case "tada" -> TitleAPI.ICON_ANIM_TADA; default -> TitleAPI.ICON_ANIM_NONE; }; } - private static void renderIcon(Minecraft mc, ItemStack icon, float titleScale, int alpha, float fadeInProgress) { + private static void renderIcon(Minecraft mc, ItemStack icon, float titleScale, int alpha, float animQ) { GL11.glPushMatrix(); float iconSize = 16.0F; @@ -131,27 +166,41 @@ public class TitleRenderer { float iconCenterX = 0.0F; float iconCenterY = iconY + scaledIconSize / 2.0F; + // q = 1 is the settled icon (identity); each style deforms toward q = 0. Entrance runs q 0->1, + // exit runs q 1->0, so the exit is the entrance in reverse. int animStyle = resolveAnimation(TitleAPI.getIconAnimation()); - boolean animating = animStyle != TitleAPI.ICON_ANIM_NONE && fadeInProgress >= 0.0F && fadeInProgress < 1.0F; - float animScale = 1.0F; - - if (animating) { - float eased = 1.0F - (1.0F - fadeInProgress) * (1.0F - fadeInProgress); - - if (animStyle == TitleAPI.ICON_ANIM_FLY_IN) { - float flyDistance = 40.0F * iconRenderScale; - float flyOffset = -flyDistance * (1.0F - eased); - GL11.glTranslatef(iconCenterX, iconCenterY + flyOffset, 0.0F); - } else if (animStyle == TitleAPI.ICON_ANIM_SPIN) { - GL11.glTranslatef(iconCenterX, iconCenterY, 0.0F); - animScale = 1.0F + 2.0F * (1.0F - eased); - GL11.glRotatef(720.0F * eased, 0.0F, 0.0F, 1.0F); + float dist = 40.0F * iconRenderScale; + float e = easeOut(animQ); + float dx = 0.0F, dy = 0.0F, rot = 0.0F, scaleMul = 1.0F; + switch (animStyle) { + case TitleAPI.ICON_ANIM_FLY_IN -> dy = -dist * (1.0F - e); + case TitleAPI.ICON_ANIM_RISE -> dy = dist * (1.0F - e); + case TitleAPI.ICON_ANIM_SLIDE -> dx = -dist * (1.0F - e); + case TitleAPI.ICON_ANIM_ZOOM -> scaleMul = Math.max(0.0F, e); + case TitleAPI.ICON_ANIM_POP -> scaleMul = Math.max(0.0F, easeOutBack(animQ)); + case TitleAPI.ICON_ANIM_SPIN -> { + rot = 720.0F * e; + scaleMul = 1.0F + 2.0F * (1.0F - e); } - } else { - GL11.glTranslatef(iconCenterX, iconCenterY, 0.0F); + case TitleAPI.ICON_ANIM_SPIN_REVERSE -> { + rot = -720.0F * e; + scaleMul = 1.0F + 2.0F * (1.0F - e); + } + case TitleAPI.ICON_ANIM_BOUNCE -> dy = -dist * 1.25F * (1.0F - easeOutBounce(animQ)); + case TitleAPI.ICON_ANIM_WOBBLE -> scaleMul = Math.max(0.0F, easeOutElastic(animQ)); + case TitleAPI.ICON_ANIM_SWING -> rot = -80.0F * (1.0F - easeOutBack(animQ)); + case TitleAPI.ICON_ANIM_SLAM -> scaleMul = 1.0F + 3.0F * (1.0F - animQ) * (1.0F - animQ); + case TitleAPI.ICON_ANIM_TADA -> { + scaleMul = Math.max(0.0F, easeOutBack(animQ)); + rot = 12.0F * (float) Math.sin(animQ * Math.PI * 5.0) * (1.0F - animQ); + } + default -> {} } - float finalScale = iconRenderScale * animScale; + GL11.glTranslatef(iconCenterX + dx, iconCenterY + dy, 0.0F); + if (rot != 0.0F) GL11.glRotatef(rot, 0.0F, 0.0F, 1.0F); + + float finalScale = iconRenderScale * scaleMul; GL11.glTranslatef(-iconSize / 2.0F * finalScale, -iconSize / 2.0F * finalScale, 0.0F); GL11.glScalef(finalScale, finalScale, 1.0F); @@ -162,6 +211,13 @@ public class TitleRenderer { GL11.glEnable(GL12.GL_RESCALE_NORMAL); GL11.glEnable(GL11.GL_DEPTH_TEST); + // renderItemIntoGUI overwrites glColor alpha with 1 when renderWithColor is on; turn it off so + // the fade alpha survives. It already blends SRC_ALPHA/ONE_MINUS_SRC_ALPHA. + boolean prevRenderWithColor = itemRender.renderWithColor; + itemRender.renderWithColor = false; + // alpha func 0.1 clips the icon before the fade reaches 0 + GL11.glAlphaFunc(GL11.GL_GREATER, 0.0F); + float preZ = itemRender.zLevel; itemRender.zLevel = -50F; @@ -174,9 +230,47 @@ public class TitleRenderer { itemRender.zLevel = preZ; + itemRender.renderWithColor = prevRenderWithColor; + GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F); + RenderHelper.disableStandardItemLighting(); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glPopMatrix(); } + + private static float easeOut(float t) { + return 1.0F - (1.0F - t) * (1.0F - t); + } + + private static float easeOutBack(float t) { + float c1 = 1.70158F; + float c3 = c1 + 1.0F; + float u = t - 1.0F; + return 1.0F + c3 * u * u * u + c1 * u * u; + } + + private static float easeOutBounce(float t) { + float n1 = 7.5625F; + float d1 = 2.75F; + if (t < 1.0F / d1) { + return n1 * t * t; + } else if (t < 2.0F / d1) { + t -= 1.5F / d1; + return n1 * t * t + 0.75F; + } else if (t < 2.5F / d1) { + t -= 2.25F / d1; + return n1 * t * t + 0.9375F; + } else { + t -= 2.625F / d1; + return n1 * t * t + 0.984375F; + } + } + + private static float easeOutElastic(float t) { + if (t <= 0.0F) return 0.0F; + if (t >= 1.0F) return 1.0F; + float c4 = (float) (2.0 * Math.PI) / 3.0F; + return (float) (Math.pow(2.0, -10.0 * t) * Math.sin((t * 10.0 - 0.75) * c4) + 1.0); + } }