All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.peanuuutz.fork.ui.mixin.MixinMouse Maven / Gradle / Ivy

The newest version!
package net.peanuuutz.fork.ui.mixin;

import net.minecraft.class_310;
import net.minecraft.class_312;
import net.peanuuutz.fork.ui.internal.MouseHacker;
import net.peanuuutz.fork.ui.scene.screen.ScreenPointerService;
import net.peanuuutz.fork.util.common.CompactHelperKt;
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;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(class_312.class)
public class MixinMouse implements MouseHacker {
    @Unique
    private long forkui$position;

    @Unique
    private long forkui$offset;

    @Shadow private double x;

    @Shadow private double y;

    @Shadow private int activeButton;

    @Shadow @Final private class_310 client;

    @Override
    public long forkui$getPosition() {
        return forkui$position;
    }

    @Override
    public long forkui$getOffset() {
        return forkui$offset;
    }

    @Override
    public int forkui$getMouseButton() {
        return activeButton;
    }

    @Inject(method = "onCursorPos", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;wrapScreenError(Ljava/lang/Runnable;Ljava/lang/String;Ljava/lang/String;)V", ordinal = 0))
    private void forkui$setPositions(long window, double x, double y, CallbackInfo ci) {
        double scaleFactor = client.method_22683().method_4495();
        float scaledX = (float) (x / scaleFactor);
        float scaledY = (float) (y / scaleFactor);
        forkui$position = CompactHelperKt.pack2Floats(scaledX, scaledY);
        ScreenPointerService.INSTANCE.setPosition(scaledX, scaledY);
        float scaledDeltaX = (float) ((x - this.x) / scaleFactor);
        float scaledDeltaY = (float) ((y - this.y) / scaleFactor);
        forkui$offset = CompactHelperKt.pack2Floats(scaledDeltaX, scaledDeltaY);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy