package client.renderer.entity;

import org.lwjgl.opengl.GL11;

import client.renderer.GlState;
import client.renderer.model.ModelHead;
import common.entity.projectile.EntityBox;


public class RenderFlyingBox extends Render<EntityBox>
{
    private static final String BOX_TEX = "textures/object/box.png";
    private static final String BRITTLE_TEX = "textures/object/box_brittle.png";
    private final ModelHead boxModel = new ModelHead();

    public RenderFlyingBox(RenderManager renderManagerIn)
    {
        super(renderManagerIn);
    }

    private float func_82400_a(float p_82400_1_, float p_82400_2_, float p_82400_3_)
    {
        float f;

        for (f = p_82400_2_ - p_82400_1_; f < -180.0F; f += 360.0F)
        {
            ;
        }

        while (f >= 180.0F)
        {
            f -= 360.0F;
        }

        return p_82400_1_ + p_82400_3_ * f;
    }

    /**
     * Renders the desired {@code T} type Entity.
     */
    public void doRender(EntityBox entity, double x, double y, double z, float partialTicks)
    {
        GL11.glPushMatrix();
        GlState.disableCull();
        float f = this.func_82400_a(entity.prevYaw, entity.rotYaw, partialTicks);
        float f1 = entity.prevPitch + (entity.rotPitch - entity.prevPitch) * partialTicks;
        GL11.glTranslatef((float)x, (float)y, (float)z);
		GL11.glRotatef((float)(entity.ticksExisted % 100) * 360.0f / 100.0f, 0.3f, 0.4f, 0.1f);
        float f2 = 0.0625F;
        GlState.enableRescaleNormal();
        GL11.glScalef(-1.0F, -1.0F, 1.0F);
        GlState.enableAlpha();
        this.bindEntityTexture(entity);
        this.boxModel.render(entity, 0.0F, 0.0F, 0.0F, f, f1, f2);
        GL11.glPopMatrix();
        super.doRender(entity, x, y, z, partialTicks);
    }

    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected String getEntityTexture(EntityBox entity)
    {
        return entity.isInvulnerable() ? BOX_TEX : BRITTLE_TEX;
    }
}
