    001    package net.minecraft.client.renderer.entity;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import net.minecraft.client.model.ModelBase;
    006    import net.minecraft.client.model.ModelCreeper;
    007    import net.minecraft.entity.EntityLiving;
    008    import net.minecraft.entity.monster.EntityCreeper;
    009    import net.minecraft.util.MathHelper;
    010    import org.lwjgl.opengl.GL11;
    011
    012    @SideOnly(Side.CLIENT)
    013    public 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 var4 = par1EntityCreeper.getCreeperFlashIntensity(par2);
    029            float var5 = 1.0F + MathHelper.sin(var4 * 100.0F) * var4 * 0.01F;
    030
    031            if (var4 < 0.0F)
    032            {
    033                var4 = 0.0F;
    034            }
    035
    036            if (var4 > 1.0F)
    037            {
    038                var4 = 1.0F;
    039            }
    040
    041            var4 *= var4;
    042            var4 *= var4;
    043            float var6 = (1.0F + var4 * 0.4F) * var5;
    044            float var7 = (1.0F + var4 * 0.1F) / var5;
    045            GL11.glScalef(var6, var7, var6);
    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 var5 = par1EntityCreeper.getCreeperFlashIntensity(par3);
    054
    055            if ((int)(var5 * 10.0F) % 2 == 0)
    056            {
    057                return 0;
    058            }
    059            else
    060            {
    061                int var6 = (int)(var5 * 0.2F * 255.0F);
    062
    063                if (var6 < 0)
    064                {
    065                    var6 = 0;
    066                }
    067
    068                if (var6 > 255)
    069                {
    070                    var6 = 255;
    071                }
    072
    073                short var7 = 255;
    074                short var8 = 255;
    075                short var9 = 255;
    076                return var6 << 24 | var7 << 16 | var8 << 8 | var9;
    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 var4 = (float)par1EntityCreeper.ticksExisted + par3;
    099                    this.loadTexture("/armor/power.png");
    100                    GL11.glMatrixMode(GL11.GL_TEXTURE);
    101                    GL11.glLoadIdentity();
    102                    float var5 = var4 * 0.01F;
    103                    float var6 = var4 * 0.01F;
    104                    GL11.glTranslatef(var5, var6, 0.0F);
    105                    this.setRenderPassModel(this.creeperModel);
    106                    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    107                    GL11.glEnable(GL11.GL_BLEND);
    108                    float var7 = 0.5F;
    109                    GL11.glColor4f(var7, var7, var7, 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    }