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