package studio.halbear.hem_custom.mixin;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ActiveRenderInfo;
import net.minecraft.client.settings.PointOfView;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.vector.Vector3f;
import net.minecraft.world.IBlockReader;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import static studio.halbear.hem_custom.vehicles.VehicleCameraSettings.GetCameraOffsets;

@Mixin(ActiveRenderInfo.class)
public abstract class CameraMixins {

    @Inject(method = "update", at = @At(value = "TAIL"),cancellable = true)
    private void update(IBlockReader currentRenderedLevel, Entity entity, boolean isDetached, boolean isMirrored, float partialTicks, CallbackInfo ci){

        if(entity.isPassenger() && Minecraft.getInstance().gameSettings.getPointOfView() != PointOfView.FIRST_PERSON && entity.getRidingEntity().getClass().getName().contains("studio.halbear.hem.entity")){
            Vector3f Position = GetCameraOffsets();
            this.movePosition(-this.calcCameraDistance(Position.getZ()), Position.getY(), Position.getX());
        }
    }
    @Shadow protected abstract void movePosition(double p_216782_1_, double p_216782_3_, double p_216782_5_);
    @Shadow protected abstract double calcCameraDistance(double p_216779_1_);
}
