aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-06-26 22:02:04 -0500
committeringlettronald <inglettronald@gmail.com>2023-06-26 22:02:04 -0500
commitb3b010d6fa09af6152c0bcb1a436718c528da24a (patch)
treef6665965a7cd0c91d108187ab099a3ad330b18b2
parentcacc7c10365c4ff9c20adde0f2bef7edd3c1cda0 (diff)
downloadDulkirMod-Fabric-b3b010d6fa09af6152c0bcb1a436718c528da24a.tar.gz
DulkirMod-Fabric-b3b010d6fa09af6152c0bcb1a436718c528da24a.tar.bz2
DulkirMod-Fabric-b3b010d6fa09af6152c0bcb1a436718c528da24a.zip
Fixed Inventory Scaling
-rw-r--r--src/main/java/com/dulkirfabric/mixin/render/GameRendererMixin.java59
-rw-r--r--src/main/java/com/dulkirfabric/mixin/render/ScreenMixin.java19
-rw-r--r--src/main/kotlin/com/dulkirfabric/commands/TestCommand.kt16
3 files changed, 71 insertions, 23 deletions
diff --git a/src/main/java/com/dulkirfabric/mixin/render/GameRendererMixin.java b/src/main/java/com/dulkirfabric/mixin/render/GameRendererMixin.java
index e8f21bb..17f527b 100644
--- a/src/main/java/com/dulkirfabric/mixin/render/GameRendererMixin.java
+++ b/src/main/java/com/dulkirfabric/mixin/render/GameRendererMixin.java
@@ -1,38 +1,57 @@
package com.dulkirfabric.mixin.render;
-import com.dulkirfabric.config.DulkirConfig;
-import net.minecraft.client.MinecraftClient;
-import net.minecraft.client.gui.screen.Screen;
-import net.minecraft.client.gui.screen.ingame.HandledScreen;
+import com.dulkirfabric.features.InventoryScale;
+import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.GameRenderer;
+import net.minecraft.client.util.Window;
+import net.minecraft.client.util.math.MatrixStack;
+import org.joml.Matrix4f;
+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.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(GameRenderer.class)
public class GameRendererMixin {
- private double normalScale = -1;
+ @ModifyArg(method = "render", at = @At(value = "INVOKE",
+ target = "Lnet/minecraft/client/gui/screen/Screen;renderWithTooltip(Lnet/minecraft/client/gui/DrawContext;IIF)V"),
+ index = 1)
+ public int fixMouseX(int mouseX) {
+ return (int) (mouseX / InventoryScale.INSTANCE.getScale());
+ }
- @Inject(method = "render", at = @At(value = "HEAD"))
- public void onRenderStart(float tickDelta, long startTime, boolean tick, CallbackInfo ci) {
- if (!DulkirConfig.ConfigVars.getConfigOptions().getInvScaleBool()) return;
- Screen screen = MinecraftClient.getInstance().currentScreen;
- if (screen instanceof HandledScreen<?>) {
- normalScale = MinecraftClient.getInstance().getWindow().getScaleFactor();
- MinecraftClient.getInstance().getWindow().setScaleFactor(DulkirConfig.ConfigVars.getConfigOptions().getInventoryScale());
- }
+ @ModifyArg(method = "render", at = @At(value = "INVOKE",
+ target = "Lnet/minecraft/client/gui/screen/Screen;renderWithTooltip(Lnet/minecraft/client/gui/DrawContext;IIF)V"),
+ index = 2)
+ public int fixMouseY(int mouseY) {
+ return (int) (mouseY / InventoryScale.INSTANCE.getScale());
}
- @Inject(method = "render", at = @At(value = "TAIL"))
- public void onRenderEnd(float tickDelta, long startTime, boolean tick, CallbackInfo ci) {
- if (!DulkirConfig.ConfigVars.getConfigOptions().getInvScaleBool()) return;
- Screen screen = MinecraftClient.getInstance().currentScreen;
- if (screen instanceof HandledScreen<?>) {
- MinecraftClient.getInstance().getWindow().setScaleFactor(normalScale);
- }
+
+ @Inject(method = "render", at = @At(value = "FIELD",
+ opcode = Opcodes.GETFIELD,
+ target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;",
+ shift = At.Shift.BEFORE,
+ ordinal = 1), locals = LocalCapture.CAPTURE_FAILHARD)
+ public void onScreenRenderPre(float tickDelta, long startTime, boolean tick, CallbackInfo ci, int i, int j,
+ Window window, Matrix4f matrix4f, MatrixStack matrixStack, DrawContext drawContext) {
+ drawContext.getMatrices().push();
+ drawContext.getMatrices().scale(InventoryScale.INSTANCE.getScale(), InventoryScale.INSTANCE.getScale(), 1f);
}
+
+ @Inject(method = "render", at = @At(value = "FIELD",
+ opcode = Opcodes.GETFIELD,
+ target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;",
+ shift = At.Shift.AFTER,
+ ordinal = 3), locals = LocalCapture.CAPTURE_FAILHARD)
+ public void onScreenRenderPost(float tickDelta, long startTime, boolean tick, CallbackInfo ci, int i, int j,
+ Window window, Matrix4f matrix4f, MatrixStack matrixStack, DrawContext drawContext) {
+ drawContext.getMatrices().pop();
+ }
} \ No newline at end of file
diff --git a/src/main/java/com/dulkirfabric/mixin/render/ScreenMixin.java b/src/main/java/com/dulkirfabric/mixin/render/ScreenMixin.java
index 3c890c7..97acba1 100644
--- a/src/main/java/com/dulkirfabric/mixin/render/ScreenMixin.java
+++ b/src/main/java/com/dulkirfabric/mixin/render/ScreenMixin.java
@@ -13,6 +13,7 @@
package com.dulkirfabric.mixin.render;
+import com.dulkirfabric.features.InventoryScale;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.Drawable;
import net.minecraft.client.gui.Element;
@@ -23,6 +24,7 @@ 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.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@@ -31,8 +33,19 @@ public abstract class ScreenMixin {
@Shadow
protected abstract <T extends Element & Drawable & Selectable> T addDrawableChild(T drawableElement);
- @Inject(method = "resize", at = @At("HEAD"))
- private void beforeResizeScreen(MinecraftClient client, int width, int height, CallbackInfo ci) {
- //todo: impl
+ @Shadow public int width;
+
+ @Shadow public int height;
+
+ @Inject(method = "init(Lnet/minecraft/client/MinecraftClient;II)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/screen/Screen;height:I", shift = At.Shift.AFTER))
+ public void onInitAfterViewportSizeSet(MinecraftClient client, int width, int height, CallbackInfo ci) {
+ this.width = (int) (width / InventoryScale.INSTANCE.getScale());
+ this.height = (int)(height / InventoryScale.INSTANCE.getScale());
+ }
+
+ @Inject(method = "resize", at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/screen/Screen;height:I", shift = At.Shift.AFTER))
+ public void onResizeAfterViewportSizeSet(MinecraftClient client, int width, int height, CallbackInfo ci) {
+ this.width = (int) (width / InventoryScale.INSTANCE.getScale());
+ this.height = (int)(height / InventoryScale.INSTANCE.getScale());
}
} \ No newline at end of file
diff --git a/src/main/kotlin/com/dulkirfabric/commands/TestCommand.kt b/src/main/kotlin/com/dulkirfabric/commands/TestCommand.kt
new file mode 100644
index 0000000..e9c30c7
--- /dev/null
+++ b/src/main/kotlin/com/dulkirfabric/commands/TestCommand.kt
@@ -0,0 +1,16 @@
+package com.dulkirfabric.commands
+
+import com.dulkirfabric.util.ScoreBoardUtils
+import com.mojang.brigadier.CommandDispatcher
+import com.mojang.brigadier.builder.LiteralArgumentBuilder
+import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
+import net.minecraft.command.CommandRegistryAccess
+
+object TestCommand {
+ fun register(dispatcher: CommandDispatcher<FabricClientCommandSource>, registryAccess: CommandRegistryAccess) {
+ dispatcher.register(LiteralArgumentBuilder.literal<FabricClientCommandSource>("linetest").executes {
+ val lines = ScoreBoardUtils.getLines()
+ return@executes 0
+ })
+ }
+} \ No newline at end of file