package net.minecraft.client.renderer.entity;

import net.minecraft.world.entity.Entity;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.OverlayTexture;
import com.mojang.math.Quaternion;
import net.minecraft.util.Mth;
import com.mojang.math.Vector3f;
import net.minecraft.client.renderer.MultiBufferSource;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.model.BoatModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.vehicle.Boat;

public class BoatRenderer extends EntityRenderer<Boat> {
    private static final ResourceLocation[] BOAT_TEXTURE_LOCATIONS;
    protected final BoatModel model;
    
    public BoatRenderer(final EntityRenderDispatcher egm) {
        super(egm);
        this.model = new BoatModel();
        this.shadowRadius = 0.8f;
    }
    
    @Override
    public void render(final Boat bft, final float float2, final float float3, final PoseStack dhl, final MultiBufferSource ebz, final int integer) {
        dhl.pushPose();
        dhl.translate(0.0, 0.375, 0.0);
        dhl.mulPose(Vector3f.YP.rotationDegrees(180.0f - float2));
        final float float4 = bft.getHurtTime() - float3;
        float float5 = bft.getDamage() - float3;
        if (float5 < 0.0f) {
            float5 = 0.0f;
        }
        if (float4 > 0.0f) {
            dhl.mulPose(Vector3f.XP.rotationDegrees(Mth.sin(float4) * float4 * float5 / 10.0f * bft.getHurtDir()));
        }
        final float float6 = bft.getBubbleAngle(float3);
        if (!Mth.equal(float6, 0.0f)) {
            dhl.mulPose(new Quaternion(new Vector3f(1.0f, 0.0f, 1.0f), bft.getBubbleAngle(float3), true));
        }
        dhl.scale(-1.0f, -1.0f, 1.0f);
        dhl.mulPose(Vector3f.YP.rotationDegrees(90.0f));
        this.model.setupAnim(bft, float3, 0.0f, -0.1f, 0.0f, 0.0f);
        final VertexConsumer dhp11 = ebz.getBuffer(this.model.renderType(this.getTextureLocation(bft)));
        this.model.renderToBuffer(dhl, dhp11, integer, OverlayTexture.NO_OVERLAY, 1.0f, 1.0f, 1.0f, 1.0f);
        if (!bft.isUnderWater()) {
            final VertexConsumer dhp12 = ebz.getBuffer(RenderType.waterMask());
            this.model.waterPatch().render(dhl, dhp12, integer, OverlayTexture.NO_OVERLAY);
        }
        dhl.popPose();
        super.render(bft, float2, float3, dhl, ebz, integer);
    }
    
    @Override
    public ResourceLocation getTextureLocation(final Boat bft) {
        return BoatRenderer.BOAT_TEXTURE_LOCATIONS[bft.getBoatType().ordinal()];
    }
    
    static {
        BOAT_TEXTURE_LOCATIONS = new ResourceLocation[] { new ResourceLocation("textures/entity/boat/oak.png"), new ResourceLocation("textures/entity/boat/spruce.png"), new ResourceLocation("textures/entity/boat/birch.png"), new ResourceLocation("textures/entity/boat/jungle.png"), new ResourceLocation("textures/entity/boat/acacia.png"), new ResourceLocation("textures/entity/boat/dark_oak.png") };
    }
}
