aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/dulkirfabric/mixin/render/GameRendererMixin.java
blob: 78b4dbd6358a8da568aaf96c4ee23be8c48b53b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.dulkirfabric.mixin.render;


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(value = GameRenderer.class, priority = 1001)
public class GameRendererMixin {

    @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());
    }

    @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 = "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();
    }
}