package client.renderer.entity;

import org.lwjgl.opengl.GL11;

import client.renderer.layers.LayerSlimeGel;
import client.renderer.model.ModelSlime;
import common.entity.npc.EntityNPC;
import common.entity.npc.EntitySlime;


public class RenderSlime extends RenderNpc
{
    public RenderSlime(RenderManager renderManagerIn)
    {
        super(renderManagerIn, new ModelSlime(16));
        this.addLayer(new LayerSlimeGel(this));
    }
    
    protected void preRenderCallback(EntityNPC entitylivingbaseIn, float partialTickTime)
    {
        float f = entitylivingbaseIn.getRenderScale() * 2.0f; // ? 1.0f : 2.0f;
        float f1 = 0.0f;
        if(entitylivingbaseIn instanceof EntitySlime) {
        	EntitySlime slime = (EntitySlime)entitylivingbaseIn;
        	f1 = (slime.prevSquishFactor + (slime.squishFactor - slime.prevSquishFactor) * partialTickTime) / (f * 0.5F + 1.0F);
        }
        float f2 = 1.0F / (f1 + 1.0F);
        GL11.glScalef(f2 * f, 1.0F / f2 * f, f2 * f);
    }
    
    public void doRender(EntityNPC entity, double x, double y, double z, float partialTicks)
    {
    	if(this.manager.gm == null || entity != this.manager.gm.getRenderViewEntity() || this.manager.gm.thirdPersonView != 0 || !this.manager.gm.showPlayerFirstPerson || this.manager.gm.charEditor)
    		super.doRender(entity, x, y, z, partialTicks);
    }
    
//    protected String getEntityTexture(EntityNPC entity)
//    {
//        return entity.getLocationSkin();
//    }
    
    public String getDefaultTexture()
    {
    	return "textures/npc/slime.png";
    }

//	public int getCompressedSize() {
//		return 2346;
//	}

//	public int compToImage(byte[] comp, int[] img, int stride) {
//		int pos = 0;
//		
//		pos = copyData(comp, pos, stride,  img,  8, 0,  16, 8, true);
//		pos = copyData(comp, pos, stride,  img,  0, 8,  32, 8, true);
//		pos = copyData(comp, pos, stride,  img, 6, 16,  12, 6, false);
//		pos = copyData(comp, pos, stride,  img, 0, 22,  24, 6, false);
//		pos = copyData(comp, pos, stride, img,  34,  0,  4, 2, false);
//		pos = copyData(comp, pos, stride, img,  32,  2,  8, 2, false);
//		pos = copyData(comp, pos, stride, img,  34,  4,  4, 2, false);
//		pos = copyData(comp, pos, stride, img,  32,  6,  8, 2, false);
//		pos = copyData(comp, pos, stride, img,  33,  8,  2, 1, false);
//		pos = copyData(comp, pos, stride, img,  32,  9,  4, 1, false);
//		
//		return pos;
//	}
//
//	public int imageToComp(byte[] comp, int[] img, int stride) {
//		int pos = 0;
//
//		pos = copyData(stride,  img,  8, 0,  16, 8, comp, pos, true);
//		pos = copyData(stride,  img,  0, 8,  32, 8, comp, pos, true);
//		pos = copyData(stride,  img, 6, 16,  12, 6, comp, pos, false);
//		pos = copyData(stride,  img, 0, 22,  24, 6, comp, pos, false);
//		pos = copyData(stride, img,  34,  0,  4, 2, comp, pos, false);
//		pos = copyData(stride, img,  32,  2,  8, 2, comp, pos, false);
//		pos = copyData(stride, img,  34,  4,  4, 2, comp, pos, false);
//		pos = copyData(stride, img,  32,  6,  8, 2, comp, pos, false);
//		pos = copyData(stride, img,  33,  8,  2, 1, comp, pos, false);
//		pos = copyData(stride, img,  32,  9,  4, 1, comp, pos, false);
//		
//		return pos;
//	}
	
    public void getSegments(TexList opaque, TexList alpha) {
    	alpha.add(  8,  0, 16, 8 );
    	alpha.add(  0,  8, 32, 8 );
    	opaque.add( 6, 16, 12, 6 );
    	opaque.add( 0, 22, 24, 6 );
    	opaque.add(34, 0 , 4 , 2 );
    	opaque.add(32, 2 , 8 , 2 );
    	opaque.add(34, 4 , 4 , 2 );
    	opaque.add(32, 6 , 8 , 2 );
    	opaque.add(33, 8 , 2 , 1 );
    	opaque.add(32, 9 , 4 , 1 );
    }
	
	public void getHeadUVs(CoordList list) {
		list.add(1, 1, 6, 22, 6, 6);
		list.add(1, 2, 34, 2, 2, 2);
		list.add(5, 2, 34, 6, 2, 2);
		list.add(4, 5, 33, 9, 1, 1);
		list.add(0, 0, 8, 8, 8, 8);
    }
}
