| 1 | package net.minecraft.client.gui.components;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.gui.ActiveTextCollector;
|
| 6 | import net.minecraft.client.gui.Font;
|
| 7 | import net.minecraft.client.gui.GuiGraphicsExtractor;
|
| 8 | import net.minecraft.client.gui.TextAlignment;
|
| 9 | import net.minecraft.client.resources.SplashManager;
|
| 10 | import net.minecraft.network.chat.Component;
|
| 11 | import net.minecraft.util.Mth;
|
| 12 | import net.minecraft.util.Util;
|
| 13 | import org.joml.Matrix3x2f;
|
| 14 |
|
| 15 | @Environment(EnvType.CLIENT)
|
| 16 | public class SplashRenderer {
|
| 17 | public static final SplashRenderer CHRISTMAS = new SplashRenderer(SplashManager.CHRISTMAS);
|
| 18 | public static final SplashRenderer NEW_YEAR = new SplashRenderer(SplashManager.NEW_YEAR);
|
| 19 | public static final SplashRenderer HALLOWEEN = new SplashRenderer(SplashManager.HALLOWEEN);
|
| 20 | private static final int WIDTH_OFFSET = 123;
|
| 21 | private static final int HEIGH_OFFSET = 69;
|
| 22 | private static final float TEXT_ANGLE = (float) (-Math.PI / 9);
|
| 23 | private final Component splash;
|
| 24 |
|
| 25 | public SplashRenderer(final Component splash) {
|
| 26 | this.splash = splash;
|
| 27 | }
|
| 28 |
|
| 29 | public void extractRenderState(final GuiGraphicsExtractor graphics, final int screenWidth, final Font font, final float alpha) {
|
| 30 | int textWidth = font.width(this.splash);
|
| 31 | ActiveTextCollector textRenderer = graphics.textRenderer();
|
| 32 | float textPhase = 1.8F - Mth.abs(Mth.sin((float)(Util.getMillis() % 1000L) / 1000.0F * (float) (Math.PI * 2)) * 0.1F);
|
| 33 | float textScale = textPhase * 100.0F / (textWidth + 32);
|
| 34 | Matrix3x2f transform = new Matrix3x2f(textRenderer.defaultParameters().pose())
|
| 35 | .translate(screenWidth / 2.0F + 123.0F, 69.0F)
|
| 36 | .rotate((float) (-Math.PI / 9))
|
| 37 | .scale(textScale);
|
| 38 | ActiveTextCollector.Parameters renderParameters = textRenderer.defaultParameters().withOpacity(alpha).withPose(transform);
|
| 39 | textRenderer.accept(TextAlignment.LEFT, -textWidth / 2, -8, renderParameters, this.splash);
|
| 40 | }
|
| 41 | }
|
| 42 |
|