package net.minecraft.client.renderer.entity.layers;

import net.minecraft.world.entity.Entity;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.world.entity.player.PlayerModelPart;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.world.item.Items;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.client.renderer.MultiBufferSource;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.entity.RenderLayerParent;
import net.minecraft.client.model.ElytraModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.client.model.EntityModel;
import net.minecraft.world.entity.LivingEntity;

public class ElytraLayer<T extends LivingEntity, M extends EntityModel<T>> extends RenderLayer<T, M> {
    private static final ResourceLocation WINGS_LOCATION;
    private final ElytraModel<T> elytraModel;
    
    public ElytraLayer(final RenderLayerParent<T, M> eid) {
        super(eid);
        this.elytraModel = new ElytraModel<T>();
    }
    
    @Override
    public void render(final PoseStack dhl, final MultiBufferSource ebz, final int integer, final T aoy, final float float5, final float float6, final float float7, final float float8, final float float9, final float float10) {
        final ItemStack bki12 = aoy.getItemBySlot(EquipmentSlot.CHEST);
        if (bki12.getItem() != Items.ELYTRA) {
            return;
        }
        ResourceLocation uh13;
        if (aoy instanceof AbstractClientPlayer) {
            final AbstractClientPlayer ebc14 = (AbstractClientPlayer)aoy;
            if (ebc14.isElytraLoaded() && ebc14.getElytraTextureLocation() != null) {
                uh13 = ebc14.getElytraTextureLocation();
            }
            else if (ebc14.isCapeLoaded() && ebc14.getCloakTextureLocation() != null && ebc14.isModelPartShown(PlayerModelPart.CAPE)) {
                uh13 = ebc14.getCloakTextureLocation();
            }
            else {
                uh13 = ElytraLayer.WINGS_LOCATION;
            }
        }
        else {
            uh13 = ElytraLayer.WINGS_LOCATION;
        }
        dhl.pushPose();
        dhl.translate(0.0, 0.0, 0.125);
        this.getParentModel().copyPropertiesTo(this.elytraModel);
        this.elytraModel.setupAnim(aoy, float5, float6, float8, float9, float10);
        final VertexConsumer dhp14 = ItemRenderer.getFoilBufferDirect(ebz, this.elytraModel.renderType(uh13), false, bki12.hasFoil());
        this.elytraModel.renderToBuffer(dhl, dhp14, integer, OverlayTexture.NO_OVERLAY, 1.0f, 1.0f, 1.0f, 1.0f);
        dhl.popPose();
    }
    
    static {
        WINGS_LOCATION = new ResourceLocation("textures/entity/elytra.png");
    }
}
