Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions common/src/main/java/dev/zelo/renderscale/mixin/MixinWindow.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
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;
import org.spongepowered.asm.mixin.Unique;
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<Integer> 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<Integer> 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<Integer> 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"))
Expand Down