    001package net.minecraft.client.renderer.entity;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import net.minecraft.client.model.ModelBase;
    006import net.minecraft.client.model.ModelCreeper;
    007import net.minecraft.entity.EntityLiving;
    008import net.minecraft.entity.monster.EntityCreeper;
    009import net.minecraft.util.MathHelper;
    010import org.lwjgl.opengl.GL11;
    011
    012@SideOnly(Side.CLIENT)
    013public class RenderCreeper extends RenderLiving
    014{
    015    /** The creeper model. */
    016    private ModelBase creeperModel = new ModelCreeper(2.0F);
    017
    018    public RenderCreeper()
    019    {
    020        super(new ModelCreeper(), 0.5F);
    021    }
    022
    023    /**
    024     * Updates creeper scale in prerender callback
    025     */
    026    protected void updateCreeperScale(EntityCreeper par1EntityCreeper, float par2)
    027    {
    028        float f1 = par1EntityCreeper.getCreeperFlashIntensity(par2);
    029        float f2 = 1.0F + MathHelper.sin(f1 * 100.0F) * f1 * 0.01F;
    030
    031        if (f1 < 0.0F)
    032        {
    033            f1 = 0.0F;
    034        }
    035
    036        if (f1 > 1.0F)
    037        {
    038            f1 = 1.0F;
    039        }
    040
    041        f1 *= f1;
    042        f1 *= f1;
    043        float f3 = (1.0F + f1 * 0.4F) * f2;
    044        float f4 = (1.0F + f1 * 0.1F) / f2;
    045        GL11.glScalef(f3, f4, f3);
    046    }
    047
    048    /**
    049     * Updates color multiplier based on creeper state called by getColorMultiplier
    050     */
    051    protected int updateCreeperColorMultiplier(EntityCreeper par1EntityCreeper, float par2, float par3)
    052    {
    053        float f2 = par1EntityCreeper.getCreeperFlashIntensity(par3);
    054
    055        if ((int)(f2 * 10.0F) % 2 == 0)
    056        {
    057            return 0;
    058        }
    059        else
    060        {
    061            int i = (int)(f2 * 0.2F * 255.0F);
    062
    063            if (i < 0)
    064            {
    065                i = 0;
    066            }
    067
    068            if (i > 255)
    069            {
    070                i = 255;
    071            }
    072
    073            short short1 = 255;
    074            short short2 = 255;
    075            short short3 = 255;
    076            return i << 24 | short1 << 16 | short2 << 8 | short3;
    077        }
    078    }
    079
    080    /**
    081     * A method used to render a creeper's powered form as a pass model.
    082     */
    083    protected int renderCreeperPassModel(EntityCreeper par1EntityCreeper, int par2, float par3)
    084    {
    085        if (par1EntityCreeper.getPowered())
    086        {
    087            if (par1EntityCreeper.getHasActivePotion())
    088            {
    089                GL11.glDepthMask(false);
    090            }
    091            else
    092            {
    093                GL11.glDepthMask(true);
    094            }
    095
    096            if (par2 == 1)
    097            {
    098                float f1 = (float)par1EntityCreeper.ticksExisted + par3;
    099                this.loadTexture("/armor/power.png");
    100                GL11.glMatrixMode(GL11.GL_TEXTURE);
    101                GL11.glLoadIdentity();
    102                float f2 = f1 * 0.01F;
    103                float f3 = f1 * 0.01F;
    104                GL11.glTranslatef(f2, f3, 0.0F);
    105                this.setRenderPassModel(this.creeperModel);
    106                GL11.glMatrixMode(GL11.GL_MODELVIEW);
    107                GL11.glEnable(GL11.GL_BLEND);
    108                float f4 = 0.5F;
    109                GL11.glColor4f(f4, f4, f4, 1.0F);
    110                GL11.glDisable(GL11.GL_LIGHTING);
    111                GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);
    112                return 1;
    113            }
    114
    115            if (par2 == 2)
    116            {
    117                GL11.glMatrixMode(GL11.GL_TEXTURE);
    118                GL11.glLoadIdentity();
    119                GL11.glMatrixMode(GL11.GL_MODELVIEW);
    120                GL11.glEnable(GL11.GL_LIGHTING);
    121                GL11.glDisable(GL11.GL_BLEND);
    122            }
    123        }
    124
    125        return -1;
    126    }
    127
    128    protected int func_77061_b(EntityCreeper par1EntityCreeper, int par2, float par3)
    129    {
    130        return -1;
    131    }
    132
    133    /**
    134     * Allows the render to do any OpenGL state modifications necessary before the model is rendered. Args:
    135     * entityLiving, partialTickTime
    136     */
    137    protected void preRenderCallback(EntityLiving par1EntityLiving, float par2)
    138    {
    139        this.updateCreeperScale((EntityCreeper)par1EntityLiving, par2);
    140    }
    141
    142    /**
    143     * Returns an ARGB int color back. Args: entityLiving, lightBrightness, partialTickTime
    144     */
    145    protected int getColorMultiplier(EntityLiving par1EntityLiving, float par2, float par3)
    146    {
    147        return this.updateCreeperColorMultiplier((EntityCreeper)par1EntityLiving, par2, par3);
    148    }
    149
    150    /**
    151     * Queries whether should render the specified pass or not.
    152     */
    153    protected int shouldRenderPass(EntityLiving par1EntityLiving, int par2, float par3)
    154    {
    155        return this.renderCreeperPassModel((EntityCreeper)par1EntityLiving, par2, par3);
    156    }
    157
    158    protected int inheritRenderPass(EntityLiving par1EntityLiving, int par2, float par3)
    159    {
    160        return this.func_77061_b((EntityCreeper)par1EntityLiving, par2, par3);
    161    }
    162}