Skip to content

Commit

Permalink
Blur 3.0.0 - Fade out & 1.19.4
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Motschen committed Mar 22, 2023
1 parent a51b02a commit ab80391
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 31 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
27 changes: 18 additions & 9 deletions src/main/java/com/tterrag/blur/Blur.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
}
});
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/tterrag/blur/config/BlurConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> blurExclusions = Lists.newArrayList(ChatScreen.class.getName(),
"com.replaymod.lib.de.johni0702.minecraft.gui.container.AbstractGuiOverlay$UserInputGuiScreen",
"ai.arcblroth.projectInception.client.InceptionInterfaceScreen",
Expand All @@ -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)
Expand All @@ -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;
}
10 changes: 6 additions & 4 deletions src/main/java/com/tterrag/blur/mixin/MixinInGameHud.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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));
}
}
}
24 changes: 17 additions & 7 deletions src/main/java/com/tterrag/blur/mixin/MixinScreen.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
}
5 changes: 4 additions & 1 deletion src/main/resources/assets/blur/lang/de_de.json
Original file line number Diff line number Diff line change
@@ -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"
}
4 changes: 2 additions & 2 deletions src/main/resources/assets/blur/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -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)",
Expand All @@ -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"
}
9 changes: 6 additions & 3 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*"
}
}

0 comments on commit ab80391

Please sign in to comment.