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