fix: gradient breaking various mod screens

This commit is contained in:
Martin Prokoph
2025-04-19 10:43:57 +02:00
parent d79dfc004b
commit 9d5b02bd0a
3 changed files with 31 additions and 25 deletions

View File

@@ -75,11 +75,13 @@ 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();
}
}

View File

@@ -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,10 +24,11 @@ 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(float delta);
@Inject(at = @At("HEAD"), method = "render")
public void blur$processScreenChange(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
if (!BlurInfo.doTest && BlurInfo.screenChanged) { // After the tests for blur and background color have been completed
@@ -39,10 +44,6 @@ public abstract class MixinScreen {
}
BlurInfo.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) {
BlurInfo.screenHasBackground = true; // Test if the screen has a background
}
@Inject(at = @At("HEAD"), method = "applyBlur", cancellable = true)
public void blur$getBlurEnabled(float delta, CallbackInfo ci) {
if (BlurConfig.forceDisabledScreens.contains(this.getClass().getCanonicalName())) {
@@ -51,21 +52,24 @@ public abstract class MixinScreen {
if (!BlurConfig.excludedScreens.contains(this.getClass().getCanonicalName()))
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(client.getRenderTickCounter().getTickDelta(true));
this.applyBlur(client.getRenderTickCounter().getTickDelta(true));
Blur.renderRotatedGradient(context, width, height); // Replaces the default gradient with our rotated one
ci.cancel();
}
}

View File

@@ -2,13 +2,13 @@
org.gradle.jvmargs=-Xmx2G
org.gradle.parallel=true
minecraft_version=1.21
supported_versions=1.21.1
yarn_mappings=1.21+build.2
minecraft_version=1.21.1
supported_versions=1.21
yarn_mappings=1.21.1+build.3
enabled_platforms=fabric,neoforge
# Mod Properties
mod_version=5.0.0
mod_version=5.0.0-hotfix.1
maven_group=eu.midnightdust.blur
archives_base_name=blur
release_type=release
@@ -16,12 +16,12 @@ curseforge_id=393563
modrinth_id=NK39zBp2
# Modloaders
fabric_loader_version=0.15.11
fabric_api_version=0.100.1+1.21
fabric_loader_version=0.16.13
fabric_api_version=0.115.4+1.21.1
neoforge_version=21.0.143
neoforge_version=21.1.153
yarn_mappings_patch_neoforge_version = 1.21+build.4
# Libraries
midnightlib_version = 1.6.3
midnightlib_version = 1.6.9+1.21
modmenu_version = 11.0.2