    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.util.Random;
    006    import org.lwjgl.opengl.GL11;
    007
    008    @SideOnly(Side.CLIENT)
    009    public class RenderDragon extends RenderLiving
    010    {
    011        /**
    012         * Reloads the dragon model if not equal to 4. Presumably a leftover debugging field.
    013         */
    014        private static int updateModelState = 0;
    015
    016        /** An instance of the dragon model in RenderDragon */
    017        protected ModelDragon modelDragon;
    018
    019        public RenderDragon()
    020        {
    021            super(new ModelDragon(0.0F), 0.5F);
    022            this.modelDragon = (ModelDragon)this.mainModel;
    023            this.setRenderPassModel(this.mainModel);
    024        }
    025
    026        /**
    027         * Used to rotate the dragon as a whole in RenderDragon. It's called in the rotateCorpse method.
    028         */
    029        protected void rotateDragonBody(EntityDragon par1EntityDragon, float par2, float par3, float par4)
    030        {
    031            float var5 = (float)par1EntityDragon.getMovementOffsets(7, par4)[0];
    032            float var6 = (float)(par1EntityDragon.getMovementOffsets(5, par4)[1] - par1EntityDragon.getMovementOffsets(10, par4)[1]);
    033            GL11.glRotatef(-var5, 0.0F, 1.0F, 0.0F);
    034            GL11.glRotatef(var6 * 10.0F, 1.0F, 0.0F, 0.0F);
    035            GL11.glTranslatef(0.0F, 0.0F, 1.0F);
    036
    037            if (par1EntityDragon.deathTime > 0)
    038            {
    039                float var7 = ((float)par1EntityDragon.deathTime + par4 - 1.0F) / 20.0F * 1.6F;
    040                var7 = MathHelper.sqrt_float(var7);
    041
    042                if (var7 > 1.0F)
    043                {
    044                    var7 = 1.0F;
    045                }
    046
    047                GL11.glRotatef(var7 * this.getDeathMaxRotation(par1EntityDragon), 0.0F, 0.0F, 1.0F);
    048            }
    049        }
    050
    051        /**
    052         * Renders the dragon model. Called by renderModel.
    053         */
    054        protected void renderDragonModel(EntityDragon par1EntityDragon, float par2, float par3, float par4, float par5, float par6, float par7)
    055        {
    056            if (par1EntityDragon.deathTicks > 0)
    057            {
    058                float var8 = (float)par1EntityDragon.deathTicks / 200.0F;
    059                GL11.glDepthFunc(GL11.GL_LEQUAL);
    060                GL11.glEnable(GL11.GL_ALPHA_TEST);
    061                GL11.glAlphaFunc(GL11.GL_GREATER, var8);
    062                this.loadDownloadableImageTexture(par1EntityDragon.skinUrl, "/mob/enderdragon/shuffle.png");
    063                this.mainModel.render(par1EntityDragon, par2, par3, par4, par5, par6, par7);
    064                GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
    065                GL11.glDepthFunc(GL11.GL_EQUAL);
    066            }
    067
    068            this.loadDownloadableImageTexture(par1EntityDragon.skinUrl, par1EntityDragon.getTexture());
    069            this.mainModel.render(par1EntityDragon, par2, par3, par4, par5, par6, par7);
    070
    071            if (par1EntityDragon.hurtTime > 0)
    072            {
    073                GL11.glDepthFunc(GL11.GL_EQUAL);
    074                GL11.glDisable(GL11.GL_TEXTURE_2D);
    075                GL11.glEnable(GL11.GL_BLEND);
    076                GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    077                GL11.glColor4f(1.0F, 0.0F, 0.0F, 0.5F);
    078                this.mainModel.render(par1EntityDragon, par2, par3, par4, par5, par6, par7);
    079                GL11.glEnable(GL11.GL_TEXTURE_2D);
    080                GL11.glDisable(GL11.GL_BLEND);
    081                GL11.glDepthFunc(GL11.GL_LEQUAL);
    082            }
    083        }
    084
    085        /**
    086         * Renders the dragon, along with its dying animation
    087         */
    088        public void renderDragon(EntityDragon par1EntityDragon, double par2, double par4, double par6, float par8, float par9)
    089        {
    090            BossStatus.func_82824_a(par1EntityDragon, false);
    091
    092            if (updateModelState != 4)
    093            {
    094                this.mainModel = new ModelDragon(0.0F);
    095                updateModelState = 4;
    096            }
    097
    098            super.doRenderLiving(par1EntityDragon, par2, par4, par6, par8, par9);
    099
    100            if (par1EntityDragon.healingEnderCrystal != null)
    101            {
    102                float var10 = (float)par1EntityDragon.healingEnderCrystal.innerRotation + par9;
    103                float var11 = MathHelper.sin(var10 * 0.2F) / 2.0F + 0.5F;
    104                var11 = (var11 * var11 + var11) * 0.2F;
    105                float var12 = (float)(par1EntityDragon.healingEnderCrystal.posX - par1EntityDragon.posX - (par1EntityDragon.prevPosX - par1EntityDragon.posX) * (double)(1.0F - par9));
    106                float var13 = (float)((double)var11 + par1EntityDragon.healingEnderCrystal.posY - 1.0D - par1EntityDragon.posY - (par1EntityDragon.prevPosY - par1EntityDragon.posY) * (double)(1.0F - par9));
    107                float var14 = (float)(par1EntityDragon.healingEnderCrystal.posZ - par1EntityDragon.posZ - (par1EntityDragon.prevPosZ - par1EntityDragon.posZ) * (double)(1.0F - par9));
    108                float var15 = MathHelper.sqrt_float(var12 * var12 + var14 * var14);
    109                float var16 = MathHelper.sqrt_float(var12 * var12 + var13 * var13 + var14 * var14);
    110                GL11.glPushMatrix();
    111                GL11.glTranslatef((float)par2, (float)par4 + 2.0F, (float)par6);
    112                GL11.glRotatef((float)(-Math.atan2((double)var14, (double)var12)) * 180.0F / (float)Math.PI - 90.0F, 0.0F, 1.0F, 0.0F);
    113                GL11.glRotatef((float)(-Math.atan2((double)var15, (double)var13)) * 180.0F / (float)Math.PI - 90.0F, 1.0F, 0.0F, 0.0F);
    114                Tessellator var17 = Tessellator.instance;
    115                RenderHelper.disableStandardItemLighting();
    116                GL11.glDisable(GL11.GL_CULL_FACE);
    117                this.loadTexture("/mob/enderdragon/beam.png");
    118                GL11.glShadeModel(GL11.GL_SMOOTH);
    119                float var18 = 0.0F - ((float)par1EntityDragon.ticksExisted + par9) * 0.01F;
    120                float var19 = MathHelper.sqrt_float(var12 * var12 + var13 * var13 + var14 * var14) / 32.0F - ((float)par1EntityDragon.ticksExisted + par9) * 0.01F;
    121                var17.startDrawing(5);
    122                byte var20 = 8;
    123
    124                for (int var21 = 0; var21 <= var20; ++var21)
    125                {
    126                    float var22 = MathHelper.sin((float)(var21 % var20) * (float)Math.PI * 2.0F / (float)var20) * 0.75F;
    127                    float var23 = MathHelper.cos((float)(var21 % var20) * (float)Math.PI * 2.0F / (float)var20) * 0.75F;
    128                    float var24 = (float)(var21 % var20) * 1.0F / (float)var20;
    129                    var17.setColorOpaque_I(0);
    130                    var17.addVertexWithUV((double)(var22 * 0.2F), (double)(var23 * 0.2F), 0.0D, (double)var24, (double)var19);
    131                    var17.setColorOpaque_I(16777215);
    132                    var17.addVertexWithUV((double)var22, (double)var23, (double)var16, (double)var24, (double)var18);
    133                }
    134
    135                var17.draw();
    136                GL11.glEnable(GL11.GL_CULL_FACE);
    137                GL11.glShadeModel(GL11.GL_FLAT);
    138                RenderHelper.enableStandardItemLighting();
    139                GL11.glPopMatrix();
    140            }
    141        }
    142
    143        /**
    144         * Renders the animation for when an enderdragon dies
    145         */
    146        protected void renderDragonDying(EntityDragon par1EntityDragon, float par2)
    147        {
    148            super.renderEquippedItems(par1EntityDragon, par2);
    149            Tessellator var3 = Tessellator.instance;
    150
    151            if (par1EntityDragon.deathTicks > 0)
    152            {
    153                RenderHelper.disableStandardItemLighting();
    154                float var4 = ((float)par1EntityDragon.deathTicks + par2) / 200.0F;
    155                float var5 = 0.0F;
    156
    157                if (var4 > 0.8F)
    158                {
    159                    var5 = (var4 - 0.8F) / 0.2F;
    160                }
    161
    162                Random var6 = new Random(432L);
    163                GL11.glDisable(GL11.GL_TEXTURE_2D);
    164                GL11.glShadeModel(GL11.GL_SMOOTH);
    165                GL11.glEnable(GL11.GL_BLEND);
    166                GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
    167                GL11.glDisable(GL11.GL_ALPHA_TEST);
    168                GL11.glEnable(GL11.GL_CULL_FACE);
    169                GL11.glDepthMask(false);
    170                GL11.glPushMatrix();
    171                GL11.glTranslatef(0.0F, -1.0F, -2.0F);
    172
    173                for (int var7 = 0; (float)var7 < (var4 + var4 * var4) / 2.0F * 60.0F; ++var7)
    174                {
    175                    GL11.glRotatef(var6.nextFloat() * 360.0F, 1.0F, 0.0F, 0.0F);
    176                    GL11.glRotatef(var6.nextFloat() * 360.0F, 0.0F, 1.0F, 0.0F);
    177                    GL11.glRotatef(var6.nextFloat() * 360.0F, 0.0F, 0.0F, 1.0F);
    178                    GL11.glRotatef(var6.nextFloat() * 360.0F, 1.0F, 0.0F, 0.0F);
    179                    GL11.glRotatef(var6.nextFloat() * 360.0F, 0.0F, 1.0F, 0.0F);
    180                    GL11.glRotatef(var6.nextFloat() * 360.0F + var4 * 90.0F, 0.0F, 0.0F, 1.0F);
    181                    var3.startDrawing(6);
    182                    float var8 = var6.nextFloat() * 20.0F + 5.0F + var5 * 10.0F;
    183                    float var9 = var6.nextFloat() * 2.0F + 1.0F + var5 * 2.0F;
    184                    var3.setColorRGBA_I(16777215, (int)(255.0F * (1.0F - var5)));
    185                    var3.addVertex(0.0D, 0.0D, 0.0D);
    186                    var3.setColorRGBA_I(16711935, 0);
    187                    var3.addVertex(-0.866D * (double)var9, (double)var8, (double)(-0.5F * var9));
    188                    var3.addVertex(0.866D * (double)var9, (double)var8, (double)(-0.5F * var9));
    189                    var3.addVertex(0.0D, (double)var8, (double)(1.0F * var9));
    190                    var3.addVertex(-0.866D * (double)var9, (double)var8, (double)(-0.5F * var9));
    191                    var3.draw();
    192                }
    193
    194                GL11.glPopMatrix();
    195                GL11.glDepthMask(true);
    196                GL11.glDisable(GL11.GL_CULL_FACE);
    197                GL11.glDisable(GL11.GL_BLEND);
    198                GL11.glShadeModel(GL11.GL_FLAT);
    199                GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    200                GL11.glEnable(GL11.GL_TEXTURE_2D);
    201                GL11.glEnable(GL11.GL_ALPHA_TEST);
    202                RenderHelper.enableStandardItemLighting();
    203            }
    204        }
    205
    206        /**
    207         * Renders the overlay for glowing eyes and the mouth. Called by shouldRenderPass.
    208         */
    209        protected int renderGlow(EntityDragon par1EntityDragon, int par2, float par3)
    210        {
    211            if (par2 == 1)
    212            {
    213                GL11.glDepthFunc(GL11.GL_LEQUAL);
    214            }
    215
    216            if (par2 != 0)
    217            {
    218                return -1;
    219            }
    220            else
    221            {
    222                this.loadTexture("/mob/enderdragon/ender_eyes.png");
    223                float var4 = 1.0F;
    224                GL11.glEnable(GL11.GL_BLEND);
    225                GL11.glDisable(GL11.GL_ALPHA_TEST);
    226                GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);
    227                GL11.glDisable(GL11.GL_LIGHTING);
    228                GL11.glDepthFunc(GL11.GL_EQUAL);
    229                char var5 = 61680;
    230                int var6 = var5 % 65536;
    231                int var7 = var5 / 65536;
    232                OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)var6 / 1.0F, (float)var7 / 1.0F);
    233                GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    234                GL11.glEnable(GL11.GL_LIGHTING);
    235                GL11.glColor4f(1.0F, 1.0F, 1.0F, var4);
    236                return 1;
    237            }
    238        }
    239
    240        /**
    241         * Queries whether should render the specified pass or not.
    242         */
    243        protected int shouldRenderPass(EntityLiving par1EntityLiving, int par2, float par3)
    244        {
    245            return this.renderGlow((EntityDragon)par1EntityLiving, par2, par3);
    246        }
    247
    248        protected void renderEquippedItems(EntityLiving par1EntityLiving, float par2)
    249        {
    250            this.renderDragonDying((EntityDragon)par1EntityLiving, par2);
    251        }
    252
    253        protected void rotateCorpse(EntityLiving par1EntityLiving, float par2, float par3, float par4)
    254        {
    255            this.rotateDragonBody((EntityDragon)par1EntityLiving, par2, par3, par4);
    256        }
    257
    258        /**
    259         * Renders the model in RenderLiving
    260         */
    261        protected void renderModel(EntityLiving par1EntityLiving, float par2, float par3, float par4, float par5, float par6, float par7)
    262        {
    263            this.renderDragonModel((EntityDragon)par1EntityLiving, par2, par3, par4, par5, par6, par7);
    264        }
    265
    266        public void doRenderLiving(EntityLiving par1EntityLiving, double par2, double par4, double par6, float par8, float par9)
    267        {
    268            this.renderDragon((EntityDragon)par1EntityLiving, par2, par4, par6, par8, par9);
    269        }
    270
    271        /**
    272         * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
    273         * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
    274         * (Render<T extends Entity) and this method has signature public void doRender(T entity, double d, double d1,
    275         * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
    276         */
    277        public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
    278        {
    279            this.renderDragon((EntityDragon)par1Entity, par2, par4, par6, par8, par9);
    280        }
    281    }