package hmggirlfront.render.mob;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

import gvclib.render.ModelBase_Non;
import hmggirlfront.entity.mob.EntitySCM_CERYNITIS;
import hmggirlfront.entity.mob.EntitySCM_CERYNITIS;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import objmodel.AdvancedModelLoader;
import objmodel.IModelCustom;

@SideOnly(Side.CLIENT)
public class RenderSCM_CERYNITIS extends RenderLiving<EntitySCM_CERYNITIS>
{
    private static final ResourceLocation boatTextures = new ResourceLocation("hmggirlfront:textures/model/mob/socom/cerynitis.png");
    private static final IModelCustom tankk = AdvancedModelLoader.loadModel(new ResourceLocation("hmggirlfront:textures/model/mob/socom/cerynitis.mqo"));
    /** instance of ModelBoat for rendering */

    public RenderSCM_CERYNITIS(RenderManager renderManagerIn)
    {
    	super(renderManagerIn, new ModelBase_Non(),0.5F);
        this.shadowSize = 0.5F;
    }

    /**
     * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
     * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
     * (Render<T extends Entity>) and this method has signature public void func_76986_a(T entity, double d, double d1,
     * double d2, float f, float f1). But JAD is pre 1.5 so doe
     */
    public float kneex = 0.4F;
   	public float kneey = 9.25F;
   	public float kneez = 0.0F;
   	
   	public float legx = 0.4F;
   	public float legy = 6.5F;
   	public float legz = -0.15F;
    public void doRender(EntitySCM_CERYNITIS entity, double x, double y, double z, float entityYaw, float partialTicks)
    {
        this.bindEntityTexture(entity);
		
		
        GL11.glPushMatrix();//glstart
		GL11.glTranslatef((float) x, (float) y, (float) z);
		GL11.glRotatef(180F, 0.0F, 1.0F, 0.0F);
		GL11.glEnable(GL12.GL_RESCALE_NORMAL);
		float f = this.interpolateRotation(entity.prevRenderYawOffset, entity.renderYawOffset, partialTicks);
		float f8 = this.handleRotationFloat(entity, partialTicks);
		this.applyRotations(entity, f8, f, partialTicks);
		
		if(entity.deathTime > 0){
			GL11.glColor4f(0.7F, 0.2F, 0.2F, 1F);
		}else {
			if(entity.hurtTime > 0) {
				GL11.glColor4f(0.7F, 0.2F, 0.2F, 1F);
			}else {
				GL11.glColor4f(1F, 1F, 1F, 1F);
			}
		}
		tankk.renderPart("waist");	
		tankk.renderPart("body");
		float limbSwing = this.F6(entity, partialTicks);
		float limbSwingAmount = this.F5(entity, partialTicks);
		this.renderlegs(entity, limbSwing, limbSwingAmount, limbSwingAmount);
			{
				GL11.glPushMatrix();//glstart
				GL11.glTranslatef(0F, 1.95F, 0F);
				GL11.glRotatef(entity.rotationPitch, 1.0F, 0.0F, 0.0F);
				GL11.glTranslatef(0F, -1.95F, -0F);
				tankk.renderPart("head");

				GL11.glPopMatrix();//glend
			}
		GL11.glRotatef(-(180.0F - entityYaw), 0.0F, 1.0F, 0.0F);
		
		GL11.glColor4f(1F, 1F, 1F, 1F);
		GL11.glDisable(GL12.GL_RESCALE_NORMAL);
		GL11.glPopMatrix();//glend
        super.doRender(entity, x, y, z, entityYaw, partialTicks);
    }
    
    
    private void renderlegs(EntitySCM_CERYNITIS entity, float limbSwing, float limbSwingAmount, float partialTicks){
    	GL11.glPushMatrix();//glstart
		this.renderleg_left(entity, limbSwing, limbSwingAmount, limbSwingAmount);
		GL11.glPopMatrix();//glend
		
		GL11.glPushMatrix();//glstart
		this.renderleg_right(entity, limbSwing, limbSwingAmount, limbSwingAmount);
		GL11.glPopMatrix();//glend
	}
    
    private void renderleg_left(EntitySCM_CERYNITIS entity, float limbSwing, float limbSwingAmount, float partialTicks){
    	float Ax = MathHelper.cos(limbSwing * 0.6662F + (float)Math.PI) * limbSwingAmount;
    	GL11.glPushMatrix();//glstart
    	tankk.renderPart("knee_l");
    	GL11.glTranslatef(kneex, kneey, kneez);
    	GL11.glRotatef(Ax * (180F / (float)Math.PI) * 1F, 1.0F, 0.0F, 0.0F);
    	GL11.glTranslatef( - kneex,  - kneey, -  kneez);
    	tankk.renderPart("leg_l");
    	GL11.glTranslatef(legx, legy, legz);
    	GL11.glRotatef(Ax * (180F / (float)Math.PI) * 1F, -1.0F, 0.0F, 0.0F);
    	GL11.glTranslatef(- legx, - legy, - legz);
    	tankk.renderPart("feet_l");
    	GL11.glPopMatrix();//glend
    }
    private void renderleg_right(EntitySCM_CERYNITIS entity, float limbSwing, float limbSwingAmount, float partialTicks){
    	float Ax = MathHelper.cos(limbSwing * 0.6662F + (float)Math.PI) * limbSwingAmount;
    	GL11.glPushMatrix();//glstart
    	tankk.renderPart("knee_r");
    	GL11.glTranslatef(- kneex, kneey, kneez);
    	GL11.glRotatef(Ax * (180F / (float)Math.PI) * 1F, -1.0F, 0.0F, 0.0F);
    	GL11.glTranslatef( kneex,  - kneey, -  kneez);
    	tankk.renderPart("leg_r");
    	GL11.glTranslatef(- legx, legy, legz);
    	GL11.glRotatef(Ax * (180F / (float)Math.PI) * 1F, 1.0F, 0.0F, 0.0F);
    	GL11.glTranslatef( legx, - legy, - legz);
    	tankk.renderPart("feet_r");
    	GL11.glPopMatrix();//glend
    }
    
    public float F6(EntityLivingBase entity, float partialTicks){
 		float f6 = 0;
 		if (!entity.isRiding())
        {
            f6 = entity.limbSwing - entity.limbSwingAmount * (1.0F - partialTicks);
            if (entity.isChild())
            {
                f6 *= 3.0F;
            }
        }
 		return f6;
 	}
 	public float F5(EntityLivingBase entity, float partialTicks){
 		float f5 = 0;
 		if (!entity.isRiding())
        {
            f5 = entity.prevLimbSwingAmount + (entity.limbSwingAmount - entity.prevLimbSwingAmount) * partialTicks;
            if (f5 > 1.0F)
            {
                f5 = 1.0F;
            }
        }
 		return f5;
 	}
    
    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected ResourceLocation getEntityTexture(EntitySCM_CERYNITIS entity)
    {
        return boatTextures;
    }
    
    protected void renderLivingAt(EntitySCM_CERYNITIS entityLivingBaseIn, double x, double y, double z)
    {
        GlStateManager.translate((float)x, (float)y, (float)z);
    }
    protected float handleRotationFloat(EntitySCM_CERYNITIS livingBase, float partialTicks)
    {
        return (float)livingBase.ticksExisted + partialTicks;
    }
}