From 84042deb0d59cd70ed988724ed0e383baf68c0cf Mon Sep 17 00:00:00 2001 From: Motschen Date: Sun, 11 Jun 2023 12:40:28 +0200 Subject: [PATCH] CustomSplashScreen 2.1.1 - Port to 1.20 --- gradle.properties | 12 +-- .../mixin/MixinSplashScreen.java | 95 +++++++++---------- 2 files changed, 49 insertions(+), 58 deletions(-) diff --git a/gradle.properties b/gradle.properties index bc293c6..93e710e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use - minecraft_version=1.19.4 - yarn_mappings=1.19.4+build.2 - loader_version=0.14.19 + minecraft_version=1.20 + yarn_mappings=1.20+build.1 + loader_version=0.14.21 # Mod Properties - mod_version = 2.1.0 + mod_version = 2.1.1 maven_group = eu.midnightdust archives_base_name = customsplashscreen # Dependencies # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api - fabric_version=0.81.1+1.19.4 - midnightlib_version=1.3.0-fabric \ No newline at end of file + fabric_version=0.83.0+1.20 + midnightlib_version=1.4.1-fabric \ No newline at end of file diff --git a/src/main/java/eu/midnightdust/customsplashscreen/mixin/MixinSplashScreen.java b/src/main/java/eu/midnightdust/customsplashscreen/mixin/MixinSplashScreen.java index 74d44a7..fda5402 100644 --- a/src/main/java/eu/midnightdust/customsplashscreen/mixin/MixinSplashScreen.java +++ b/src/main/java/eu/midnightdust/customsplashscreen/mixin/MixinSplashScreen.java @@ -9,10 +9,9 @@ import eu.midnightdust.customsplashscreen.texture.EmptyTexture; import eu.midnightdust.lib.config.MidnightConfig; import eu.midnightdust.lib.util.MidnightColorUtil; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawableHelper; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.SplashOverlay; import net.minecraft.client.render.GameRenderer; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.resource.ResourceReload; import net.minecraft.util.Identifier; import net.minecraft.util.Util; @@ -32,9 +31,6 @@ import java.util.Optional; import java.util.function.Consumer; import java.util.function.IntSupplier; -import static net.minecraft.client.gui.DrawableHelper.drawTexture; -import static net.minecraft.client.gui.DrawableHelper.fill; - @Mixin(value = SplashOverlay.class, priority = 3000) public abstract class MixinSplashScreen { @@ -71,8 +67,8 @@ public abstract class MixinSplashScreen { client.getTextureManager().registerTexture(CUSTOM_PROGRESS_BAR_TEXTURE, new ConfigTexture(CUSTOM_PROGRESS_BAR_TEXTURE)); client.getTextureManager().registerTexture(CUSTOM_PROGRESS_BAR_BACKGROUND_TEXTURE, new ConfigTexture(CUSTOM_PROGRESS_BAR_BACKGROUND_TEXTURE)); } - @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/Window;getScaledWidth()I", shift = At.Shift.BEFORE, ordinal = 2)) - private void css$renderSplashBackground(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci) { + @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;getScaledWindowWidth()I", shift = At.Shift.BEFORE, ordinal = 2)) + private void css$renderSplashBackground(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) { if (CustomSplashScreenConfig.backgroundImage) { int width = client.getWindow().getScaledWidth(); int height = client.getWindow().getScaledHeight(); @@ -82,20 +78,19 @@ public abstract class MixinSplashScreen { if (f >= 1.0F) s = 1.0F - MathHelper.clamp(f - 1.0F, 0.0F, 1.0F); else if (reloading) s = MathHelper.clamp(g, 0.0F, 1.0F); else s = 1.0F; - RenderSystem.setShaderTexture(0, BACKGROUND_TEXTURE); RenderSystem.enableBlend(); RenderSystem.blendEquation(32774); RenderSystem.defaultBlendFunc(); RenderSystem.setShader(GameRenderer::getPositionTexProgram); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, s); - drawTexture(matrices, 0, 0, 0, 0, 0, width, height, width, height); + context.drawTexture(BACKGROUND_TEXTURE, 0, 0, 0, 0, 0, width, height, width, height); RenderSystem.defaultBlendFunc(); RenderSystem.disableBlend(); } } @Inject(at = @At("TAIL"), method = "render") - public void css$render(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci) { + public void css$render(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) { if (CustomSplashScreenConfig.logoStyle == CustomSplashScreenConfig.LogoStyle.Aspect1to1) { float f = this.reloadCompleteTime > -1L ? (float)(Util.getMeasuringTimeMs() - this.reloadCompleteTime) / 1000.0F : -1.0F; float s = 1.0f; @@ -106,13 +101,12 @@ public abstract class MixinSplashScreen { double d = Math.min((double)this.client.getWindow().getScaledWidth() * 0.75D, this.client.getWindow().getScaledHeight()) * 0.25D; int w = (int)(d * 2); // Render the Logo - RenderSystem.setShaderTexture(0, ASPECT_1to1_TEXTURE); RenderSystem.enableBlend(); RenderSystem.setShader(GameRenderer::getPositionTexProgram); RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA); if (!CustomSplashScreenConfig.logoBlend) RenderSystem.defaultBlendFunc(); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, s); - drawTexture(matrices, (int)(this.client.getWindow().getScaledWidth() * 0.5D) - (w / 2), (int)(d * 0.5D), w, w, 0, 0, 512, 512, 512, 512); + context.drawTexture(ASPECT_1to1_TEXTURE,(int)(this.client.getWindow().getScaledWidth() * 0.5D) - (w / 2), (int)(d * 0.5D), w, w, 0, 0, 512, 512, 512, 512); RenderSystem.defaultBlendFunc(); RenderSystem.disableBlend(); } @@ -120,13 +114,12 @@ public abstract class MixinSplashScreen { } @Inject(at = @At("TAIL"), method = "renderProgressBar") - private void css$renderProgressBar(MatrixStack matrices, int x1, int y1, int x2, int y2, float opacity, CallbackInfo ci) { + private void css$renderProgressBar(DrawContext context, int x1, int y1, int x2, int y2, float opacity, CallbackInfo ci) { int i = MathHelper.ceil((float)(x2 - x1 - 2) * this.progress); // Bossbar Progress Bar if (CustomSplashScreenConfig.progressBarType == CustomSplashScreenConfig.ProgressBarType.BossBar) { int color = CustomSplashScreenConfig.bossBarColor.ordinal() * 10; - RenderSystem.setShaderTexture(0, BOSS_BAR_TEXTURE); RenderSystem.setShader(GameRenderer::getPositionTexProgram); int overlay = 70 + CustomSplashScreenConfig.bossBarType.ordinal()*10; @@ -134,12 +127,12 @@ public abstract class MixinSplashScreen { int offset = ((x2 - x1) - width) / 2; i = MathHelper.ceil((float)(width - 2) * this.progress); - drawTexture(matrices, x1 + offset, y1 + 1, width, (int) ((width / 182f) * 5), 0, color, 182, 5,256, 256); - drawTexture(matrices, x1 + offset, y1 + 1, i, (int) ((width / 182f) * 5), 0, color+5, (int) (180 * this.progress), 5, 256, 256); + context.drawTexture(BOSS_BAR_TEXTURE, x1 + offset, y1 + 1, width, (int) ((width / 182f) * 5), 0, color, 182, 5,256, 256); + context.drawTexture(BOSS_BAR_TEXTURE, x1 + offset, y1 + 1, i, (int) ((width / 182f) * 5), 0, color+5, (int) (180 * this.progress), 5, 256, 256); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); if (overlay != 120) { - drawTexture(matrices, x1 + offset, y1 + 1, width, (int) ((width / 182f) * 5), 0, overlay, 182, 5,256, 256); + context.drawTexture(BOSS_BAR_TEXTURE, x1 + offset, y1 + 1, width, (int) ((width / 182f) * 5), 0, overlay, 182, 5,256, 256); } RenderSystem.disableBlend(); } @@ -150,13 +143,11 @@ public abstract class MixinSplashScreen { int height = (int) (((x2 - x1) / 400f) * 10); int u = CustomSplashScreenConfig.customProgressBarMode.equals(CustomSplashScreenConfig.ProgressBarMode.Slide) ? x2 - x1 - i : 0; if (CustomSplashScreenConfig.progressBarBackground) { - RenderSystem.setShaderTexture(0, CUSTOM_PROGRESS_BAR_BACKGROUND_TEXTURE); RenderSystem.setShader(GameRenderer::getPositionTexProgram); - drawTexture(matrices, x1, y1, x2 - x1, height, 0, 0, x2 - x1, height, x2 - x1, height); + context.drawTexture(CUSTOM_PROGRESS_BAR_BACKGROUND_TEXTURE, x1, y1, x2 - x1, height, 0, 0, x2 - x1, height, x2 - x1, height); } - RenderSystem.setShaderTexture(0, CUSTOM_PROGRESS_BAR_TEXTURE); RenderSystem.setShader(GameRenderer::getPositionTexProgram); - drawTexture(matrices, x1, y1, i, height, u, 0, regionWidth, height, x2 - x1, height); + context.drawTexture(CUSTOM_PROGRESS_BAR_TEXTURE, x1, y1, i, height, u, 0, regionWidth, height, x2 - x1, height); } // Spinning Circle Progress Indicator if (CustomSplashScreenConfig.progressBarType == CustomSplashScreenConfig.ProgressBarType.SpinningCircle) { @@ -171,45 +162,45 @@ public abstract class MixinSplashScreen { for (int j = 0; j<=CustomSplashScreenConfig.spinningCircleTrail; j++) { RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); - renderSpinningCircle(matrices,(time+j) % 24,centerY - size,centerY + size, centerX - size, centerX + size,size/5,color); + renderSpinningCircle(context,(time+j) % 24,centerY - size,centerY + size, centerX - size, centerX + size,size/5,color); } } } @Unique - private void renderSpinningCircle(MatrixStack matrices, int time, int top, int bottom, int left, int right, int blockSize, int color) { + private void renderSpinningCircle(DrawContext context, int time, int top, int bottom, int left, int right, int blockSize, int color) { switch (time) { //top - case 0 -> DrawableHelper.fill(matrices, left + 4*blockSize, top, left + 3*blockSize, top + blockSize, color); - case 1 -> DrawableHelper.fill(matrices, left + 5*blockSize, top, left + 4*blockSize, top + blockSize, color); - case 2 -> DrawableHelper.fill(matrices, left + 6*blockSize, top, left + 5*blockSize, top + blockSize, color); - case 3 -> DrawableHelper.fill(matrices, left + 7*blockSize, top, left + 6*blockSize, top + blockSize, color); + case 0 -> context.fill(left + 4*blockSize, top, left + 3*blockSize, top + blockSize, color); + case 1 -> context.fill(left + 5*blockSize, top, left + 4*blockSize, top + blockSize, color); + case 2 -> context.fill(left + 6*blockSize, top, left + 5*blockSize, top + blockSize, color); + case 3 -> context.fill(left + 7*blockSize, top, left + 6*blockSize, top + blockSize, color); //top right - case 4 -> DrawableHelper.fill(matrices, right - 3*blockSize, top + blockSize, right - 2*blockSize, top + 2*blockSize, color); - case 5 -> DrawableHelper.fill(matrices, right - 2*blockSize, top + 2*blockSize, right - blockSize, top + 3*blockSize, color); + case 4 -> context.fill(right - 3*blockSize, top + blockSize, right - 2*blockSize, top + 2*blockSize, color); + case 5 -> context.fill(right - 2*blockSize, top + 2*blockSize, right - blockSize, top + 3*blockSize, color); //right - case 6 -> DrawableHelper.fill(matrices, right - blockSize, top + 3*blockSize, right, top + 4*blockSize, color); - case 7 -> DrawableHelper.fill(matrices, right - blockSize, top + 4*blockSize, right, top + 5*blockSize, color); - case 8 -> DrawableHelper.fill(matrices, right - blockSize, top + 5*blockSize, right, top + 6*blockSize, color); - case 9 -> DrawableHelper.fill(matrices, right - blockSize, top + 6*blockSize, right, top + 7*blockSize, color); + case 6 -> context.fill(right - blockSize, top + 3*blockSize, right, top + 4*blockSize, color); + case 7 -> context.fill(right - blockSize, top + 4*blockSize, right, top + 5*blockSize, color); + case 8 -> context.fill(right - blockSize, top + 5*blockSize, right, top + 6*blockSize, color); + case 9 -> context.fill(right - blockSize, top + 6*blockSize, right, top + 7*blockSize, color); //bottom right - case 10 -> DrawableHelper.fill(matrices, right - 2*blockSize, bottom - 2*blockSize, right - blockSize, bottom - 3*blockSize, color); - case 11 -> DrawableHelper.fill(matrices, right - 3*blockSize, bottom - blockSize, right - 2*blockSize, bottom - 2*blockSize, color); + case 10 -> context.fill(right - 2*blockSize, bottom - 2*blockSize, right - blockSize, bottom - 3*blockSize, color); + case 11 -> context.fill(right - 3*blockSize, bottom - blockSize, right - 2*blockSize, bottom - 2*blockSize, color); //bottom - case 12 -> DrawableHelper.fill(matrices, right - 4*blockSize, bottom, right - 3*blockSize, bottom - blockSize, color); - case 13 -> DrawableHelper.fill(matrices, right - 5*blockSize, bottom, right - 4*blockSize, bottom - blockSize, color); - case 14 -> DrawableHelper.fill(matrices, right - 6*blockSize, bottom, right - 5*blockSize, bottom - blockSize, color); - case 15 -> DrawableHelper.fill(matrices, right - 7*blockSize, bottom, right - 6*blockSize, bottom - blockSize, color); + case 12 -> context.fill(right - 4*blockSize, bottom, right - 3*blockSize, bottom - blockSize, color); + case 13 -> context.fill(right - 5*blockSize, bottom, right - 4*blockSize, bottom - blockSize, color); + case 14 -> context.fill(right - 6*blockSize, bottom, right - 5*blockSize, bottom - blockSize, color); + case 15 -> context.fill(right - 7*blockSize, bottom, right - 6*blockSize, bottom - blockSize, color); //bottom left - case 16 -> DrawableHelper.fill(matrices, left + 3*blockSize, bottom - blockSize, left + 2*blockSize, bottom - 2*blockSize, color); - case 17 -> DrawableHelper.fill(matrices, left + 2*blockSize, bottom - 2*blockSize, left + blockSize, bottom - 3*blockSize, color); + case 16 -> context.fill(left + 3*blockSize, bottom - blockSize, left + 2*blockSize, bottom - 2*blockSize, color); + case 17 -> context.fill(left + 2*blockSize, bottom - 2*blockSize, left + blockSize, bottom - 3*blockSize, color); //left - case 18 -> DrawableHelper.fill(matrices, left + blockSize, bottom - 3*blockSize, left, bottom - 4*blockSize, color); - case 19 -> DrawableHelper.fill(matrices, left + blockSize, bottom - 4*blockSize, left, bottom - 5*blockSize, color); - case 20 -> DrawableHelper.fill(matrices, left + blockSize, bottom - 5*blockSize, left, bottom - 6*blockSize, color); - case 21 -> DrawableHelper.fill(matrices, left + blockSize, bottom - 6*blockSize, left, bottom - 7*blockSize, color); + case 18 -> context.fill(left + blockSize, bottom - 3*blockSize, left, bottom - 4*blockSize, color); + case 19 -> context.fill(left + blockSize, bottom - 4*blockSize, left, bottom - 5*blockSize, color); + case 20 -> context.fill(left + blockSize, bottom - 5*blockSize, left, bottom - 6*blockSize, color); + case 21 -> context.fill(left + blockSize, bottom - 6*blockSize, left, bottom - 7*blockSize, color); //top left - case 22 -> DrawableHelper.fill(matrices, left + 2*blockSize, top + 2*blockSize, left + blockSize, top + 3*blockSize, color); - case 23 -> DrawableHelper.fill(matrices, left + 3*blockSize, top + blockSize, left + 2 * blockSize, top + 2*blockSize, color); + case 22 -> context.fill(left + 2*blockSize, top + 2*blockSize, left + blockSize, top + 3*blockSize, color); + case 23 -> context.fill(left + 3*blockSize, top + blockSize, left + 2 * blockSize, top + 2*blockSize, color); } } // Replaced by the methods below for compatibility with Puzzle @@ -233,24 +224,24 @@ public abstract class MixinSplashScreen { GlStateManager._clearColor(m, n, o, 1.0F); } @Inject(method = "render", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;blendFunc(II)V", shift = At.Shift.AFTER)) - private void css$betterBlend(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci) { + private void css$betterBlend(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) { if (!CustomSplashScreenConfig.logoBlend) RenderSystem.defaultBlendFunc(); } @Inject(method = "renderProgressBar", at = @At("HEAD")) - private void css$addProgressBarBackground(MatrixStack matrices, int minX, int minY, int maxX, int maxY, float opacity, CallbackInfo ci) { + private void css$addProgressBarBackground(DrawContext context, int minX, int minY, int maxX, int maxY, float opacity, CallbackInfo ci) { if (CustomSplashScreenConfig.progressBarType.equals(CustomSplashScreenConfig.ProgressBarType.Vanilla) && CustomSplashScreenConfig.progressBarBackground) { float f = this.reloadCompleteTime > -1L ? (float) (Util.getMeasuringTimeMs() - this.reloadCompleteTime) / 1000.0F : -1.0F; int m = MathHelper.ceil((1.0F - MathHelper.clamp(f - 1.0F, 0.0F, 1.0F)) * 255.0F); RenderSystem.disableBlend(); - fill(matrices, minX, minY, maxX, maxY, withAlpha(MidnightColorUtil.hex2Rgb(CustomSplashScreenConfig.splashProgressBackgroundColor).getRGB(), m)); + context.fill(minX, minY, maxX, maxY, withAlpha(MidnightColorUtil.hex2Rgb(CustomSplashScreenConfig.splashProgressBackgroundColor).getRGB(), m)); } } - @ModifyArg(method = "renderProgressBar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/SplashOverlay;fill(Lnet/minecraft/client/util/math/MatrixStack;IIIII)V"), index = 5) + @ModifyArg(method = "renderProgressBar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;fill(IIIII)V"), index = 4) private int css$modifyProgressFrame(int color) { // Set the Progress Bar Frame Color to our configured value // return CustomSplashScreenConfig.progressBarType.equals(CustomSplashScreenConfig.ProgressBarType.Vanilla) ? MidnightColorUtil.hex2Rgb(CustomSplashScreenConfig.splashProgressFrameColor).getRGB() | 255 << 24 : 0; } - @ModifyArg(method = "renderProgressBar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/SplashOverlay;fill(Lnet/minecraft/client/util/math/MatrixStack;IIIII)V", ordinal = 0), index = 5) + @ModifyArg(method = "renderProgressBar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;fill(IIIII)V", ordinal = 0), index = 4) private int css$modifyProgressColor(int color) { // Set the Progress Bar Color to our configured value // return CustomSplashScreenConfig.progressBarType.equals(CustomSplashScreenConfig.ProgressBarType.Vanilla) ? MidnightColorUtil.hex2Rgb(CustomSplashScreenConfig.splashProgressBarColor).getRGB() | 255 << 24 : 0; }