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

import net.minecraft.world.entity.Entity;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.renderer.entity.ParrotRenderer;
import net.minecraft.world.entity.EntityType;
import net.minecraft.client.renderer.MultiBufferSource;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.entity.RenderLayerParent;
import net.minecraft.client.model.ParrotModel;
import net.minecraft.client.model.PlayerModel;
import net.minecraft.world.entity.player.Player;

public class ParrotOnShoulderLayer<T extends Player> extends RenderLayer<T, PlayerModel<T>> {
    private final ParrotModel model;
    
    public ParrotOnShoulderLayer(final RenderLayerParent<T, PlayerModel<T>> dwv) {
        super(dwv);
        this.model = new ParrotModel();
    }
    
    @Override
    public void render(final PoseStack cyl, final MultiBufferSource dqt, final int integer, final T ayj, final float float5, final float float6, final float float7, final float float8, final float float9, final float float10) {
        this.render(cyl, dqt, integer, ayj, float5, float6, float9, float10, true);
        this.render(cyl, dqt, integer, ayj, float5, float6, float9, float10, false);
    }
    
    private void render(final PoseStack cyl, final MultiBufferSource dqt, final int integer, final T ayj, final float float5, final float float6, final float float7, final float float8, final boolean boolean9) {
        final CompoundTag jt11 = boolean9 ? ayj.getShoulderEntityLeft() : ayj.getShoulderEntityRight();
        final CompoundTag compoundTag;
        final VertexConsumer cyo13;
        EntityType.byString(jt11.getString("id")).filter(aku -> aku == EntityType.PARROT).ifPresent(aku -> {
            cyl.pushPose();
            cyl.translate(boolean9 ? 0.4000000059604645 : -0.4000000059604645, ayj.isCrouching() ? -1.2999999523162842 : -1.5, 0.0);
            cyo13 = dqt.getBuffer(this.model.renderType(ParrotRenderer.PARROT_LOCATIONS[compoundTag.getInt("Variant")]));
            this.model.renderOnShoulder(cyl, cyo13, integer, OverlayTexture.NO_OVERLAY, float5, float6, float7, float8, ayj.tickCount);
            cyl.popPose();
        });
    }
}
