package client.renderer.layers;

import org.lwjgl.opengl.GL11;

import client.Client;
import client.renderer.entity.RendererLivingEntity;
import client.renderer.model.ModelBiped;
import common.entity.npc.EntityNPC;
import common.init.Items;
import common.item.Item;
import common.item.ItemStack;

public class LayerHeldItem implements LayerRenderer<EntityNPC>
{
    private final RendererLivingEntity<?> livingEntityRenderer;
    private final float xshift;
    private final float yshift;

    public LayerHeldItem(RendererLivingEntity<?> livingEntityRendererIn, float xshift, float yshift)
    {
        this.livingEntityRenderer = livingEntityRendererIn;
        this.xshift = xshift * 0.0625F; // -0.0625F
        this.yshift = yshift * 0.0625F; // 0.4375F
    }

    public void doRenderLayer(EntityNPC entitylivingbaseIn, float p_177141_2_, float p_177141_3_, float partialTicks, float p_177141_5_, float p_177141_6_, float p_177141_7_, float scale)
    {
        ItemStack itemstack = entitylivingbaseIn.getHeldItem();

        if (itemstack != null && itemstack.getItem().getWieldType() != null)
        {
            GL11.glPushMatrix();

//            if (this.livingEntityRenderer.getMainModel().isChild)
//            {
//                float f = 0.5F;
//                SKC.glTranslatef(0.0F, 0.625F, 0.0F);
//                if(this.rotate) {
//                	SKC.glRotatef(-20.0F, -1.0F, 0.0F, 0.0F);
//                }
//                SKC.glScalef(f, f, f);
//            }

            ((ModelBiped)this.livingEntityRenderer.getMainModel()).postRenderArm(0.0625F);
            GL11.glTranslatef(this.xshift, this.yshift, 0.0625F);

            if (entitylivingbaseIn.isPlayer() && ((EntityNPC)entitylivingbaseIn).fishEntity != null)
            {
                itemstack = new ItemStack(Items.fishing_rod, 0);
            }

            Item item = itemstack.getItem();
            Client gm = Client.CLIENT;

            if (entitylivingbaseIn.isSneakingVisually())
            {
                GL11.glTranslatef(0.0F, 0.203125F, 0.0F);
            }

            gm.getItemRenderer().renderItem(entitylivingbaseIn, itemstack, true);
            GL11.glPopMatrix();
        }
    }

    public boolean shouldCombineTextures()
    {
        return false;
    }
}
