From 156607300867bd8e900b1eac82c0bb98489514d4 Mon Sep 17 00:00:00 2001 From: OffsetMonkey538 Date: Sun, 15 Mar 2026 15:46:17 +0200 Subject: [PATCH] Use ModifyReturnValue to allow stacking of other mixins --- .../zelo/renderscale/mixin/MixinWindow.java | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/common/src/main/java/dev/zelo/renderscale/mixin/MixinWindow.java b/common/src/main/java/dev/zelo/renderscale/mixin/MixinWindow.java index c0cc9d9..f228a2b 100644 --- a/common/src/main/java/dev/zelo/renderscale/mixin/MixinWindow.java +++ b/common/src/main/java/dev/zelo/renderscale/mixin/MixinWindow.java @@ -1,5 +1,6 @@ package dev.zelo.renderscale.mixin; +import com.llamalad7.mixinextras.injector.ModifyReturnValue; import com.mojang.blaze3d.platform.Window; import dev.zelo.renderscale.CommonClass; import org.spongepowered.asm.mixin.Mixin; @@ -7,29 +8,24 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(Window.class) public abstract class MixinWindow { - @Inject(method = "getWidth", at = @At("RETURN"), cancellable = true) - private void a(CallbackInfoReturnable cir) { - var value = renderScale$scale(cir.getReturnValueI()); - cir.setReturnValue(value); + @ModifyReturnValue(method = "getWidth", at = @At("RETURN")) + private int renderScale$scaleWidth(int original) { + return renderScale$scale(original); } - @Inject(method = "getHeight", at = @At("RETURN"), cancellable = true) - private void b(CallbackInfoReturnable cir) { - var value = renderScale$scale(cir.getReturnValueI()); - cir.setReturnValue(value); + @ModifyReturnValue(method = "getHeight", at = @At("RETURN")) + private int renderScale$scaleHeight(int original) { + return renderScale$scale(original); } - @Inject(method = "getGuiScale", at = @At("RETURN"), cancellable = true) - private void c(CallbackInfoReturnable cir) { + @ModifyReturnValue(method = "getGuiScale", at = @At("RETURN")) + private int renderScale$modifyGuiScale(int original) { // It's NeoForges' fault for this null check - if (CommonClass.getInstance() != null) { - cir.setReturnValue((int) (cir.getReturnValueI() * (CommonClass.getInstance().getCurrentScaleFactor()))); - } + return CommonClass.getInstance() == null ? original : (int) (original * CommonClass.getInstance().getCurrentScaleFactor()); } @Inject(method = "onFramebufferResize", at = @At("RETURN"))