package com.dairymoose.entity;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Vector3f;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@OnlyIn(Dist.CLIENT)
/* loaded from: outputsrg.jar:com/dairymoose/entity/BicycleRenderer.class */
public final class BicycleRenderer extends EntityRenderer<BicycleEntity> {
    private float modelScale;
    private final BicycleModel bicycleModel;
    private static final Logger LOGGER = LogManager.getLogger();
    private static final ResourceLocation texture = new ResourceLocation("modernlife", "textures/entity/bicycle_uv.png");

    public BicycleRenderer(EntityRendererProvider.Context ctx) {
        super(ctx);
        this.modelScale = 1.0f;
        this.bicycleModel = new BicycleModel(ctx.bakeLayer(BicycleModel.BICYCLE));
    }

    public boolean shouldRender(BicycleEntity p_225626_1_, Frustum p_225626_2_, double p_225626_3_, double p_225626_5_, double p_225626_7_) {
        return true;
    }

    public void render(BicycleEntity bicycleEntity, float angle, float partialTicks, PoseStack matrixStack, MultiBufferSource buffer, int p_225623_6_) {
        Vec3 pos = bicycleEntity.position();
        if (bicycleEntity.lastRenderPos != null) {
            float t = ((float) (System.currentTimeMillis() - bicycleEntity.lastRenderTime)) / 1000.0f;
            if (t >= 0.05d) {
                pos = new Vec3(pos.x, 0.0d, pos.z);
                bicycleEntity.lastRenderPos = new Vec3(bicycleEntity.lastRenderPos.x, 0.0d, bicycleEntity.lastRenderPos.z);
                float distSqr = (float) pos.distanceToSqr(bicycleEntity.lastRenderPos);
                float dist = Mth.sqrt(distSqr);
                float calcSpeed = dist / t;
                float increment = calcSpeed / 15.0f;
                bicycleEntity.renderWheelRot = (bicycleEntity.renderWheelRot + increment) % 360.0f;
                bicycleEntity.lastRenderPos = pos;
                bicycleEntity.lastRenderTime = System.currentTimeMillis();
            }
        }
        matrixStack.pushPose();
        matrixStack.translate(0.0d, 1.5d, 0.0d);
        matrixStack.mulPose(Vector3f.YP.rotationDegrees(180.0f - angle));
        float lvt_7_1_ = bicycleEntity.getHurtTime() - partialTicks;
        float lvt_8_1_ = bicycleEntity.getDamage() - partialTicks;
        if (lvt_8_1_ < 0.0f) {
            lvt_8_1_ = 0.0f;
        }
        if (lvt_7_1_ > 0.0f) {
            matrixStack.mulPose(Vector3f.XP.rotationDegrees((((Mth.sin(lvt_7_1_) * lvt_7_1_) * lvt_8_1_) / 10.0f) * bicycleEntity.getHurtDir()));
        }
        matrixStack.scale(-this.modelScale, -this.modelScale, this.modelScale);
        this.bicycleModel.setupAnim(bicycleEntity, partialTicks, 0.0f, -0.1f, 0.0f, 0.0f);
        VertexConsumer builder = buffer.getBuffer(this.bicycleModel.m_103119_(getTextureLocation(bicycleEntity)));
        this.bicycleModel.renderToBufferWithRotation(bicycleEntity.renderWheelRot, matrixStack, builder, p_225623_6_, OverlayTexture.NO_OVERLAY, 1.0f, 1.0f, 1.0f, 1.0f);
        matrixStack.popPose();
        if (bicycleEntity.lastRenderPos == null) {
            bicycleEntity.lastRenderPos = pos;
            bicycleEntity.lastRenderTime = System.currentTimeMillis();
        }
        super.render(bicycleEntity, angle, partialTicks, matrixStack, buffer, p_225623_6_);
    }

    public ResourceLocation getTextureLocation(BicycleEntity var1) {
        return texture;
    }
}
