package de.winniepat.citrus.mixins;

import de.winniepat.citrus.managers.ZoomManager;
import net.minecraft.client.Mouse;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(Mouse.class)
public class MouseMixin {
    @Inject(method = "onMouseScroll", at = @At("HEAD"), cancellable = true)
    private void onScroll(long window, double horizontal, double vertical, CallbackInfo info) {
        if (ZoomManager.isZooming()) {
            ZoomManager.changeZoom(vertical);

            info.cancel();
        }
    }

    @ModifyVariable(method = "updateMouse", at = @At("STORE"), ordinal = 2)
    private double adjustSensitivity(double value) {
        if (ZoomManager.isZooming()) {
            return value / ZoomManager.getZoomMultiplier() * 3;
        }
        return value;
    }
}
