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