package hmggirlfront.render.mob;

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

import gvclib.render.ModelBase_Non;
import hmggirlfront.entity.mob.EntityIBCBoss08;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
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.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
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 RenderIBCBoss08 extends RenderLiving<EntityIBCBoss08> //extends RenderLiving<EntityDoll>
{
	private static final ResourceLocation boatTextures = new ResourceLocation("hmggirlfront:textures/model/mob/ibc_boss08.png");
    private static final IModelCustom tankk = AdvancedModelLoader.loadModel(new ResourceLocation("hmggirlfront:textures/model/mob/ibc_boss08.mqo"));
    
    public RenderIBCBoss08(RenderManager renderManagerIn)
    {
    	super(renderManagerIn, new ModelBase_Non(),0.5F);
        this.shadowSize = 0.5F;
    }

    public void rendermodel(EntityIBCBoss08 entity, String model) {
    	tankk.renderPart(model);
    }
    
    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected ResourceLocation getEntityTexture(EntityIBCBoss08 entity)
    {
    	ResourceLocation dolltex = boatTextures;
		return dolltex;
    }
    
    
    
    /**
     * 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
     */
    float iii;
    public void doRender(EntityIBCBoss08 entity, double x, double y, double z, float entityYaw, float partialTicks)
    {
    	{
			//doRenderShadowAndFire(entity, x, y, z, entityYaw, partialTicks);
		}
    	float limbSwing = this.F6(entity, partialTicks);
		float limbSwingAmount = this.F5(entity, partialTicks);
    	this.bindEntityTexture(entity);
    	GL11.glPushMatrix();
		GL11.glTranslatef((float) x, (float) y, (float) z);
		GL11.glRotatef(180F, 0.0F, 1.0F, 0.0F);
		GL11.glEnable(GL12.GL_RESCALE_NORMAL);

		//GL11.glScaled(1.5, 1.5, 1.5);
		GL11.glScaled(1.0, 1.0, 1.0);
		if(entity.deathTime > 0){
			GL11.glColor4f(0.6F, 0.6F, 0.6F, 1F);
			GL11.glRotatef(180.0F - entity.renderYawOffset, 0.0F, 1.0F, 0.0F);
			if(entity.deathTime <= 20){
				float ka = (float)Math.sin((entity.deathTime %100) * 0.1) * 2F;
				GL11.glRotatef(ka, 1.0F, 0.0F, 0.0F);
				this.rendermodel(entity, "leg_l");
				this.rendermodel(entity, "leg_r");
				{
					this.rendermodel(entity, "body");
					this.rendermodel(entity, "body1");
					this.rendermodel(entity, "mantle");
					this.rendermodel(entity, "arm_l");
					this.rendermodel(entity, "arm_r");
					this.rendermodel(entity, "head");
					this.rendermodel(entity, "head1");
				}
			}
			else if(entity.deathTime > 20 && entity.deathTime <= 30){
				GL11.glRotatef((entity.deathTime - 20)*9, 1.0F, 0.0F, 0.0F);
				this.rendermodel(entity, "leg_l");
				this.rendermodel(entity, "leg_r");
				
				GL11.glTranslatef(0F, 0.75F, 0.0F);
				GL11.glRotatef(-(entity.deathTime - 20)*9, 1.0F, 0.0F, 0.0F);
				GL11.glTranslatef(0F, -0.75F, 0.0F);
				{
					this.rendermodel(entity, "body");
					this.rendermodel(entity, "body1");
					this.rendermodel(entity, "mantle");
					this.rendermodel(entity, "arm_l");
					this.rendermodel(entity, "arm_r");
					this.rendermodel(entity, "head");
					this.rendermodel(entity, "head1");
				}
			}
			else if(entity.deathTime > 30 && entity.deathTime <= 80){
				GL11.glRotatef(90, 1.0F, 0.0F, 0.0F);
				this.rendermodel(entity, "leg_l");
				this.rendermodel(entity, "leg_r");
				
				GL11.glTranslatef(0F, 0.75F, 0.0F);
				float ka = (float)Math.sin((entity.deathTime %100) * 0.1) * 5F;
				GL11.glRotatef( -90 + ka, 1.0F, 0.0F, 0.0F);
				GL11.glTranslatef(0F, -0.75F, 0.0F);
				{
					this.rendermodel(entity, "body");
					this.rendermodel(entity, "body1");
					this.rendermodel(entity, "mantle");
					this.rendermodel(entity, "arm_l");
					this.rendermodel(entity, "arm_r");
					this.rendermodel(entity, "head");
					this.rendermodel(entity, "head1");
				}
			}
			else if(entity.deathTime > 80 && entity.deathTime <= 85){
				GL11.glRotatef(90, 1.0F, 0.0F, 0.0F);
				this.rendermodel(entity, "leg_l");
				this.rendermodel(entity, "leg_r");
				
				GL11.glTranslatef(0F, 0.75F, 0.0F);
				GL11.glRotatef( -90 + (entity.deathTime - 80)*6, 1.0F, 0.0F, 0.0F);
				GL11.glTranslatef(0F, -0.75F, 0.0F);
				{
					this.rendermodel(entity, "body");
					this.rendermodel(entity, "body1");
					this.rendermodel(entity, "mantle");
					this.rendermodel(entity, "arm_l");
					this.rendermodel(entity, "arm_r");
					this.rendermodel(entity, "head");
					this.rendermodel(entity, "head1");
				}
			}
			else if(entity.deathTime > 85 && entity.deathTime <= 90){
				GL11.glRotatef(90, 1.0F, 0.0F, 0.0F);
				this.rendermodel(entity, "leg_l");
				this.rendermodel(entity, "leg_r");
				
				GL11.glTranslatef(0F, 0.75F, 0.0F);
				GL11.glRotatef( -90 + 30, 1.0F, 0.0F, 0.0F);
				GL11.glTranslatef(0F, -0.75F, 0.0F);
				{
					this.rendermodel(entity, "body");
					this.rendermodel(entity, "body1");
					this.rendermodel(entity, "mantle");
					this.rendermodel(entity, "arm_l");
					this.rendermodel(entity, "arm_r");
					GL11.glTranslatef(0F, 1.5F, 0.0F);
					GL11.glRotatef((entity.deathTime - 85)*6, 1.0F, 0.0F, 0.0F);
					GL11.glTranslatef(0F, -1.5F, 0.0F);
					this.rendermodel(entity, "head");
					this.rendermodel(entity, "head1");
				}
			}
			else {
				GL11.glRotatef(90, 1.0F, 0.0F, 0.0F);
				this.rendermodel(entity, "leg_l");
				this.rendermodel(entity, "leg_r");
				
				GL11.glTranslatef(0F, 0.75F, 0.0F);
				GL11.glRotatef( -90 + 30, 1.0F, 0.0F, 0.0F);
				GL11.glTranslatef(0F, -0.75F, 0.0F);
				{
					this.rendermodel(entity, "body");
					this.rendermodel(entity, "body1");
					this.rendermodel(entity, "mantle");
					this.rendermodel(entity, "arm_l");
					this.rendermodel(entity, "arm_r");
					GL11.glTranslatef(0F, 1.5F, 0.0F);
					GL11.glRotatef(30, 1.0F, 0.0F, 0.0F);
					GL11.glTranslatef(0F, -1.5F, 0.0F);
					this.rendermodel(entity, "head");
					this.rendermodel(entity, "head1");
				}
			}
		}else {
		if(entity.deathTime > 0){
			GL11.glColor4f(0.6F, 0.6F, 0.6F, 1F);
		}else {
			if(entity.hurtTime > 0) {
				GL11.glColor4f(0.7F, 0.2F, 0.2F, 1F);
			}else {
				GL11.glColor4f(1F, 1F, 1F, 1F);
			}
		}
		if(entity.getattacktask() && !(entity.deathTime > 0)) {
			GL11.glRotatef(180.0F - entity.rotationYawHead, 0.0F, 1.0F, 0.0F);
		}else {
			GL11.glRotatef(180.0F - entity.renderYawOffset, 0.0F, 1.0F, 0.0F);
		}
		
		if(entity.cooltime2 >= 30 && entity.cooltime2 < 50 && entity.deathTime == 0 && entity.getAIType2() == 1 && entity.targetentity != null) {
			this.bindEntityTexture(entity);
			this.rendermodel(entity, "kick");
		}else{
			if(entity.cooltime2 > 20 && entity.cooltime2 < 30 && entity.deathTime == 0 && entity.getAIType2() == 1 && entity.targetentity != null) {
				GL11.glTranslatef(0F, 1.0F, 0F);
				GL11.glRotatef(entity.cooltime * 30, 1.0F, 0.0F, 0.0F);
				GL11.glTranslatef(0F, -1.0F, 0F);
			}
			if(entity.cooltime2 > 50 && entity.cooltime2 < 60&& entity.deathTime == 0 && entity.getAIType2() == 1 && entity.targetentity != null) {
				GL11.glTranslatef(0F, 1.0F, 0F);
				GL11.glRotatef(entity.cooltime * 30, 1.0F, 0.0F, 0.0F);
				GL11.glTranslatef(0F, -1.0F, 0F);
			}
			
			
			
			
			
			
			
			
			
			{
				GL11.glPushMatrix();//glstart
				this.renderlegs(entity, limbSwing, limbSwingAmount, partialTicks);
				GL11.glPopMatrix();//glend
			}
			if(entity.isRiding()) {
				GL11.glTranslatef(0F, -0.5F, 0.0F);
			}
			{
				GL11.glPushMatrix();//glstart
				this.renderbody(entity, limbSwing, limbSwingAmount, partialTicks);
				GL11.glPopMatrix();//glend
			}
			this.bindEntityTexture(entity);
			if(entity.deathTime > 0){
				GL11.glTranslatef(0F, -0.1F, 0.25F);
				GL11.glTranslatef(0F, 1.5F, 0.0F);
				GL11.glRotatef(20, 1.0F, 0.0F, 0.0F);
				GL11.glTranslatef(0F, -1.5F, 0.0F);
			}
			if(entity.getattacktask() && !(entity.deathTime > 0)) {
				GL11.glRotatef(-(180.0F - entity.rotationYawHead), 0.0F, 1.0F, 0.0F);
			}else {
				GL11.glRotatef(-(180.0F - entity.renderYawOffset), 0.0F, 1.0F, 0.0F);
			}
			GL11.glTranslatef(0F, 1.5F, 0.0F);
			GL11.glRotatef(180.0F - entity.rotationYawHead, 0.0F, 1.0F, 0.0F);
			GL11.glRotatef(entity.rotationPitch, 1.0F, 0.0F, 0.0F);
			GL11.glTranslatef(0F, -1.5F, 0.0F);
			this.rendermodel(entity, "head");
			this.rendermodel(entity, "head1");
		}
		
		if(entity.anti_bullet_tate > 0){
			GL11.glPushMatrix();//glstart
			GL11.glEnable(GL12.GL_RESCALE_NORMAL);
			GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
			GL11.glEnable(GL11.GL_BLEND);
			
			GL11.glColor4f(1F, 1F, 1F, 0.3F);
			//Minecraft.getMinecraft().renderEngine.bindTexture(boatTextures);
			this.rendermodel(entity, "tate");
	        GL11.glDisable(GL11.GL_BLEND);
	        GL11.glColor4f(1F, 1F, 1F, 1F);
			GL11.glDisable(GL12.GL_RESCALE_NORMAL);
			GL11.glPopMatrix();//glend
		}
		
		EntityPlayer player = Minecraft.getMinecraft().player;
		}
		GL11.glColor4f(1F, 1F, 1F, 1F);
		GL11.glDisable(GL12.GL_RESCALE_NORMAL);
		GL11.glPopMatrix();
		super.doRender(entity, x, y, z, entityYaw, partialTicks);
    }
    
    private void renderlegs(EntityIBCBoss08 entity, float limbSwing, float limbSwingAmount, float partialTicks){
    	GL11.glPushMatrix();//glstart
    	{
			float Ax = MathHelper.cos(limbSwing * 0.6662F + (float)Math.PI) * limbSwingAmount;
			GL11.glTranslatef(0.15F, 0.625F, 0.0F);//GL11.glTranslatef(0.15F, 0.75F, 0.0F);
			if(entity.isRiding()) {
				GL11.glTranslatef(0F, -0.5F, 0.0F);
				GL11.glRotatef(-90, 1.0F, 0.0F, 0.0F);
				GL11.glRotatef(20, 0.0F, 0.0F, 1.0F);
			}else {
				GL11.glRotatef(Ax * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);
			}
			GL11.glTranslatef(-0.15F, -0.625F, 0.0F);
			this.rendermodel(entity, "leg_l");
		}
		GL11.glPopMatrix();//glend
		
		GL11.glPushMatrix();//glstart
		{
			float Ax =MathHelper.cos(limbSwing * 0.6662F) * limbSwingAmount;
			GL11.glTranslatef(-0.15F, 0.625F, 0.0F);
			if(entity.isRiding()) {
				GL11.glTranslatef(0F, -0.5F, 0.0F);
				GL11.glRotatef(-90, 1.0F, 0.0F, 0.0F);
				GL11.glRotatef(-20, 0.0F, 0.0F, 1.0F);
			}else {
				GL11.glRotatef(Ax * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);
			}
			GL11.glTranslatef(0.15F, -0.625F, 0.0F);
			this.rendermodel(entity, "leg_r");
		}
		GL11.glPopMatrix();//glend
	}
    
    private void renderbody(EntityIBCBoss08 entity, float limbSwing, float limbSwingAmount, float partialTicks){
    	if(entity.deathTime > 0){
    		GL11.glTranslatef(0F, 0.75F, 0.0F);
    		GL11.glRotatef(20, 1.0F, 0.0F, 0.0F);
    		GL11.glTranslatef(0F, -0.75F, 0.0F);
    	}
    	GL11.glPushMatrix();//glstart
    	this.rendermodel(entity, "body");
		this.rendermodel(entity, "body1");
		this.rendermodel(entity, "mantle");
		GL11.glPopMatrix();//glend
    	
		ItemStack main = entity.getHeldItemMainhand();
		ItemStack off = entity.getHeldItemOffhand();
		 float arm_l_rotex = 0;
	     float arm_l_rotez = 0;
	     float arm_l_rotey = 0;
	     float arm_r_rotex = 0;
	     float arm_r_rotez = 0;
	     float arm_r_rotey = 0;
    	GL11.glPushMatrix();//glstart
    	{
			float Ax = MathHelper.cos(limbSwing * 0.6662F) * limbSwingAmount;
			GL11.glTranslatef(0.35F, 1.375F, 0.0F);
			/*if(entity.getAIType2() != 1) {
				arm_l_rotex = -60 + entity.rotationPitch;
				arm_l_rotey = 20;
			}else
			if(entity.getAIType2() == 1) {
				arm_l_rotex = -60;
				arm_l_rotey = 20;
			}
			else */{
				arm_l_rotex = Ax * (180F / (float)Math.PI) * 2;
			}
			GL11.glRotatef(arm_l_rotex, 1.0F, 0.0F, 0.0F);
			GL11.glRotatef(arm_l_rotey, 0.0F, 1.0F, 0.0F);
			GL11.glRotatef(arm_l_rotez, 0.0F, 0.0F, 1.0F);
			
			GL11.glTranslatef(-0.35F, -1.375F, 0.0F);
			this.rendermodel(entity, "arm_l");

		}
		GL11.glPopMatrix();//glend
		
		GL11.glPushMatrix();//glstart
		{
			float Ax = MathHelper.cos(limbSwing * 0.6662F + (float)Math.PI) * limbSwingAmount;
			GL11.glTranslatef(-0.35F, 1.375F, 0.0F);
			//arm_r_rotex = (MathHelper.sin(partialTicks * 0.067F) * 0.05F) * (180F / (float)Math.PI);
			/*if(entity.getAIType2() != 1) {
				arm_r_rotex = -60 + entity.rotationPitch;
				arm_r_rotey = -20;
			}else
			if(entity.getAIType2() == 1) {
				arm_r_rotex = -60;
				arm_r_rotey = -20;
			}
			else */{
				arm_r_rotex = Ax * (180F / (float)Math.PI) * 2;
			}
			
			GL11.glRotatef(arm_r_rotex, 1.0F, 0.0F, 0.0F);
			GL11.glRotatef(arm_r_rotey, 0.0F, 1.0F, 0.0F);
			GL11.glRotatef(arm_r_rotez, 0.0F, 0.0F, 1.0F);
			
			GL11.glTranslatef(0.35F, -1.375F, 0.0F);
			this.rendermodel(entity, "arm_r");
			
		}
		GL11.glPopMatrix();//glend
		
		GL11.glPushMatrix();//glstart
		{
			float pitch = entity.rotationPitch;
			/*if(entity.getAIType2() == 1) {
				pitch = -30;
			}*/
			GL11.glTranslatef(0.0F, 1.6F, -0.36F);
			if(entity.gun_count1 < 4){
    			GL11.glTranslatef(0.0F, 0.0F, -0.1F);
    		}
			if(entity.getRemain_L() <= 0){
				GL11.glRotatef(-60, 1.0F, 0.0F, 0.0F);
			}else {
				GL11.glRotatef(pitch, 1.0F, 0.0F, 0.0F);
			}
			GL11.glTranslatef(-0.0F,-1.6F, 0.36F);
			this.rendermodel(entity, "gun");
		}
		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;
 	}
    
    protected void renderLivingAt(EntityIBCBoss08 entityLivingBaseIn, double x, double y, double z)
    {
        GlStateManager.translate((float)x, (float)y, (float)z);
    }
    protected float handleRotationFloat(EntityIBCBoss08 livingBase, float partialTicks)
    {
        return (float)livingBase.ticksExisted + partialTicks;
    }
}