package net.halbear.supernova.mixin;

import net.halbear.supernova.SuperNova;
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 net.halbear.supernova.vehicle.VehicleCameraSetup.GetCameraOffsets;

@Mixin(ActiveRenderInfo.class)
public abstract class CameraMixin {
    @Inject(method = {"update", "func_216772_a"}, at = @At(value = "TAIL"),cancellable = true, remap = 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().getType().getRegistryName().getNamespace().equals(SuperNova.MOD_ID)){
            Vector3f Position = GetCameraOffsets();
            this.movePosition(-this.calcCameraDistance(Position.getZ()), Position.getY(), Position.getX());
        }
    }
    @Shadow(aliases = {"move", "func_216782_a"})
    protected abstract void movePosition(double p_216782_1_, double p_216782_3_, double p_216782_5_);
    @Shadow(aliases = {"getMaxZoom", "func_216779_a"}) protected abstract double calcCameraDistance(double p_216779_1_);
}
