package studio.halbear.hem_custom.vehicles.Renderer;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Vector3f;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import studio.halbear.hem_custom.registry.ModStatics;
import studio.halbear.hem_custom.vehicles.Entity.Aeroplane;
import studio.halbear.hem_custom.vehicles.Entity.Airboat;
import studio.halbear.hem_custom.vehicles.Renderer.Models.AeroplaneModel;
import studio.halbear.hem_custom.vehicles.Renderer.Models.AirboatModel;

import javax.annotation.Nonnull;

@OnlyIn(Dist.CLIENT)
public class AirboatRenderer extends EntityRenderer<Airboat> {
    private AirboatModel model = new AirboatModel();

    public AirboatRenderer(EntityRendererManager renderManagerIn) {
        super(renderManagerIn );
    }

    @Override
    public void render(Airboat entity, float entityYaw, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer buffer, int packedLight) {
        matrixStack.push();

        matrixStack.rotate(Vector3f.YP.rotationDegrees(180.0F - entityYaw));
        matrixStack.scale(-1.0F, -1.0F, 1.0F);
        matrixStack.translate(0.0D, -1.5D, 0.0D);

        IVertexBuilder vertexBuilder = buffer.getBuffer(this.model.getRenderType(getEntityTexture(entity)));

        this.model.setRotationAngles(entity, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F);
        this.model.render(matrixStack, vertexBuilder, packedLight, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);

        matrixStack.pop();
        super.render(entity, entityYaw, partialTicks, matrixStack, buffer, packedLight);
    }

    @Override
    @Nonnull
    public ResourceLocation getEntityTexture(Airboat entity) {
        return new ResourceLocation(ModStatics.MOD_ID,"textures/entities/airboat.png");
    }

   /* @Override
    public boolean shouldRender(Aeroplane livingEntity, ClippingHelper camera, double camX, double camY, double camZ) {
       return true;
    }*/
}
