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

import net.minecraft.world.entity.Entity;
import net.minecraft.client.Minecraft;
import com.mojang.math.Vector3f;
import net.minecraft.client.model.ArmedModel;
import net.minecraft.world.item.ItemStack;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.world.entity.HumanoidArm;
import net.minecraft.client.renderer.MultiBufferSource;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.entity.RenderLayerParent;
import net.minecraft.world.entity.LivingEntity;

public class ItemInHandLayer<T extends LivingEntity, M extends EntityModel> extends RenderLayer<T, M> {
    public ItemInHandLayer(final RenderLayerParent<T, M> eid) {
        super(eid);
    }
    
    @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 boolean boolean12 = aoy.getMainArm() == HumanoidArm.RIGHT;
        final ItemStack bki13 = boolean12 ? aoy.getOffhandItem() : aoy.getMainHandItem();
        final ItemStack bki14 = boolean12 ? aoy.getMainHandItem() : aoy.getOffhandItem();
        if (bki13.isEmpty() && bki14.isEmpty()) {
            return;
        }
        dhl.pushPose();
        if (((net.minecraft.client.model.EntityModel)this.getParentModel()).young) {
            final float float11 = 0.5f;
            dhl.translate(0.0, 0.75, 0.0);
            dhl.scale(0.5f, 0.5f, 0.5f);
        }
        this.renderArmWithItem(aoy, bki14, ItemTransforms.TransformType.THIRD_PERSON_RIGHT_HAND, HumanoidArm.RIGHT, dhl, ebz, integer);
        this.renderArmWithItem(aoy, bki13, ItemTransforms.TransformType.THIRD_PERSON_LEFT_HAND, HumanoidArm.LEFT, dhl, ebz, integer);
        dhl.popPose();
    }
    
    private void renderArmWithItem(final LivingEntity aoy, final ItemStack bki, final ItemTransforms.TransformType b, final HumanoidArm aou, final PoseStack dhl, final MultiBufferSource ebz, final int integer) {
        if (bki.isEmpty()) {
            return;
        }
        dhl.pushPose();
        this.getParentModel().translateToHand(aou, dhl);
        dhl.mulPose(Vector3f.XP.rotationDegrees(-90.0f));
        dhl.mulPose(Vector3f.YP.rotationDegrees(180.0f));
        final boolean boolean9 = aou == HumanoidArm.LEFT;
        dhl.translate((boolean9 ? -1 : 1) / 16.0f, 0.125, -0.625);
        Minecraft.getInstance().getItemInHandRenderer().renderItem(aoy, bki, b, boolean9, dhl, ebz, integer);
        dhl.popPose();
    }
}
