mirror of
https://github.com/Motschen/Blur.git
synced 2025-12-16 19:55:10 +01:00
Rewrite large parts of the mod
Blur is now more alive than ever, as I've been working on a new update: Blur+ 🪩 The mod's goal now is to improve upon the vanilla blur effect, adding smooth & configurable animations, the ability to apply it to containers (such as the inventory, chests, etc.), as well as customizable gradient backgrounds. 🌈
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'fabric-loom' version '1.4-SNAPSHOT'
|
id 'fabric-loom' version '1.5-SNAPSHOT'
|
||||||
id 'maven-publish'
|
id 'maven-publish'
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,6 +28,9 @@ repositories {
|
|||||||
maven {
|
maven {
|
||||||
url = "https://api.modrinth.com/maven"
|
url = "https://api.modrinth.com/maven"
|
||||||
}
|
}
|
||||||
|
flatDir {
|
||||||
|
dirs("localMaven")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -36,8 +39,8 @@ dependencies {
|
|||||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||||
|
|
||||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||||
modImplementation "org.ladysnake:satin:${satin_version}"
|
//modImplementation "org.ladysnake:satin:${satin_version}"
|
||||||
include "org.ladysnake:satin:${satin_version}"
|
//include "org.ladysnake:satin:${satin_version}"
|
||||||
|
|
||||||
implementation 'com.google.code.findbugs:jsr305:3.0.2'
|
implementation 'com.google.code.findbugs:jsr305:3.0.2'
|
||||||
modImplementation "maven.modrinth:midnightlib:${project.midnightlib_version}"
|
modImplementation "maven.modrinth:midnightlib:${project.midnightlib_version}"
|
||||||
|
|||||||
@@ -4,17 +4,16 @@ org.gradle.parallel=true
|
|||||||
|
|
||||||
# Fabric Properties
|
# Fabric Properties
|
||||||
# check these on https://fabricmc.net/develop
|
# check these on https://fabricmc.net/develop
|
||||||
minecraft_version=1.20.4
|
minecraft_version=24w11a
|
||||||
yarn_mappings=1.20.4+build.3
|
yarn_mappings=24w11a+build.5
|
||||||
loader_version=0.15.3
|
loader_version=0.15.7
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version=3.2.0
|
mod_version=4.0.0
|
||||||
maven_group=com.tterrag.blur
|
maven_group=eu.midnightdust.blur
|
||||||
archives_base_name=blur
|
archives_base_name=blur
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
|
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
|
||||||
fabric_version=0.91.3+1.20.4
|
fabric_version=0.96.11+1.20.5
|
||||||
satin_version=1.15.0
|
midnightlib_version=fabric-1.5.3-24w09a
|
||||||
midnightlib_version=1.5.3-fabric
|
|
||||||
|
|||||||
BIN
localMaven/midnightlib-fabric-1.5.3-24w09a.jar
Normal file
BIN
localMaven/midnightlib-fabric-1.5.3-24w09a.jar
Normal file
Binary file not shown.
@@ -1,97 +0,0 @@
|
|||||||
package com.tterrag.blur;
|
|
||||||
|
|
||||||
import com.tterrag.blur.config.BlurConfig;
|
|
||||||
import eu.midnightdust.lib.util.MidnightColorUtil;
|
|
||||||
import ladysnake.satin.api.event.ShaderEffectRenderCallback;
|
|
||||||
import ladysnake.satin.api.managed.ManagedShaderEffect;
|
|
||||||
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.Screen;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class Blur implements ClientModInitializer {
|
|
||||||
|
|
||||||
public static final String MODID = "blur";
|
|
||||||
public static final MinecraftClient client = MinecraftClient.getInstance();
|
|
||||||
public static long start;
|
|
||||||
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));
|
|
||||||
private static final Uniform1f blurProgress = blur.findUniform1f("Progress");
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onInitializeClient() {
|
|
||||||
BlurConfig.init("blur", BlurConfig.class);
|
|
||||||
|
|
||||||
ShaderEffectRenderCallback.EVENT.register((deltaTick) -> {
|
|
||||||
if (start > 0) {
|
|
||||||
blurProgress.set(getProgress(client.currentScreen != null));
|
|
||||||
blur.render(deltaTick);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean doFade = false;
|
|
||||||
|
|
||||||
public static void onScreenChange(Screen newGui) {
|
|
||||||
if (client.world != null) {
|
|
||||||
boolean excluded = newGui == null || BlurConfig.blurExclusions.stream().anyMatch(exclusion -> newGui.getClass().getName().startsWith(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;
|
|
||||||
}
|
|
||||||
prevScreen = newGui.getClass().getName();
|
|
||||||
} else if (newGui == null && BlurConfig.fadeOutTimeMillis > 0 && !Objects.equals(prevScreen, "")) {
|
|
||||||
blur.setUniformValue("Radius", (float) BlurConfig.radius);
|
|
||||||
start = System.currentTimeMillis();
|
|
||||||
doFade = true;
|
|
||||||
} else {
|
|
||||||
screenHasBackground = false;
|
|
||||||
start = -1;
|
|
||||||
doFade = true;
|
|
||||||
prevScreen = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static float getProgress(boolean fadeIn) {
|
|
||||||
float x;
|
|
||||||
if (fadeIn) {
|
|
||||||
x = Math.min((System.currentTimeMillis() - start) / (float) BlurConfig.fadeTimeMillis, 1);
|
|
||||||
if (BlurConfig.ease) x *= (2 - x); // easeInCubic
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
x = Math.max(1 + (start - System.currentTimeMillis()) / (float) BlurConfig.fadeOutTimeMillis, 0);
|
|
||||||
if (BlurConfig.ease) x *= (2 - x); // easeOutCubic
|
|
||||||
if (x <= 0) {
|
|
||||||
start = 0;
|
|
||||||
screenHasBackground = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
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(fadeIn);
|
|
||||||
a *= prog;
|
|
||||||
r *= prog;
|
|
||||||
g *= prog;
|
|
||||||
b *= prog;
|
|
||||||
return a << 24 | r << 16 | b << 8 | g;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package com.tterrag.blur.config;
|
|
||||||
|
|
||||||
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 {
|
|
||||||
public static final String STYLE = "style";
|
|
||||||
public static final String SCREENS = "screens";
|
|
||||||
|
|
||||||
@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",
|
|
||||||
"net.optifine.gui.GuiChatOF",
|
|
||||||
"baritone.",
|
|
||||||
"io.github.darkkronicle.advancedchatcore.chat.AdvancedChatScreen",
|
|
||||||
"net.coderbot.iris.gui.screen.ShaderPackScreen",
|
|
||||||
"eu.midnightdust.midnightcontrols.client.gui.TouchscreenOverlay");
|
|
||||||
@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;
|
|
||||||
@Entry(category = STYLE)
|
|
||||||
public static boolean ease = true;
|
|
||||||
@Entry(category = STYLE, isSlider = true, min = 0, max = 100)
|
|
||||||
public static int radius = 8;
|
|
||||||
@Entry(category = STYLE, isColor = true, width = 7, min = 7)
|
|
||||||
public static String gradientStart = "#000000";
|
|
||||||
@Entry(category = STYLE, isSlider = true, min = 0, max = 255)
|
|
||||||
public static int gradientStartAlpha = 75;
|
|
||||||
@Entry(category = STYLE, isColor = true, width = 7, min = 7)
|
|
||||||
public static String gradientEnd = "#000000";
|
|
||||||
@Entry(category = STYLE, isSlider = true, min = 0, max = 255)
|
|
||||||
public static int gradientEndAlpha = 75;
|
|
||||||
@Entry(category = SCREENS)
|
|
||||||
public static boolean showScreenTitle = false;
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
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.DrawContext;
|
|
||||||
import net.minecraft.client.gui.hud.InGameHud;
|
|
||||||
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;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
@Mixin(InGameHud.class)
|
|
||||||
public class MixinInGameHud {
|
|
||||||
@Shadow private int scaledWidth;
|
|
||||||
@Shadow private int scaledHeight;
|
|
||||||
@Final @Shadow private MinecraftClient client;
|
|
||||||
@Inject(at = @At("TAIL"), method = "render")
|
|
||||||
public void blur$onRender(DrawContext context, float tickDelta, CallbackInfo ci) {
|
|
||||||
if (client.currentScreen == null && client.world != null && Blur.start > 0 && (Blur.prevScreen == null || BlurConfig.blurExclusions.stream().noneMatch(exclusion -> Blur.prevScreen.startsWith(exclusion))) && Blur.screenHasBackground) {
|
|
||||||
context.fillGradient(0, 0, this.scaledWidth, this.scaledHeight, Blur.getBackgroundColor(false, false), Blur.getBackgroundColor(true, false));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package com.tterrag.blur.mixin;
|
|
||||||
|
|
||||||
import org.objectweb.asm.Opcodes;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
import com.tterrag.blur.Blur;
|
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
|
||||||
|
|
||||||
@Mixin(MinecraftClient.class)
|
|
||||||
public class MixinMinecraftClient {
|
|
||||||
|
|
||||||
@Inject(method = "setScreen",
|
|
||||||
at = @At(value = "FIELD",
|
|
||||||
target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;",
|
|
||||||
opcode = Opcodes.PUTFIELD))
|
|
||||||
private void onScreenOpen(Screen newScreen, CallbackInfo info) {
|
|
||||||
Blur.onScreenChange(newScreen);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
package com.tterrag.blur.mixin;
|
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
import net.minecraft.client.gui.DrawContext;
|
|
||||||
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;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Constant;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.ModifyConstant;
|
|
||||||
|
|
||||||
import com.tterrag.blur.Blur;
|
|
||||||
|
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
@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.client != null && this.title.equals(blurConfig)) {
|
|
||||||
Blur.onScreenChange(this.client.currentScreen);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@Inject(at = @At("HEAD"), method = "renderBackground")
|
|
||||||
public void blur$getBackgroundEnabled(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
|
|
||||||
if (this.client != null && this.client.world != null) {
|
|
||||||
Blur.screenHasBackground = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ModifyConstant(
|
|
||||||
method = "renderInGameBackground",
|
|
||||||
constant = @Constant(intValue = -1072689136))
|
|
||||||
private int blur$getFirstBackgroundColor(int color) {
|
|
||||||
return Blur.getBackgroundColor(false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ModifyConstant(
|
|
||||||
method = "renderInGameBackground",
|
|
||||||
constant = @Constant(intValue = -804253680))
|
|
||||||
private int blur$getSecondBackgroundColor(int color) {
|
|
||||||
return Blur.getBackgroundColor(true, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
74
src/main/java/eu/midnightdust/blur/Blur.java
Normal file
74
src/main/java/eu/midnightdust/blur/Blur.java
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
package eu.midnightdust.blur;
|
||||||
|
|
||||||
|
import eu.midnightdust.blur.config.BlurConfig;
|
||||||
|
import eu.midnightdust.lib.util.MidnightColorUtil;
|
||||||
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
|
|
||||||
|
public class Blur implements ClientModInitializer {
|
||||||
|
|
||||||
|
public static long start;
|
||||||
|
public static float progress;
|
||||||
|
|
||||||
|
public static boolean prevScreenHasBlur;
|
||||||
|
public static boolean screenHasBlur;
|
||||||
|
|
||||||
|
public static boolean prevScreenHasBackground;
|
||||||
|
public static boolean screenHasBackground;
|
||||||
|
|
||||||
|
public static boolean doTest = true;
|
||||||
|
public static boolean screenChanged = true;
|
||||||
|
public static long lastScreenChange = System.currentTimeMillis();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInitializeClient() {
|
||||||
|
BlurConfig.init("blur", BlurConfig.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean doFade = false;
|
||||||
|
|
||||||
|
public static void onScreenChange() {
|
||||||
|
if (screenHasBlur) {
|
||||||
|
if (doFade) {
|
||||||
|
start = System.currentTimeMillis();
|
||||||
|
doFade = false;
|
||||||
|
}
|
||||||
|
} else if (prevScreenHasBlur && BlurConfig.fadeOutTimeMillis > 0) {
|
||||||
|
start = System.currentTimeMillis();
|
||||||
|
doFade = true;
|
||||||
|
} else {
|
||||||
|
start = -1;
|
||||||
|
doFade = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateProgress(boolean fadeIn) {
|
||||||
|
float x;
|
||||||
|
if (fadeIn) {
|
||||||
|
x = Math.min((System.currentTimeMillis() - start) / (float) BlurConfig.fadeTimeMillis, 1);
|
||||||
|
if (BlurConfig.animationCurve.equals(BlurConfig.AnimationCurve.EASE)) x *= (2 - x); // easeInCubic
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
x = Math.max(1 + (start - System.currentTimeMillis()) / (float) BlurConfig.fadeOutTimeMillis, 0);
|
||||||
|
if (BlurConfig.animationCurve.equals(BlurConfig.AnimationCurve.EASE)) x *= (2 - x); // easeOutCubic
|
||||||
|
if (x <= 0) {
|
||||||
|
start = -1;
|
||||||
|
x = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Blur.progress = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getBackgroundColor(boolean second) {
|
||||||
|
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 = progress;
|
||||||
|
a *= prog;
|
||||||
|
r *= prog;
|
||||||
|
g *= prog;
|
||||||
|
b *= prog;
|
||||||
|
return a << 24 | r << 16 | b << 8 | g;
|
||||||
|
}
|
||||||
|
}
|
||||||
32
src/main/java/eu/midnightdust/blur/config/BlurConfig.java
Normal file
32
src/main/java/eu/midnightdust/blur/config/BlurConfig.java
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package eu.midnightdust.blur.config;
|
||||||
|
|
||||||
|
import eu.midnightdust.lib.config.MidnightConfig;
|
||||||
|
|
||||||
|
public class BlurConfig extends MidnightConfig {
|
||||||
|
public static final String ANIMATIONS = "animations";
|
||||||
|
public static final String STYLE = "style";
|
||||||
|
@Entry @Hidden public static int configVersion = 2;
|
||||||
|
|
||||||
|
@Entry(category = STYLE)
|
||||||
|
public static boolean blurContainers = true;
|
||||||
|
@Entry(category = ANIMATIONS, min = 0, max = 2000, isSlider = true)
|
||||||
|
public static int fadeTimeMillis = 200;
|
||||||
|
@Entry(category = ANIMATIONS, min = 0, max = 2000, isSlider = true)
|
||||||
|
public static int fadeOutTimeMillis = 200;
|
||||||
|
@Entry(category = ANIMATIONS)
|
||||||
|
public static AnimationCurve animationCurve = AnimationCurve.EASE;
|
||||||
|
@Entry(category = STYLE)
|
||||||
|
public static boolean useGradient = true;
|
||||||
|
@Entry(category = STYLE, isColor = true, width = 7, min = 7)
|
||||||
|
public static String gradientStart = "#000000";
|
||||||
|
@Entry(category = STYLE, isSlider = true, min = 0, max = 255)
|
||||||
|
public static int gradientStartAlpha = 75;
|
||||||
|
@Entry(category = STYLE, isColor = true, width = 7, min = 7)
|
||||||
|
public static String gradientEnd = "#000000";
|
||||||
|
@Entry(category = STYLE, isSlider = true, min = 0, max = 255)
|
||||||
|
public static int gradientEndAlpha = 75;
|
||||||
|
|
||||||
|
public enum AnimationCurve {
|
||||||
|
EASE, FLAT;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package eu.midnightdust.blur.mixin;
|
||||||
|
|
||||||
|
import eu.midnightdust.blur.Blur;
|
||||||
|
import net.minecraft.client.render.GameRenderer;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||||
|
|
||||||
|
@Mixin(GameRenderer.class)
|
||||||
|
public class MixinGameRenderer {
|
||||||
|
@ModifyVariable(method = "renderBlur", at = @At("STORE"), ordinal = 1)
|
||||||
|
private float blur$modifyRadius(float radius) { // Modify the radius based on the animation progress
|
||||||
|
|
||||||
|
if (!Blur.screenChanged && Blur.start >= 0) // Only update the progress after all tests have been completed
|
||||||
|
Blur.updateProgress(Blur.screenHasBlur);
|
||||||
|
return radius * Blur.progress;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package eu.midnightdust.blur.mixin;
|
||||||
|
|
||||||
|
import eu.midnightdust.blur.config.BlurConfig;
|
||||||
|
import net.minecraft.client.gui.DrawContext;
|
||||||
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
@Mixin(HandledScreen.class)
|
||||||
|
public class MixinHandledScreen extends Screen {
|
||||||
|
protected MixinHandledScreen(Text title) {
|
||||||
|
super(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "renderBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreen;drawBackground(Lnet/minecraft/client/gui/DrawContext;FII)V", shift = At.Shift.BEFORE))
|
||||||
|
private void blur$renderContainerBlur(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) { // Applies the blur effect in containers (Inventory, Chest, etc.)
|
||||||
|
if (BlurConfig.blurContainers) this.applyBlur(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/main/java/eu/midnightdust/blur/mixin/MixinInGameHud.java
Normal file
29
src/main/java/eu/midnightdust/blur/mixin/MixinInGameHud.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package eu.midnightdust.blur.mixin;
|
||||||
|
|
||||||
|
import eu.midnightdust.blur.Blur;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.gui.DrawContext;
|
||||||
|
import net.minecraft.client.gui.hud.InGameHud;
|
||||||
|
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;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
@Mixin(InGameHud.class)
|
||||||
|
public class MixinInGameHud {
|
||||||
|
@Final @Shadow private MinecraftClient client;
|
||||||
|
|
||||||
|
@Inject(at = @At("TAIL"), method = "render")
|
||||||
|
public void blur$renderFadeOut(DrawContext context, float delta, CallbackInfo ci) { // Adds a fade-out effect when a player is in a world and closes all screens
|
||||||
|
if (client.currentScreen == null && client.world != null && Blur.start >= 0 && Blur.prevScreenHasBlur) {
|
||||||
|
Blur.doTest = false;
|
||||||
|
Blur.screenChanged = false;
|
||||||
|
this.client.gameRenderer.renderBlur(delta);
|
||||||
|
this.client.getFramebuffer().beginWrite(false);
|
||||||
|
|
||||||
|
if (Blur.prevScreenHasBackground) context.fillGradient(0, 0, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight(), Blur.getBackgroundColor(false), Blur.getBackgroundColor(true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
37
src/main/java/eu/midnightdust/blur/mixin/MixinMinecraftClient.java
Executable file
37
src/main/java/eu/midnightdust/blur/mixin/MixinMinecraftClient.java
Executable file
@@ -0,0 +1,37 @@
|
|||||||
|
package eu.midnightdust.blur.mixin;
|
||||||
|
|
||||||
|
import eu.midnightdust.blur.Blur;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
|
||||||
|
@Mixin(MinecraftClient.class)
|
||||||
|
public class MixinMinecraftClient {
|
||||||
|
|
||||||
|
@Inject(method = "setScreen",
|
||||||
|
at = @At(value = "FIELD",
|
||||||
|
target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;",
|
||||||
|
opcode = Opcodes.PUTFIELD))
|
||||||
|
private void blur$onScreenOpen(Screen newScreen, CallbackInfo info) {
|
||||||
|
if (Blur.lastScreenChange < System.currentTimeMillis() - 100) { // For some reason, in certain scenarios the screen is set to a new one multiple times in a tick. We want to avoid that.
|
||||||
|
|
||||||
|
// Here, we reset all tests, to check if the new screen has blur and/or a background
|
||||||
|
Blur.prevScreenHasBlur = Blur.screenHasBlur;
|
||||||
|
Blur.prevScreenHasBackground = Blur.screenHasBackground;
|
||||||
|
Blur.screenHasBlur = false;
|
||||||
|
Blur.screenHasBackground = false;
|
||||||
|
Blur.doTest = true;
|
||||||
|
Blur.screenChanged = true;
|
||||||
|
Blur.start = -1;
|
||||||
|
Blur.lastScreenChange = System.currentTimeMillis();
|
||||||
|
|
||||||
|
// Manually activate the onScreenChange method when all screens are closed (in-game)
|
||||||
|
if (newScreen == null) Blur.onScreenChange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
83
src/main/java/eu/midnightdust/blur/mixin/MixinScreen.java
Executable file
83
src/main/java/eu/midnightdust/blur/mixin/MixinScreen.java
Executable file
@@ -0,0 +1,83 @@
|
|||||||
|
package eu.midnightdust.blur.mixin;
|
||||||
|
|
||||||
|
import eu.midnightdust.blur.config.BlurConfig;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.gui.DrawContext;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
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;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Constant;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.ModifyConstant;
|
||||||
|
|
||||||
|
import eu.midnightdust.blur.Blur;
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
@Mixin(Screen.class)
|
||||||
|
public abstract class MixinScreen {
|
||||||
|
|
||||||
|
@Shadow protected MinecraftClient client;
|
||||||
|
|
||||||
|
@Shadow @Final protected Text title;
|
||||||
|
|
||||||
|
@Shadow public abstract void renderInGameBackground(DrawContext context);
|
||||||
|
|
||||||
|
// @Unique
|
||||||
|
// private final Text blurConfig = Text.translatable("blur.midnightconfig.title");
|
||||||
|
|
||||||
|
// @Inject(at = @At("HEAD"), method = "tick")
|
||||||
|
// private void blur$reloadShader(CallbackInfo ci) {
|
||||||
|
// if (this.client != null && this.title.equals(blurConfig)) {
|
||||||
|
// //Blur.onScreenChange();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
@Inject(at = @At("HEAD"), method = "render")
|
||||||
|
public void blur$processScreenChange(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
|
||||||
|
if (!Blur.doTest && Blur.screenChanged) { // After the tests for blur and background color have been completed
|
||||||
|
Blur.onScreenChange();
|
||||||
|
Blur.screenChanged = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Blur.start >= 0 && !Blur.screenHasBlur && Blur.prevScreenHasBlur) { // Fade out in non-blurred screens
|
||||||
|
this.client.gameRenderer.renderBlur(delta);
|
||||||
|
this.client.getFramebuffer().beginWrite(false);
|
||||||
|
|
||||||
|
if (Blur.prevScreenHasBackground) context.fillGradient(0, 0, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight(), Blur.getBackgroundColor(false), Blur.getBackgroundColor(true));
|
||||||
|
}
|
||||||
|
Blur.doTest = false; // Set the test state to completed, as tests will happen in the same tick.
|
||||||
|
}
|
||||||
|
@Inject(at = @At("HEAD"), method = "renderInGameBackground")
|
||||||
|
public void blur$getBackgroundEnabled(DrawContext context, CallbackInfo ci) {
|
||||||
|
Blur.screenHasBackground = true; // Test if the screen has a background
|
||||||
|
}
|
||||||
|
@Inject(at = @At("HEAD"), method = "applyBlur")
|
||||||
|
public void blur$getBlurEnabled(float delta, CallbackInfo ci) {
|
||||||
|
Blur.screenHasBlur = true; // Test if the screen has blur
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(at = @At("HEAD"), method = "renderDarkening(Lnet/minecraft/client/gui/DrawContext;IIII)V", cancellable = true)
|
||||||
|
public void blur$applyGradient(DrawContext context, int x, int y, int width, int height, CallbackInfo ci) {
|
||||||
|
if (BlurConfig.useGradient) { // Replaces the background texture with a gradient
|
||||||
|
renderInGameBackground(context);
|
||||||
|
ci.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ModifyConstant(
|
||||||
|
method = "renderInGameBackground",
|
||||||
|
constant = @Constant(intValue = -1072689136))
|
||||||
|
private int blur$getFirstBackgroundColor(int color) {
|
||||||
|
return Blur.getBackgroundColor(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ModifyConstant(
|
||||||
|
method = "renderInGameBackground",
|
||||||
|
constant = @Constant(intValue = -804253680))
|
||||||
|
private int blur$getSecondBackgroundColor(int color) {
|
||||||
|
return Blur.getBackgroundColor(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,17 @@
|
|||||||
{
|
{
|
||||||
"blur.midnightconfig.title": "Blur Config",
|
"blur.midnightconfig.title": "Blur+ Config",
|
||||||
|
"blur.midnightconfig.category.animations": "Animations",
|
||||||
"blur.midnightconfig.category.style": "Style",
|
"blur.midnightconfig.category.style": "Style",
|
||||||
"blur.midnightconfig.category.screens": "Screens",
|
"blur.midnightconfig.blurContainers": "Apply Blur to Containers",
|
||||||
"blur.midnightconfig.blurExclusions": "Blur Exclusions",
|
|
||||||
"blur.midnightconfig.fadeTimeMillis": "Fade Time (in milliseconds)",
|
"blur.midnightconfig.fadeTimeMillis": "Fade Time (in milliseconds)",
|
||||||
"blur.midnightconfig.fadeOutTimeMillis": "Fade Out Time (in milliseconds)",
|
"blur.midnightconfig.fadeOutTimeMillis": "Fade Out Time (in milliseconds)",
|
||||||
"blur.midnightconfig.ease": "Ease Animation",
|
"blur.midnightconfig.animationCurve": "Animation Curve",
|
||||||
|
"blur.midnightconfig.enum.AnimationCurve.EASE": "Ease",
|
||||||
|
"blur.midnightconfig.enum.AnimationCurve.FLAT": "Flat",
|
||||||
"blur.midnightconfig.radius": "Radius",
|
"blur.midnightconfig.radius": "Radius",
|
||||||
|
"blur.midnightconfig.useGradient": "Gradient as Background",
|
||||||
"blur.midnightconfig.gradientStart": "Gradient Start Color",
|
"blur.midnightconfig.gradientStart": "Gradient Start Color",
|
||||||
"blur.midnightconfig.gradientEnd": "Gradient End Color",
|
"blur.midnightconfig.gradientEnd": "Gradient End Color",
|
||||||
"blur.midnightconfig.gradientStartAlpha": "Gradient Start Alpha",
|
"blur.midnightconfig.gradientStartAlpha": "Gradient Start Alpha",
|
||||||
"blur.midnightconfig.gradientEndAlpha": "Gradient End Alpha",
|
"blur.midnightconfig.gradientEndAlpha": "Gradient End Alpha"
|
||||||
"blur.midnightconfig.showScreenTitle": "Log screen title"
|
|
||||||
}
|
}
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
{
|
|
||||||
"targets": [
|
|
||||||
"swap"
|
|
||||||
],
|
|
||||||
"passes": [
|
|
||||||
{
|
|
||||||
"name": "blur:fade_in_blur",
|
|
||||||
"intarget": "minecraft:main",
|
|
||||||
"outtarget": "swap",
|
|
||||||
"uniforms": [
|
|
||||||
{
|
|
||||||
"name": "BlurDir",
|
|
||||||
"values": [ 1.0, 0.0 ]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Radius",
|
|
||||||
"values": [ 8.0 ]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "blur:fade_in_blur",
|
|
||||||
"intarget": "swap",
|
|
||||||
"outtarget": "minecraft:main",
|
|
||||||
"uniforms": [
|
|
||||||
{
|
|
||||||
"name": "BlurDir",
|
|
||||||
"values": [ 0.0, 1.0 ]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Radius",
|
|
||||||
"values": [ 8.0 ]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "blur:fade_in_blur",
|
|
||||||
"intarget": "minecraft:main",
|
|
||||||
"outtarget": "swap",
|
|
||||||
"uniforms": [
|
|
||||||
{
|
|
||||||
"name": "BlurDir",
|
|
||||||
"values": [ 1.0, 0.0 ]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Radius",
|
|
||||||
"values": [ 8.0 ]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "blur:fade_in_blur",
|
|
||||||
"intarget": "swap",
|
|
||||||
"outtarget": "minecraft:main",
|
|
||||||
"uniforms": [
|
|
||||||
{
|
|
||||||
"name": "BlurDir",
|
|
||||||
"values": [ 0.0, 1.0 ]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Radius",
|
|
||||||
"values": [ 8.0 ]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
#version 150
|
|
||||||
|
|
||||||
uniform sampler2D DiffuseSampler;
|
|
||||||
|
|
||||||
in vec2 texCoord;
|
|
||||||
in vec2 oneTexel;
|
|
||||||
|
|
||||||
uniform vec2 InSize;
|
|
||||||
|
|
||||||
uniform vec2 BlurDir;
|
|
||||||
uniform float Radius;
|
|
||||||
uniform float Progress;
|
|
||||||
|
|
||||||
out vec4 fragColor;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
vec4 blurred = vec4(0.0);
|
|
||||||
float totalStrength = 0.0;
|
|
||||||
float totalAlpha = 0.0;
|
|
||||||
float totalSamples = 0.0;
|
|
||||||
float progRadius = floor(Radius * Progress);
|
|
||||||
for(float r = -progRadius; r <= progRadius; r += 1.0) {
|
|
||||||
vec4 sample = texture(DiffuseSampler, texCoord + oneTexel * r * BlurDir);
|
|
||||||
|
|
||||||
// Accumulate average alpha
|
|
||||||
totalAlpha = totalAlpha + sample.a;
|
|
||||||
totalSamples = totalSamples + 1.0;
|
|
||||||
|
|
||||||
// Accumulate smoothed blur
|
|
||||||
float strength = 1.0 - abs(r / progRadius);
|
|
||||||
totalStrength = totalStrength + strength;
|
|
||||||
blurred = blurred + sample;
|
|
||||||
}
|
|
||||||
fragColor = vec4(blurred.rgb / (progRadius * 2.0 + 1.0), totalAlpha);
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
"blend": {
|
|
||||||
"func": "add",
|
|
||||||
"srcrgb": "srcalpha",
|
|
||||||
"dstrgb": "1-srcalpha"
|
|
||||||
},
|
|
||||||
"vertex": "sobel",
|
|
||||||
"fragment": "blur:fade_in_blur",
|
|
||||||
"attributes": [ "Position" ],
|
|
||||||
"samplers": [
|
|
||||||
{ "name": "DiffuseSampler" }
|
|
||||||
],
|
|
||||||
"uniforms": [
|
|
||||||
{ "name": "ProjMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
|
|
||||||
{ "name": "InSize", "type": "float", "count": 2, "values": [ 1.0, 1.0 ] },
|
|
||||||
{ "name": "OutSize", "type": "float", "count": 2, "values": [ 1.0, 1.0 ] },
|
|
||||||
{ "name": "BlurDir", "type": "float", "count": 2, "values": [ 1.0, 1.0 ] },
|
|
||||||
{ "name": "Radius", "type": "float", "count": 1, "values": [ 5.0 ] },
|
|
||||||
{ "name": "Progress", "type": "float", "count": 1, "values": [ 0.0 ] }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
{
|
{
|
||||||
"schemaVersion": 1,
|
"schemaVersion": 1,
|
||||||
"id": "blur",
|
"id": "blur",
|
||||||
"name": "Blur (Fabric)",
|
"name": "Blur+ (Fabric)",
|
||||||
"version": "$version",
|
"version": "$version",
|
||||||
"environment": "client",
|
"environment": "client",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"icon": "assets/blur/icon.png",
|
"icon": "assets/blur/icon.png",
|
||||||
"entrypoints": {
|
"entrypoints": {
|
||||||
"client": [
|
"client": [
|
||||||
"com.tterrag.blur.Blur"
|
"eu.midnightdust.blur.Blur"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"contact": {
|
"contact": {
|
||||||
@@ -17,17 +17,17 @@
|
|||||||
"issues": "https://github.com/Motschen/Blur/issues"
|
"issues": "https://github.com/Motschen/Blur/issues"
|
||||||
},
|
},
|
||||||
"authors": [
|
"authors": [
|
||||||
"tterrag1098",
|
|
||||||
"Motschen",
|
"Motschen",
|
||||||
|
"tterrag1098",
|
||||||
"Pyrofab",
|
"Pyrofab",
|
||||||
"backryun",
|
"backryun",
|
||||||
"byquanton"
|
"byquanton"
|
||||||
],
|
],
|
||||||
"description": "Modifies the background behind Minecraft GUIs to have a blur effect",
|
"description": "Various Enhancements to the blur effect behind Minecraft GUIs",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"mixins.blur.json"
|
"mixins.blur.json"
|
||||||
],
|
],
|
||||||
"depends": {
|
"depends": {
|
||||||
"satin": "*"
|
"minecraft": ">1.20.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
{
|
{
|
||||||
"required": true,
|
"required": true,
|
||||||
"minVersion": "0.8",
|
"minVersion": "0.8",
|
||||||
"package": "com.tterrag.blur.mixin",
|
"package": "eu.midnightdust.blur.mixin",
|
||||||
"compatibilityLevel": "JAVA_17",
|
"compatibilityLevel": "JAVA_17",
|
||||||
"client": [
|
"client": [
|
||||||
"MixinScreen",
|
"MixinScreen",
|
||||||
|
"MixinHandledScreen",
|
||||||
"MixinMinecraftClient",
|
"MixinMinecraftClient",
|
||||||
|
"MixinGameRenderer",
|
||||||
"MixinInGameHud"
|
"MixinInGameHud"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
|
|||||||
Reference in New Issue
Block a user