package net.moonleay.gimble.mixin;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.Camera;
import net.moonleay.gimble.client.editor.ClientEditor;
import net.moonleay.gimble.editor.state.mode.Capability;
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.callback.CallbackInfoReturnable;

@Mixin(Camera.class)
public class NoClipCameraFixMixin {

    @Inject(method = "clipToSpace", at = @At("HEAD"), cancellable = true)
    private void fixCameraInNoClip(double desiredCameraDistance, CallbackInfoReturnable<Double> cir) {
        if (!ClientEditor.INSTANCE.shouldClient(Capability.NO_CLIP) || (!(MinecraftClient.getInstance().player != null && MinecraftClient.getInstance().player.isCreative()))) {
            return;
        }
        cir.setReturnValue(desiredCameraDistance);
        cir.cancel();
    }
}
