mirror of
https://github.com/Motschen/Blur.git
synced 2025-12-13 02:15:09 +01:00
Implement fade out effect, better config screen
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id 'fabric-loom' version '1.0-SNAPSHOT'
|
||||
id 'fabric-loom' version '1.1-SNAPSHOT'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
|
||||
loader_version=0.14.11
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 2.6.1
|
||||
mod_version = 2.7.0
|
||||
maven_group = com.tterrag.blur
|
||||
archives_base_name = blur
|
||||
|
||||
@@ -16,4 +16,4 @@ org.gradle.jvmargs=-Xmx1G
|
||||
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
|
||||
fabric_version=0.69.0+1.19.3
|
||||
satin_version = 1.10.0
|
||||
midnightlib_version=1.1.0-fabric
|
||||
midnightlib_version=1.2.1-fabric
|
||||
|
||||
@@ -8,47 +8,34 @@ import ladysnake.satin.api.managed.ShaderEffectManager;
|
||||
import ladysnake.satin.api.managed.uniform.Uniform1f;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.ChatScreen;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.util.Identifier;
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Blur implements ClientModInitializer {
|
||||
|
||||
public static final String MODID = "blur";
|
||||
public static List<String> defaultExclusions = new ArrayList<>();
|
||||
public static long start;
|
||||
public static long fadeOutProgress;
|
||||
|
||||
private long start;
|
||||
|
||||
private final ManagedShaderEffect blur = ShaderEffectManager.getInstance().manage(new Identifier(MODID, "shaders/post/fade_in_blur.json"),
|
||||
private static final ManagedShaderEffect blur = ShaderEffectManager.getInstance().manage(new Identifier(MODID, "shaders/post/fade_in_blur.json"),
|
||||
shader -> shader.setUniformValue("Radius", (float) BlurConfig.radius));
|
||||
private final Uniform1f blurProgress = blur.findUniform1f("Progress");
|
||||
|
||||
public static final Blur INSTANCE = new Blur();
|
||||
private static final Uniform1f blurProgress = blur.findUniform1f("Progress");
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
defaultExclusions.add(ChatScreen.class.getName());
|
||||
defaultExclusions.add("com.replaymod.lib.de.johni0702.minecraft.gui.container.AbstractGuiOverlay$UserInputGuiScreen");
|
||||
defaultExclusions.add("ai.arcblroth.projectInception.client.InceptionInterfaceScreen");
|
||||
defaultExclusions.add("net.optifine.gui.GuiChatOF");
|
||||
defaultExclusions.add("io.github.darkkronicle.advancedchatcore.chat.AdvancedChatScreen");
|
||||
defaultExclusions.add("net.coderbot.iris.gui.screen.ShaderPackScreen");
|
||||
BlurConfig.init("blur", BlurConfig.class);
|
||||
|
||||
ShaderEffectRenderCallback.EVENT.register((deltaTick) -> {
|
||||
if (start > 0) {
|
||||
blurProgress.set(getProgress());
|
||||
blurProgress.set(getProgress(MinecraftClient.getInstance().currentScreen != null));
|
||||
blur.render(deltaTick);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean doFade = false;
|
||||
private static boolean doFade = false;
|
||||
|
||||
public void onScreenChange(Screen newGui) {
|
||||
public static void onScreenChange(Screen newGui) {
|
||||
if (MinecraftClient.getInstance().world != null) {
|
||||
boolean excluded = newGui == null || BlurConfig.blurExclusions.stream().anyMatch(exclusion -> newGui.getClass().getName().contains(exclusion));
|
||||
if (!excluded) {
|
||||
@@ -58,6 +45,10 @@ public class Blur implements ClientModInitializer {
|
||||
start = System.currentTimeMillis();
|
||||
doFade = false;
|
||||
}
|
||||
fadeOutProgress = BlurConfig.fadeOutTimeMillis;
|
||||
} else if (newGui == null && fadeOutProgress > 0) {
|
||||
blur.setUniformValue("Radius", (float) BlurConfig.radius);
|
||||
start = System.currentTimeMillis();
|
||||
} else {
|
||||
start = -1;
|
||||
doFade = true;
|
||||
@@ -65,19 +56,26 @@ public class Blur implements ClientModInitializer {
|
||||
}
|
||||
}
|
||||
|
||||
private float getProgress() {
|
||||
float x = Math.min((System.currentTimeMillis() - start) / (float) BlurConfig.fadeTimeMillis, 1);
|
||||
if (BlurConfig.ease) x *= (2 - x); // easeOutCubic
|
||||
return x;
|
||||
private static float getProgress(boolean fadeIn) {
|
||||
if (fadeIn) {
|
||||
float x = Math.min((System.currentTimeMillis() - start) / (float) BlurConfig.fadeTimeMillis, 1);
|
||||
if (BlurConfig.ease) x *= (2 - x); // easeInCubic
|
||||
return x;
|
||||
}
|
||||
else {
|
||||
float x = Math.min((System.currentTimeMillis() - start) / (float) BlurConfig.fadeOutTimeMillis, 1);
|
||||
if (BlurConfig.ease) x *= (2 - x); // easeOutCubic
|
||||
return -x + BlurConfig.fadeOutTimeMillis;
|
||||
}
|
||||
}
|
||||
|
||||
public int getBackgroundColor(boolean second) {
|
||||
public static int getBackgroundColor(boolean second, Screen screen) {
|
||||
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 = INSTANCE.getProgress();
|
||||
float prog = getProgress(screen != null);
|
||||
a *= prog;
|
||||
r *= prog;
|
||||
g *= prog;
|
||||
|
||||
@@ -1,27 +1,39 @@
|
||||
package com.tterrag.blur.config;
|
||||
|
||||
import com.tterrag.blur.Blur;
|
||||
import com.google.common.collect.Lists;
|
||||
import eu.midnightdust.lib.config.MidnightConfig;
|
||||
import net.minecraft.client.gui.screen.ChatScreen;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BlurConfig extends MidnightConfig {
|
||||
@Entry
|
||||
public static List<String> blurExclusions = Blur.defaultExclusions;
|
||||
@Entry(min = 0, max = 5000, width = 4)
|
||||
public static final String style = "style";
|
||||
public static final String misc = "misc";
|
||||
|
||||
|
||||
@Entry(category = misc)
|
||||
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",
|
||||
"net.optifine.gui.GuiChatOF",
|
||||
"io.github.darkkronicle.advancedchatcore.chat.AdvancedChatScreen",
|
||||
"net.coderbot.iris.gui.screen.ShaderPackScreen");
|
||||
@Entry(category = style, min = 0, max = 5000, width = 4)
|
||||
public static int fadeTimeMillis = 200;
|
||||
@Entry
|
||||
@Entry(category = style, min = 0, max = 5000, width = 4)
|
||||
public static int fadeOutTimeMillis = 200;
|
||||
@Entry(category = style)
|
||||
public static boolean ease = true;
|
||||
@Entry(min = 0, max = 500, width = 3)
|
||||
@Entry(category = style, isSlider = true, min = 0, max = 100)
|
||||
public static int radius = 8;
|
||||
@Entry(isColor = true, width = 7, min = 7)
|
||||
@Entry(category = style, isColor = true, width = 7, min = 7)
|
||||
public static String gradientStart = "#000000";
|
||||
@Entry(min = 0, max = 255)
|
||||
@Entry(category = style, isSlider = true, min = 0, max = 255)
|
||||
public static int gradientStartAlpha = 75;
|
||||
@Entry(isColor = true, width = 7, min = 7)
|
||||
@Entry(category = style, isColor = true, width = 7, min = 7)
|
||||
public static String gradientEnd = "#000000";
|
||||
@Entry(min = 0, max = 255)
|
||||
@Entry(category = style, isSlider = true, min = 0, max = 255)
|
||||
public static int gradientEndAlpha = 75;
|
||||
@Entry
|
||||
@Entry(category = misc)
|
||||
public static boolean showScreenTitle = false;
|
||||
}
|
||||
}
|
||||
25
src/main/java/com/tterrag/blur/mixin/MixinInGameHud.java
Normal file
25
src/main/java/com/tterrag/blur/mixin/MixinInGameHud.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.tterrag.blur.mixin;
|
||||
|
||||
import com.tterrag.blur.Blur;
|
||||
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.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(InGameHud.class)
|
||||
public class MixinInGameHud extends DrawableHelper {
|
||||
@Shadow private int scaledWidth;
|
||||
@Shadow private int scaledHeight;
|
||||
@Shadow private MinecraftClient client;
|
||||
@Inject(at = @At("HEAD"), 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,6 @@ public class MixinMinecraftClient {
|
||||
target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;",
|
||||
opcode = Opcodes.PUTFIELD))
|
||||
private void onScreenOpen(Screen newScreen, CallbackInfo info) {
|
||||
Blur.INSTANCE.onScreenChange(newScreen);
|
||||
Blur.onScreenChange(newScreen);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
package com.tterrag.blur.mixin;
|
||||
|
||||
import com.tterrag.blur.config.BlurConfig;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.TextColor;
|
||||
import net.minecraft.util.Formatting;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
@@ -26,12 +21,10 @@ public abstract class MixinScreen {
|
||||
|
||||
@Shadow @Nullable protected MinecraftClient client;
|
||||
|
||||
@Shadow protected TextRenderer textRenderer;
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "tick")
|
||||
private void blur$reloadShader(CallbackInfo ci) {
|
||||
if (this.getClass().toString().toLowerCase(Locale.ROOT).contains("midnightconfigscreen") && this.client != null) {
|
||||
Blur.INSTANCE.onScreenChange(this.client.currentScreen);
|
||||
Blur.onScreenChange(this.client.currentScreen);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,13 +32,13 @@ public abstract class MixinScreen {
|
||||
method = "renderBackground(Lnet/minecraft/client/util/math/MatrixStack;I)V",
|
||||
constant = @Constant(intValue = -1072689136))
|
||||
private int blur$getFirstBackgroundColor(int color) {
|
||||
return Blur.INSTANCE.getBackgroundColor(false);
|
||||
return Blur.getBackgroundColor(false, client.currentScreen);
|
||||
}
|
||||
|
||||
@ModifyConstant(
|
||||
method = "renderBackground(Lnet/minecraft/client/util/math/MatrixStack;I)V",
|
||||
constant = @Constant(intValue = -804253680))
|
||||
private int blur$getSecondBackgroundColor(int color) {
|
||||
return Blur.INSTANCE.getBackgroundColor(true);
|
||||
return Blur.getBackgroundColor(true, client.currentScreen);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
{
|
||||
"blur.midnightconfig.title": "Blur Config",
|
||||
"blur.midnightconfig.category.style": "Style",
|
||||
"blur.midnightconfig.category.misc": "Miscellaneous",
|
||||
"blur.midnightconfig.blurExclusions": "Blur Exclusions",
|
||||
"blur.midnightconfig.fadeTimeMillis": "Fade Time (in milliseconds)",
|
||||
"blur.midnightconfig.fadeOutTimeMillis": "Fade Out Time (in milliseconds)",
|
||||
"blur.midnightconfig.ease": "Ease Animation",
|
||||
"blur.midnightconfig.radius": "Radius",
|
||||
"blur.midnightconfig.gradientStart": "Gradient Start Color",
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"icon": "assets/blur/icon.png",
|
||||
"entrypoints": {
|
||||
"client": [
|
||||
"com.tterrag.blur.Blur::INSTANCE"
|
||||
"com.tterrag.blur.Blur"
|
||||
]
|
||||
},
|
||||
"contact": {
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"client": [
|
||||
"MixinScreen",
|
||||
"MixinMinecraftClient"
|
||||
"MixinMinecraftClient",
|
||||
"MixinInGameHud"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
||||
Reference in New Issue
Block a user