package com.acethewildfire.acesbs.mixin;

import com.acethewildfire.acesbs.item.ModItems;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.item.ItemStack;
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(GameRenderer.class)
public class GameRendererMixin {

    @Inject(method = "getFov", at = @At("RETURN"), cancellable = true)
    private void modifyBowFov(Camera camera, float tickDelta, boolean changingFov, CallbackInfoReturnable<Float> cir) {
        MinecraftClient client = MinecraftClient.getInstance();

        if (client.player == null) return;

        ItemStack itemStack = client.player.getActiveItem();

        if (client.player.isUsingItem() && itemStack.isOf(ModItems.KAUPEN_BOW)) {
            float fov = cir.getReturnValue();

            int i = client.player.getItemUseTime();
            float g = (float)i / 20.0F;
            g = g > 1.0F ? 1.0F : g * g;

            fov *= 1.0F - g * 0.15F;

            cir.setReturnValue(fov);
        }
    }
}
