    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 (par1EntityCreeper.func_82150_aj())
    083                {
    084                    GL11.glDepthMask(false);
    085                }
    086                else
    087                {
    088                    GL11.glDepthMask(true);
    089                }
    090
    091                if (par2 == 1)
    092                {
    093                    float var4 = (float)par1EntityCreeper.ticksExisted + par3;
    094                    this.loadTexture("/armor/power.png");
    095                    GL11.glMatrixMode(GL11.GL_TEXTURE);
    096                    GL11.glLoadIdentity();
    097                    float var5 = var4 * 0.01F;
    098                    float var6 = var4 * 0.01F;
    099                    GL11.glTranslatef(var5, var6, 0.0F);
    100                    this.setRenderPassModel(this.creeperModel);
    101                    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    102                    GL11.glEnable(GL11.GL_BLEND);
    103                    float var7 = 0.5F;
    104                    GL11.glColor4f(var7, var7, var7, 1.0F);
    105                    GL11.glDisable(GL11.GL_LIGHTING);
    106                    GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);
    107                    return 1;
    108                }
    109
    110                if (par2 == 2)
    111                {
    112                    GL11.glMatrixMode(GL11.GL_TEXTURE);
    113                    GL11.glLoadIdentity();
    114                    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    115                    GL11.glEnable(GL11.GL_LIGHTING);
    116                    GL11.glDisable(GL11.GL_BLEND);
    117                }
    118            }
    119
    120            return -1;
    121        }
    122
    123        protected int func_77061_b(EntityCreeper par1EntityCreeper, int par2, float par3)
    124        {
    125            return -1;
    126        }
    127
    128        /**
    129         * Allows the render to do any OpenGL state modifications necessary before the model is rendered. Args:
    130         * entityLiving, partialTickTime
    131         */
    132        protected void preRenderCallback(EntityLiving par1EntityLiving, float par2)
    133        {
    134            this.updateCreeperScale((EntityCreeper)par1EntityLiving, par2);
    135        }
    136
    137        /**
    138         * Returns an ARGB int color back. Args: entityLiving, lightBrightness, partialTickTime
    139         */
    140        protected int getColorMultiplier(EntityLiving par1EntityLiving, float par2, float par3)
    141        {
    142            return this.updateCreeperColorMultiplier((EntityCreeper)par1EntityLiving, par2, par3);
    143        }
    144
    145        /**
    146         * Queries whether should render the specified pass or not.
    147         */
    148        protected int shouldRenderPass(EntityLiving par1EntityLiving, int par2, float par3)
    149        {
    150            return this.renderCreeperPassModel((EntityCreeper)par1EntityLiving, par2, par3);
    151        }
    152
    153        protected int inheritRenderPass(EntityLiving par1EntityLiving, int par2, float par3)
    154        {
    155            return this.func_77061_b((EntityCreeper)par1EntityLiving, par2, par3);
    156        }
    157    }