From ab80391b29d184038760cee73f39988a615040ac Mon Sep 17 00:00:00 2001 From: Motschen Date: Wed, 22 Mar 2023 18:19:22 +0100 Subject: [PATCH] Blur 3.0.0 - Fade out & 1.19.4 - Add fade out effect (closes #41) - Duration can be configured seperately - Disabled by default until I get some feedback on it - Improve config screen (tabs & sliders) - French translations by @Calvineries - Update to 1.19.4 by @backryun & @byquanton --- gradle.properties | 2 +- src/main/java/com/tterrag/blur/Blur.java | 27 ++++++++++++------- .../com/tterrag/blur/config/BlurConfig.java | 8 +++--- .../tterrag/blur/mixin/MixinInGameHud.java | 10 ++++--- .../com/tterrag/blur/mixin/MixinScreen.java | 24 ++++++++++++----- .../resources/assets/blur/lang/de_de.json | 5 +++- .../resources/assets/blur/lang/en_us.json | 4 +-- src/main/resources/fabric.mod.json | 9 ++++--- 8 files changed, 58 insertions(+), 31 deletions(-) diff --git a/gradle.properties b/gradle.properties index b43bc78..a0f1828 100755 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G loader_version=0.14.17 # Mod Properties - mod_version=2.7.0 + mod_version=3.0.0 maven_group=com.tterrag.blur archives_base_name=blur diff --git a/src/main/java/com/tterrag/blur/Blur.java b/src/main/java/com/tterrag/blur/Blur.java index e49d88c..6f71fdf 100644 --- a/src/main/java/com/tterrag/blur/Blur.java +++ b/src/main/java/com/tterrag/blur/Blur.java @@ -14,8 +14,10 @@ public class Blur implements ClientModInitializer { public static final String MODID = "blur"; + public static final MinecraftClient client = MinecraftClient.getInstance(); public static long start; - public static long fadeOutProgress; + public static String prevScreen; + public static boolean screenHasBackground; private static final ManagedShaderEffect blur = ShaderEffectManager.getInstance().manage(new Identifier(MODID, "shaders/post/fade_in_blur.json"), shader -> shader.setUniformValue("Radius", (float) BlurConfig.radius)); @@ -27,7 +29,7 @@ public void onInitializeClient() { ShaderEffectRenderCallback.EVENT.register((deltaTick) -> { if (start > 0) { - blurProgress.set(getProgress(MinecraftClient.getInstance().currentScreen != null)); + blurProgress.set(getProgress(client.currentScreen != null)); blur.render(deltaTick); } }); @@ -36,20 +38,23 @@ public void onInitializeClient() { private static boolean doFade = false; public static void onScreenChange(Screen newGui) { - if (MinecraftClient.getInstance().world != null) { + if (client.world != null) { boolean excluded = newGui == null || BlurConfig.blurExclusions.stream().anyMatch(exclusion -> newGui.getClass().getName().contains(exclusion)); if (!excluded) { + screenHasBackground = false; if (BlurConfig.showScreenTitle) System.out.println(newGui.getClass().getName()); blur.setUniformValue("Radius", (float) BlurConfig.radius); if (doFade) { start = System.currentTimeMillis(); doFade = false; } - fadeOutProgress = BlurConfig.fadeOutTimeMillis; - } else if (newGui == null && fadeOutProgress > 0) { + prevScreen = newGui.getClass().getName(); + } else if (newGui == null && BlurConfig.fadeOutTimeMillis > 0 && !BlurConfig.blurExclusions.contains(prevScreen)) { blur.setUniformValue("Radius", (float) BlurConfig.radius); start = System.currentTimeMillis(); + doFade = true; } else { + screenHasBackground = false; start = -1; doFade = true; } @@ -63,19 +68,23 @@ private static float getProgress(boolean fadeIn) { return x; } else { - float x = Math.min((System.currentTimeMillis() - start) / (float) BlurConfig.fadeOutTimeMillis, 1); + float x = Math.max(1+(start - System.currentTimeMillis()) / (float) BlurConfig.fadeOutTimeMillis, 0); if (BlurConfig.ease) x *= (2 - x); // easeOutCubic - return -x + BlurConfig.fadeOutTimeMillis; + if (x <= 0) { + start = 0; + screenHasBackground = false; + } + return x; } } - public static int getBackgroundColor(boolean second, Screen screen) { + public static int getBackgroundColor(boolean second, boolean fadeIn) { int a = second ? BlurConfig.gradientEndAlpha : BlurConfig.gradientStartAlpha; var col = MidnightColorUtil.hex2Rgb(second ? BlurConfig.gradientEnd : BlurConfig.gradientStart); int r = (col.getRGB() >> 16) & 0xFF; int b = (col.getRGB() >> 8) & 0xFF; int g = col.getRGB() & 0xFF; - float prog = getProgress(screen != null); + float prog = getProgress(fadeIn); a *= prog; r *= prog; g *= prog; diff --git a/src/main/java/com/tterrag/blur/config/BlurConfig.java b/src/main/java/com/tterrag/blur/config/BlurConfig.java index d8ec801..2d9b627 100644 --- a/src/main/java/com/tterrag/blur/config/BlurConfig.java +++ b/src/main/java/com/tterrag/blur/config/BlurConfig.java @@ -8,10 +8,10 @@ public class BlurConfig extends MidnightConfig { public static final String style = "style"; - public static final String misc = "misc"; + public static final String screens = "screens"; - @Entry(category = misc) + @Entry(category = screens) public static List blurExclusions = Lists.newArrayList(ChatScreen.class.getName(), "com.replaymod.lib.de.johni0702.minecraft.gui.container.AbstractGuiOverlay$UserInputGuiScreen", "ai.arcblroth.projectInception.client.InceptionInterfaceScreen", @@ -21,7 +21,7 @@ public class BlurConfig extends MidnightConfig { @Entry(category = style, min = 0, max = 5000, width = 4) public static int fadeTimeMillis = 200; @Entry(category = style, min = 0, max = 5000, width = 4) - public static int fadeOutTimeMillis = 200; + public static int fadeOutTimeMillis = 0; @Entry(category = style) public static boolean ease = true; @Entry(category = style, isSlider = true, min = 0, max = 100) @@ -34,6 +34,6 @@ public class BlurConfig extends MidnightConfig { public static String gradientEnd = "#000000"; @Entry(category = style, isSlider = true, min = 0, max = 255) public static int gradientEndAlpha = 75; - @Entry(category = misc) + @Entry(category = screens) public static boolean showScreenTitle = false; } \ No newline at end of file diff --git a/src/main/java/com/tterrag/blur/mixin/MixinInGameHud.java b/src/main/java/com/tterrag/blur/mixin/MixinInGameHud.java index 2dec110..13cf884 100644 --- a/src/main/java/com/tterrag/blur/mixin/MixinInGameHud.java +++ b/src/main/java/com/tterrag/blur/mixin/MixinInGameHud.java @@ -1,10 +1,12 @@ package com.tterrag.blur.mixin; import com.tterrag.blur.Blur; +import com.tterrag.blur.config.BlurConfig; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.gui.hud.InGameHud; import net.minecraft.client.util.math.MatrixStack; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -15,11 +17,11 @@ public class MixinInGameHud extends DrawableHelper { @Shadow private int scaledWidth; @Shadow private int scaledHeight; - @Shadow private MinecraftClient client; - @Inject(at = @At("HEAD"), method = "render") + @Final @Shadow private MinecraftClient client; + @Inject(at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;setShaderTexture(ILnet/minecraft/util/Identifier;)V", ordinal = 0, shift = At.Shift.BEFORE), method = "render") public void blur$onRender(MatrixStack matrices, float tickDelta, CallbackInfo ci) { - if (client.currentScreen == null && client.world != null && Blur.start > 0) { - this.fillGradient(matrices, 0, 0, this.scaledWidth, this.scaledHeight, Blur.getBackgroundColor(false, null), Blur.getBackgroundColor(true, null)); + if (client.currentScreen == null && client.world != null && Blur.start > 0 && !BlurConfig.blurExclusions.contains(Blur.prevScreen) && Blur.screenHasBackground) { + fillGradient(matrices, 0, 0, this.scaledWidth, this.scaledHeight, Blur.getBackgroundColor(false, false), Blur.getBackgroundColor(true, false)); } } } diff --git a/src/main/java/com/tterrag/blur/mixin/MixinScreen.java b/src/main/java/com/tterrag/blur/mixin/MixinScreen.java index 16ab017..6388d90 100755 --- a/src/main/java/com/tterrag/blur/mixin/MixinScreen.java +++ b/src/main/java/com/tterrag/blur/mixin/MixinScreen.java @@ -1,7 +1,10 @@ package com.tterrag.blur.mixin; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.text.Text; import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -14,31 +17,38 @@ import net.minecraft.client.gui.screen.Screen; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.util.Locale; - @Mixin(Screen.class) public abstract class MixinScreen { @Shadow @Nullable protected MinecraftClient client; + @Shadow @Final protected Text title; + private final Text blurConfig = Text.translatable("blur.midnightconfig.title"); + @Inject(at = @At("HEAD"), method = "tick") private void blur$reloadShader(CallbackInfo ci) { - if (this.getClass().toString().toLowerCase(Locale.ROOT).contains("midnightconfigscreen") && this.client != null) { + if (this.client != null && this.title.equals(blurConfig)) { Blur.onScreenChange(this.client.currentScreen); } } + @Inject(at = @At("HEAD"), method = "renderBackground") + public void blur$getBackgroundEnabled(MatrixStack matrices, CallbackInfo ci) { + if (this.client != null && this.client.world != null) { + Blur.screenHasBackground = true; + } + } @ModifyConstant( - method = "renderBackground(Lnet/minecraft/client/util/math/MatrixStack;I)V", + method = "renderBackground", constant = @Constant(intValue = -1072689136)) private int blur$getFirstBackgroundColor(int color) { - return Blur.getBackgroundColor(false, client.currentScreen); + return Blur.getBackgroundColor(false, true); } @ModifyConstant( - method = "renderBackground(Lnet/minecraft/client/util/math/MatrixStack;I)V", + method = "renderBackground", constant = @Constant(intValue = -804253680)) private int blur$getSecondBackgroundColor(int color) { - return Blur.getBackgroundColor(true, client.currentScreen); + return Blur.getBackgroundColor(true, true); } } diff --git a/src/main/resources/assets/blur/lang/de_de.json b/src/main/resources/assets/blur/lang/de_de.json index c9ccafb..53ada1d 100644 --- a/src/main/resources/assets/blur/lang/de_de.json +++ b/src/main/resources/assets/blur/lang/de_de.json @@ -1,12 +1,15 @@ { "blur.midnightconfig.title": "Blur Konfiguration", "blur.midnightconfig.blurExclusions": "Blur-Ausnahmen", + "blur.midnightconfig.category.style": "Stil", + "blur.midnightconfig.category.screens": "Bildschirme", "blur.midnightconfig.fadeTimeMillis": "Überblendzeit (in Millisekunden)", + "blur.midnightconfig.fadeOutTimeMillis": "Ausblendzeit (in milliseconds)", "blur.midnightconfig.ease": "Geschmeidige Animation", "blur.midnightconfig.radius": "Radius", "blur.midnightconfig.gradientStart": "Farbverlauf-Anfangsfarbe", "blur.midnightconfig.gradientEnd": "Farbverlauf-Endfarbe", "blur.midnightconfig.gradientStartAlpha": "Farbverlauf-Anfangstransparenz", "blur.midnightconfig.gradientEndAlpha": "Farbverlauf-Endstransparenz", - "blur.midnightconfig.showScreenTitle": "Zeige Bildschirmtitel" + "blur.midnightconfig.showScreenTitle": "Logge Bildschirmtitel" } \ No newline at end of file diff --git a/src/main/resources/assets/blur/lang/en_us.json b/src/main/resources/assets/blur/lang/en_us.json index 71ef601..d75745d 100755 --- a/src/main/resources/assets/blur/lang/en_us.json +++ b/src/main/resources/assets/blur/lang/en_us.json @@ -1,7 +1,7 @@ { "blur.midnightconfig.title": "Blur Config", "blur.midnightconfig.category.style": "Style", - "blur.midnightconfig.category.misc": "Miscellaneous", + "blur.midnightconfig.category.screens": "Screens", "blur.midnightconfig.blurExclusions": "Blur Exclusions", "blur.midnightconfig.fadeTimeMillis": "Fade Time (in milliseconds)", "blur.midnightconfig.fadeOutTimeMillis": "Fade Out Time (in milliseconds)", @@ -11,5 +11,5 @@ "blur.midnightconfig.gradientEnd": "Gradient End Color", "blur.midnightconfig.gradientStartAlpha": "Gradient Start Alpha", "blur.midnightconfig.gradientEndAlpha": "Gradient End Alpha", - "blur.midnightconfig.showScreenTitle": "Show screen title" + "blur.midnightconfig.showScreenTitle": "Log screen title" } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index a16a204..fddb6bd 100755 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -12,19 +12,22 @@ ] }, "contact": { - "homepage": "https://www.curseforge.com/minecraft/mc-mods/blur-fabric", + "homepage": "https://modrinth.com/mod/blur-fabric", "sources": "https://github.com/Motschen/Blur", "issues": "https://github.com/Motschen/Blur/issues" }, "authors": [ "tterrag1098", - "Pyrofab", "Motschen", + "Pyrofab", "backryun", "byquanton" ], "description": "Modifies the background behind Minecraft GUIs to have a blur effect", "mixins": [ "mixins.blur.json" - ] + ], + "depends": { + "satin": "*" + } }