package client.renderer.entity;

import org.lwjgl.opengl.GL11;

import client.renderer.layers.LayerArrow;
import client.renderer.layers.LayerHeldItem;
import client.renderer.model.ModelSpaceMarine;
import common.entity.npc.EntityNPC;
import common.item.ItemAction;
import common.item.ItemStack;


public class RenderSpaceMarine extends RenderNpc
{
	public RenderSpaceMarine(RenderManager renderManager)
    {
        super(renderManager, new ModelSpaceMarine());
        this.addLayer(new LayerHeldItem(this, -2.5f, 21));
        this.addLayer(new LayerArrow(this));
    }

    public ModelSpaceMarine getMainModel()
    {
        return (ModelSpaceMarine)super.getMainModel();
    }
    
    public void doRender(EntityNPC entity, double x, double y, double z, float partialTicks)
    {
//        if (!(entity.isPlayer()SP) || this.renderManager.livingPlayer == entity)
//        {
	//    	if(entity.isBoss())
	//            BossStatus.setBossStatus(entity);
//	        double d0 = y;
//	        if(/* this.canSneak() && */ entity.isSneakingVisually() && !(entity.isPlayer()SP))
//	            d0 = y - 0.125D;
        this.setModelVisibilities(entity);
        super.doRender(entity, x, y, z, partialTicks);
//        }
    }

    protected void setModelVisibilities(EntityNPC npc)
    {
    	ModelSpaceMarine modelplayer = this.getMainModel();
        ItemStack itemstack = npc.getHeldItem();
        modelplayer.setVisible(true);
        modelplayer.bipedHead.showModel &= this.manager.gm == null || npc != this.manager.gm.getRenderViewEntity() || this.manager.gm.thirdPersonView != 0 || !this.manager.gm.showPlayerFirstPerson || this.manager.gm.charEditor;
        modelplayer.heldItemLeft = 0;
        modelplayer.aimedBow = false;
        modelplayer.isSneak = false;

        if (itemstack == null || itemstack.getItem().getWieldType() == null)
        {
            modelplayer.heldItemRight = 0;
        }
        else
        {
            modelplayer.heldItemRight = 1;

            if (npc.isUsingItem())
            {
                ItemAction enumaction = itemstack.getItemUseAction();
                enumaction = enumaction == ItemAction.NONE ? itemstack.getItem().getItemPosition() : enumaction;

                if (enumaction == ItemAction.BLOCK)
                {
                    modelplayer.heldItemRight = 3;
                }
                else if (enumaction == ItemAction.AIM)
                {
                    modelplayer.aimedBow = true;
                }
            }
            else {
                ItemAction enumaction = itemstack.getItem().getItemPosition();
                
            	if(enumaction == ItemAction.AIM) {
            		modelplayer.aimedBow = true;
            	}
            }
        }
    }
    
    protected void preRenderCallback(EntityNPC entitylivingbaseIn, float partialTickTime)
    {
        float f = entitylivingbaseIn.getRenderScale(); // 0.9375F;
        GL11.glScalef(f, f, f);
    }
    
//    public void renderPlayerArm(EntityNPC entity)
//    {
//        float f = 1.0F;
//        GlState.color(f, f, f);
//        ModelSpaceMarine modelplayer = this.getMainModel();
//        this.setModelVisibilities(entity);
//        modelplayer.swingProgress = 0.0F;
//        modelplayer.isSneak = false;
//        modelplayer.setRotationAngles(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F, entity);
//        modelplayer.renderRightArm((float)this.arms - 12.0f);
//    }
    
    public final String getDefaultTexture()
    {
    	return "textures/npc/marine.png";
    }
    
    public void getSegments(TexList opaque, TexList alpha) {
    	opaque.add(0, 0, 128, 106);
    }
	
    public void getHeadUVs(CoordList list) {
    	list.add(0, 0, 28, 11, 8, 8);
    }
}
