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> dwv) {
        super(dwv);
    }
    
    @Override
    public void render(final PoseStack cyl, final MultiBufferSource dqt, final int integer, final T akz, final float float5, final float float6, final float float7, final float float8, final float float9, final float float10) {
        final boolean boolean12 = akz.getMainArm() == HumanoidArm.RIGHT;
        final ItemStack ben13 = boolean12 ? akz.getOffhandItem() : akz.getMainHandItem();
        final ItemStack ben14 = boolean12 ? akz.getMainHandItem() : akz.getOffhandItem();
        if (ben13.isEmpty() && ben14.isEmpty()) {
            return;
        }
        cyl.pushPose();
        if (((net.minecraft.client.model.EntityModel)this.getParentModel()).young) {
            final float float11 = 0.5f;
            cyl.translate(0.0, 0.75, 0.0);
            cyl.scale(0.5f, 0.5f, 0.5f);
        }
        this.renderArmWithItem(akz, ben14, ItemTransforms.TransformType.THIRD_PERSON_RIGHT_HAND, HumanoidArm.RIGHT, cyl, dqt, integer);
        this.renderArmWithItem(akz, ben13, ItemTransforms.TransformType.THIRD_PERSON_LEFT_HAND, HumanoidArm.LEFT, cyl, dqt, integer);
        cyl.popPose();
    }
    
    private void renderArmWithItem(final LivingEntity akz, final ItemStack ben, final ItemTransforms.TransformType b, final HumanoidArm aky, final PoseStack cyl, final MultiBufferSource dqt, final int integer) {
        if (ben.isEmpty()) {
            return;
        }
        cyl.pushPose();
        this.getParentModel().translateToHand(aky, cyl);
        cyl.mulPose(Vector3f.XP.rotationDegrees(-90.0f));
        cyl.mulPose(Vector3f.YP.rotationDegrees(180.0f));
        final boolean boolean9 = aky == HumanoidArm.LEFT;
        cyl.translate((boolean9 ? -1 : 1) / 16.0f, 0.125, -0.625);
        Minecraft.getInstance().getItemInHandRenderer().renderItem(akz, ben, b, boolean9, cyl, dqt, integer);
        cyl.popPose();
    }
}
