mirror of
https://github.com/Motschen/Blur.git
synced 2025-12-13 02:15:09 +01:00
Compare commits
4 Commits
695fa67270
...
fa6fd82e4d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa6fd82e4d | ||
|
|
528958fa8c | ||
|
|
552f1e619e | ||
|
|
c9c630ac11 |
@@ -23,20 +23,19 @@ public class Blur {
|
||||
|
||||
public static boolean doFade = false;
|
||||
|
||||
static float lastDelta;
|
||||
public static void onRender(DrawContext context, int width, int height, MinecraftClient client, float delta) {
|
||||
public static void onRender() {
|
||||
if (!BlurInfo.doTest && BlurInfo.screenChanged) { // After the tests for blur and background color have been completed
|
||||
Blur.onScreenChange();
|
||||
BlurInfo.screenChanged = false;
|
||||
}
|
||||
|
||||
BlurInfo.doTest = false; // Set the test state to completed, as tests will happen in the same tick.
|
||||
}
|
||||
public static void renderFadeout(DrawContext context, int width, int height, MinecraftClient client) {
|
||||
if (BlurInfo.start >= 0 && !BlurInfo.screenHasBlur && BlurInfo.prevScreenHasBlur) { // Fade out in non-blurred screens
|
||||
client.gameRenderer.renderBlur();
|
||||
|
||||
if (BlurInfo.prevScreenHasBackground && BlurConfig.useGradient && lastDelta != delta) Blur.renderRotatedGradient(context, width, height);
|
||||
lastDelta = delta;
|
||||
if (BlurInfo.prevScreenHasBackground && BlurConfig.useGradient) Blur.renderRotatedGradient(context, width, height);
|
||||
}
|
||||
BlurInfo.doTest = false; // Set the test state to completed, as tests will happen in the same tick.
|
||||
}
|
||||
|
||||
public static void onScreenChange() {
|
||||
@@ -79,7 +78,10 @@ public class Blur {
|
||||
int b = (col.getRGB() >> 8) & 0xFF;
|
||||
int g = col.getRGB() & 0xFF;
|
||||
float prog = progress;
|
||||
a *= prog; r *= prog; g *= prog; b *= prog;
|
||||
a = (int) (prog * a);
|
||||
r = (int) (prog * r);
|
||||
g = (int) (prog * g);
|
||||
b = (int) (prog * b);
|
||||
return a << 24 | r << 16 | b << 8 | g;
|
||||
}
|
||||
public static int getRotation() {
|
||||
@@ -90,11 +92,12 @@ public class Blur {
|
||||
float diagonal = Math.sqrt((float) width*width + height*height);
|
||||
int smallestDimension = Math.min(width, height);
|
||||
|
||||
context.getMatrices().push();
|
||||
Matrix4f posMatrix = context.getMatrices().peek().getPositionMatrix();
|
||||
posMatrix.rotationZ(Math.toRadians(getRotation()));
|
||||
posMatrix.setTranslation(width / 2f, height / 2f, 0); // Make the gradient's center the pivot point
|
||||
posMatrix.setTranslation(width / 2f, height / 2f, -1000); // Make the gradient's center the pivot point
|
||||
posMatrix.scale(diagonal / smallestDimension); // Scales the gradient to the maximum diagonal value needed
|
||||
context.fillGradient(-width / 2, -height / 2, width / 2, height / 2, Blur.getBackgroundColor(false), Blur.getBackgroundColor(true)); // Actually draw the gradient
|
||||
posMatrix.rotationZ(0);
|
||||
context.getMatrices().pop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ public class BlurConfig extends MidnightConfig {
|
||||
public static final String SCREENS = "screens";
|
||||
@Entry @Hidden public static int configVersion = 2;
|
||||
|
||||
@Comment(category = SCREENS, centered = true)
|
||||
public static Comment _general;
|
||||
@Entry(category = SCREENS)
|
||||
public static boolean blurContainers = true;
|
||||
@Entry(category = SCREENS)
|
||||
@@ -22,14 +24,21 @@ public class BlurConfig extends MidnightConfig {
|
||||
@Condition(requiredOption = "blurTitleScreen", visibleButLocked = true)
|
||||
@Entry(category = SCREENS)
|
||||
public static boolean darkenTitleScreen = false;
|
||||
@Entry(category = ANIMATIONS, min = 0, max = 2000, isSlider = true)
|
||||
public static int fadeTimeMillis = 300;
|
||||
@Entry(category = ANIMATIONS, min = 0, max = 2000, isSlider = true)
|
||||
public static int fadeOutTimeMillis = 300;
|
||||
@Entry(category = ANIMATIONS)
|
||||
public static BlurConfig.Easing animationCurve = Easing.FLAT;
|
||||
@Comment(category = SCREENS, centered = true)
|
||||
public static Comment _advanced;
|
||||
@Entry(category = SCREENS) // Screens where Blur+ should not apply transition effects (mostly dynamically blurred screens)
|
||||
public static List<String> excludedScreens = Lists.newArrayList("net.irisshaders.iris.gui.screen.ShaderPackScreen");
|
||||
@Entry(category = SCREENS) // Screens where the vanilla blur effect should be force enabled
|
||||
public static List<String> forceEnabledScreens = Lists.newArrayList("dev.emi.emi.screen.RecipeScreen");
|
||||
@Entry(category = SCREENS) // Screens where the vanilla blur effect should be force disabled
|
||||
public static List<String> forceDisabledScreens = Lists.newArrayList();
|
||||
|
||||
@Comment(category = STYLE, centered = true)
|
||||
public static Comment _blur;
|
||||
@Entry(category = STYLE, isSlider = true, min = 0, max = 20)
|
||||
public static int radius = 5;
|
||||
@Comment(category = STYLE, centered = true)
|
||||
public static Comment _gradient;
|
||||
@Entry(category = STYLE)
|
||||
public static boolean useGradient = true;
|
||||
@Condition(requiredOption = "useGradient", visibleButLocked = true)
|
||||
@@ -49,12 +58,15 @@ public class BlurConfig extends MidnightConfig {
|
||||
public static int gradientRotation = 0;
|
||||
@Entry(category = STYLE)
|
||||
public static boolean rainbowMode = false;
|
||||
@Entry(category = SCREENS) // Screens where Blur+ should not apply transition effects (mostly dynamically blurred screens)
|
||||
public static List<String> excludedScreens = Lists.newArrayList("net.irisshaders.iris.gui.screen.ShaderPackScreen");
|
||||
@Entry(category = SCREENS) // Screens where the vanilla blur effect should be force enabled
|
||||
public static List<String> forceEnabledScreens = Lists.newArrayList("dev.emi.emi.screen.RecipeScreen");
|
||||
@Entry(category = SCREENS) // Screens where the vanilla blur effect should be force disabled
|
||||
public static List<String> forceDisabledScreens = Lists.newArrayList();
|
||||
|
||||
@Comment(category = ANIMATIONS, centered = true)
|
||||
public static Comment _animations;
|
||||
@Entry(category = ANIMATIONS, min = 0, max = 2000, isSlider = true)
|
||||
public static int fadeTimeMillis = 300;
|
||||
@Entry(category = ANIMATIONS, min = 0, max = 2000, isSlider = true)
|
||||
public static int fadeOutTimeMillis = 300;
|
||||
@Entry(category = ANIMATIONS)
|
||||
public static BlurConfig.Easing animationCurve = Easing.FLAT;
|
||||
|
||||
@Override
|
||||
public void writeChanges(String modid) {
|
||||
|
||||
@@ -24,6 +24,6 @@ public class MixinHandledScreen extends Screen {
|
||||
}
|
||||
@Inject(at = @At("HEAD"), method = "render")
|
||||
public void blur$processScreenChange(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
|
||||
if (PlatformFunctions.getPlatformName().equals("neoforge")) Blur.onRender(context, width, height, this.client, delta);
|
||||
if (PlatformFunctions.getPlatformName().equals("neoforge")) Blur.onRender();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
package eu.midnightdust.blur.mixin;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import eu.midnightdust.blur.BlurInfo;
|
||||
import eu.midnightdust.blur.config.BlurConfig;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
|
||||
@@ -20,18 +24,16 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
public abstract class MixinScreen {
|
||||
@Shadow @Final protected Text title;
|
||||
@Shadow protected MinecraftClient client;
|
||||
@Shadow public abstract void renderInGameBackground(DrawContext context);
|
||||
@Shadow public int width;
|
||||
@Shadow public int height;
|
||||
@Shadow protected abstract void applyBlur();
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "render")
|
||||
public void blur$processScreenChange(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
|
||||
Blur.onRender(context, width, height, this.client, delta);
|
||||
}
|
||||
@Inject(at = @At("HEAD"), method = "renderInGameBackground")
|
||||
public void blur$getBackgroundEnabled(DrawContext context, CallbackInfo ci) {
|
||||
BlurInfo.screenHasBackground = true; // Test if the screen has a background
|
||||
Blur.onRender();
|
||||
Blur.renderFadeout(context, width, height, client);
|
||||
}
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "applyBlur", cancellable = true)
|
||||
public void blur$getBlurEnabled(CallbackInfo ci) {
|
||||
if (BlurConfig.forceDisabledScreens.contains(this.getClass().getCanonicalName())) {
|
||||
@@ -41,20 +43,23 @@ public abstract class MixinScreen {
|
||||
BlurInfo.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();
|
||||
}
|
||||
@WrapOperation(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;renderBackgroundTexture(Lnet/minecraft/client/gui/DrawContext;Lnet/minecraft/util/Identifier;IIFFII)V"), method = "renderDarkening(Lnet/minecraft/client/gui/DrawContext;IIII)V")
|
||||
private void blur$applyGradient(DrawContext context, Identifier texture, int x, int y, float u, float v, int width, int height, Operation<Void> original) {
|
||||
if (BlurConfig.useGradient) {
|
||||
blur$renderGradient(context); // Replaces the background texture with a gradient
|
||||
} else original.call(context, texture, x, y, u, v, width, height);
|
||||
}
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "renderInGameBackground", cancellable = true)
|
||||
public void blur$rotatedGradient(DrawContext context, CallbackInfo ci) {
|
||||
@WrapOperation(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;fillGradient(IIIIII)V"), method = "renderInGameBackground")
|
||||
public void blur$rotatedGradient(DrawContext context, int startX, int startY, int endX, int endY, int colorStart, int colorEnd, Operation<Void> original) {
|
||||
blur$renderGradient(context);
|
||||
}
|
||||
@Unique
|
||||
private void blur$renderGradient(DrawContext context) {
|
||||
BlurInfo.screenHasBackground = true; // Test if the screen has a background
|
||||
if (BlurConfig.forceEnabledScreens.contains(this.getClass().getCanonicalName()))
|
||||
((ScreenAccessor)this).forceApplyBlur();
|
||||
this.applyBlur();
|
||||
|
||||
Blur.renderRotatedGradient(context, width, height); // Replaces the default gradient with our rotated one
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"blur.midnightconfig.title": "Blur+ Konfiguration",
|
||||
"blur.midnightconfig.category.animations": "Animationen",
|
||||
"blur.midnightconfig.category.screens": "Bildschirme",
|
||||
"blur.midnightconfig.category.style": "Stil",
|
||||
"blur.midnightconfig.blurContainers": "Unschärfe in Containern",
|
||||
"blur.midnightconfig.blurTitleScreen": "Unschärfe im Titelbildschirm",
|
||||
@@ -26,5 +27,10 @@
|
||||
"blur.midnightconfig.gradientStartAlpha": "Farbverlauf-Anfangstransparenz",
|
||||
"blur.midnightconfig.gradientEndAlpha": "Farbverlauf-Endstransparenz",
|
||||
"blur.midnightconfig.gradientRotation": "Farbverlauf-Rotation",
|
||||
"blur.midnightconfig.excludedScreens": "Ausgeschlossene Bildschirme"
|
||||
"blur.midnightconfig.excludedScreens": "Ausgeschlossene Bildschirme",
|
||||
"blur.midnightconfig._general": "§7⛏ Generell",
|
||||
"blur.midnightconfig._advanced": "§7⚒ Fortgeschritten",
|
||||
"blur.midnightconfig._blur": "§7▒ Unschärfe",
|
||||
"blur.midnightconfig._gradient": "§7\uD83D\uDFE2 Farbverlauf",
|
||||
"blur.midnightconfig._animations": "§7\uD83D\uDCFD Animationen"
|
||||
}
|
||||
@@ -33,5 +33,10 @@
|
||||
"blur.midnightconfig.forceEnabledScreens": "Force-enabled Screens",
|
||||
"blur.midnightconfig.forceEnabledScreens.tooltip": "Screens where the vanilla blur effect should be force-enabled\nMight not work 100% of the time",
|
||||
"blur.midnightconfig.forceDisabledScreens": "Force-disabled Screens",
|
||||
"blur.midnightconfig.forceDisabledScreens.tooltip": "Screens where the vanilla blur effect should be force-disabled"
|
||||
"blur.midnightconfig.forceDisabledScreens.tooltip": "Screens where the vanilla blur effect should be force-disabled",
|
||||
"blur.midnightconfig._general": "§7⛏ General",
|
||||
"blur.midnightconfig._advanced": "§7⚒ Advanced",
|
||||
"blur.midnightconfig._blur": "§7▒ Blur",
|
||||
"blur.midnightconfig._gradient": "§7\uD83D\uDFE2 Gradient",
|
||||
"blur.midnightconfig._animations": "§7\uD83D\uDCFD Animations"
|
||||
}
|
||||
Reference in New Issue
Block a user