package net.minecraft.src;

import net.lax1dude.eaglercraft.TextureLocation;
import net.lax1dude.eaglercraft.EaglerAdapter;

public class RenderSlime extends RenderLiving
{
    private static final TextureLocation slimeTextures = new TextureLocation("textures/entity/slime/slime.png");
    private ModelBase scaleAmount;

    public RenderSlime(ModelBase par1ModelBase, ModelBase par2ModelBase, float par3)
    {
        super(par1ModelBase, par3);
        this.scaleAmount = par2ModelBase;
    }

    /**
     * Determines whether Slime Render should pass or not.
     */
    protected int shouldSlimeRenderPass(EntitySlime par1EntitySlime, int par2, float par3)
    {
        if (par1EntitySlime.isInvisible())
        {
            return 0;
        }
        else if (par2 == 0)
        {
            this.setRenderPassModel(this.scaleAmount);
            EaglerAdapter.glEnable(EaglerAdapter.GL_NORMALIZE);
            EaglerAdapter.glEnable(EaglerAdapter.GL_BLEND);
            EaglerAdapter.glBlendFunc(EaglerAdapter.GL_SRC_ALPHA, EaglerAdapter.GL_ONE_MINUS_SRC_ALPHA);
            return 1;
        }
        else
        {
            if (par2 == 1)
            {
                EaglerAdapter.glDisable(EaglerAdapter.GL_BLEND);
                EaglerAdapter.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
            }

            return -1;
        }
    }

    /**
     * sets the scale for the slime based on getSlimeSize in EntitySlime
     */
    protected void scaleSlime(EntitySlime par1EntitySlime, float par2)
    {
        float var3 = (float)par1EntitySlime.getSlimeSize();
        float var4 = (par1EntitySlime.prevSquishFactor + (par1EntitySlime.squishFactor - par1EntitySlime.prevSquishFactor) * par2) / (var3 * 0.5F + 1.0F);
        float var5 = 1.0F / (var4 + 1.0F);
        EaglerAdapter.glScalef(var5 * var3, 1.0F / var5 * var3, var5 * var3);
    }

    protected TextureLocation getSlimeTextures(EntitySlime par1EntitySlime)
    {
        return slimeTextures;
    }

    /**
     * Allows the render to do any OpenGL state modifications necessary before the model is rendered. Args:
     * entityLiving, partialTickTime
     */
    protected void preRenderCallback(EntityLivingBase par1EntityLivingBase, float par2)
    {
        this.scaleSlime((EntitySlime)par1EntityLivingBase, par2);
    }

    @Override
    protected void bindTexture(EntityLivingBase par1EntityLiving) {
        slimeTextures.bindTexture();
    }

    /**
     * Queries whether should render the specified pass or not.
     */
    protected int shouldRenderPass(EntityLivingBase par1EntityLivingBase, int par2, float par3)
    {
        return this.shouldSlimeRenderPass((EntitySlime)par1EntityLivingBase, par2, par3);
    }

    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected TextureLocation getEntityTexture(Entity par1Entity)
    {
        return this.getSlimeTextures((EntitySlime)par1Entity);
    }
}
