package hmggirlfront.render.mob;

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

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

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

    public RenderIBCJUPITER(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
     */
    float iii;
    public void doRender(EntityIBCJUPITER 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);
		
		tankk.renderPart("mat1");
		
		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);
			}
		}
	//	GL11.glRotatef(180.0F - entityYaw, 0.0F, 1.0F, 0.0F);
		//get_world_rotation(entity);
		//tankk.renderPart("mat1");
		
		GL11.glRotatef(-(180.0F - entityYaw), 0.0F, 1.0F, 0.0F);
		if(entity.getGene(entity)){
			
			GL11.glPushMatrix();//glstart
			GL11.glTranslatef(0F, 3.9F, 0F);
			GL11.glRotatef(180.0F - entity.rotationYawHead, 0.0F, 1.0F, 0.0F);
			GL11.glTranslatef(0F, -3.9F, 0F);
			
			GL11.glTranslatef(0F, 3.9F, 0F);
			GL11.glRotatef(entity.rotationPitch, 1.0F, 0.0F, 0.0F);
			GL11.glTranslatef(0F, -3.9F, 0F);
			tankk.renderPart("mat4");
			tankk.renderPart("mat6_1");
			if(entity.cooltime > 20 && entity.cooltime < 80 && entity.getattacktask()) {
				GL11.glTranslatef(0F, 4.95F , 9.75F);
				float size = partialTicks * 0.4F + 1.0F;
            	GlStateManager.scale(size, size, size);
				GL11.glTranslatef(0.0F, -4.95F , -9.75F);
				int i = 15728880;
		        int j = i % 65536;
		        int k = i / 65536;
		        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)j, (float)k);
				tankk.renderPart("beam_c");
			}
			GL11.glPopMatrix();//glend
		}else {
			{
				GL11.glPushMatrix();//glstart
				GL11.glTranslatef(0F, 3.9F, 0F);
				GL11.glRotatef(-30, 1.0F, 0.0F, 0.0F);
				GL11.glTranslatef(0F, -3.9F, 0F);
				tankk.renderPart("mat4");
				tankk.renderPart("mat6_2");
				GL11.glPopMatrix();//glend
			}
			{
				GL11.glPushMatrix();//glstart
				tankk.renderPart("mat7");
				
				GL11.glTranslatef(0F, 1.0F, 4.4F);
				GL11.glRotatef(180.0F - entity.rotationYawHead, 0.0F, 1.0F, 0.0F);
				GL11.glTranslatef(0F, -1.0F, -4.4F);
				
				GL11.glTranslatef(0F, 1.0F, 4.4F);
				GL11.glRotatef(entity.rotationPitch, 1.0F, 0.0F, 0.0F);
				GL11.glTranslatef(0F, -1.0F, -4.4F);
				tankk.renderPart("mat8");
				{
					int i = 15728880;
			        int j = i % 65536;
			        int k = i / 65536;
			        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)j, (float)k);
	    			tankk.renderPart("mat8_lt");
				}
				GL11.glPopMatrix();//glend
			}
		}
		GL11.glColor4f(1F, 1F, 1F, 1F);
		GL11.glDisable(GL12.GL_RESCALE_NORMAL);
		GL11.glPopMatrix();//glend
		super.doRender(entity, x, y, z, entityYaw, partialTicks);
	}
    
    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected ResourceLocation getEntityTexture(EntityIBCJUPITER entity)
    {
        return boatTextures;
    }
    
    protected void renderLivingAt(EntityIBCJUPITER entityLivingBaseIn, double x, double y, double z)
    {
        GlStateManager.translate((float)x, (float)y, (float)z);
    }
    protected float handleRotationFloat(EntityIBCJUPITER livingBase, float partialTicks)
    {
        return (float)livingBase.ticksExisted + partialTicks;
    }
}