    001package net.minecraft.client.renderer.entity;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import java.util.Random;
    006import net.minecraft.client.model.ModelDragon;
    007import net.minecraft.client.renderer.OpenGlHelper;
    008import net.minecraft.client.renderer.RenderHelper;
    009import net.minecraft.client.renderer.Tessellator;
    010import net.minecraft.entity.Entity;
    011import net.minecraft.entity.EntityLiving;
    012import net.minecraft.entity.boss.BossStatus;
    013import net.minecraft.entity.boss.EntityDragon;
    014import net.minecraft.util.MathHelper;
    015import org.lwjgl.opengl.GL11;
    016
    017@SideOnly(Side.CLIENT)
    018public 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 f3 = (float)par1EntityDragon.getMovementOffsets(7, par4)[0];
    041        float f4 = (float)(par1EntityDragon.getMovementOffsets(5, par4)[1] - par1EntityDragon.getMovementOffsets(10, par4)[1]);
    042        GL11.glRotatef(-f3, 0.0F, 1.0F, 0.0F);
    043        GL11.glRotatef(f4 * 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 f5 = ((float)par1EntityDragon.deathTime + par4 - 1.0F) / 20.0F * 1.6F;
    049            f5 = MathHelper.sqrt_float(f5);
    050
    051            if (f5 > 1.0F)
    052            {
    053                f5 = 1.0F;
    054            }
    055
    056            GL11.glRotatef(f5 * 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 f6 = (float)par1EntityDragon.deathTicks / 200.0F;
    068            GL11.glDepthFunc(GL11.GL_LEQUAL);
    069            GL11.glEnable(GL11.GL_ALPHA_TEST);
    070            GL11.glAlphaFunc(GL11.GL_GREATER, f6);
    071            this.loadTexture("/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.loadTexture(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 f2 = (float)par1EntityDragon.healingEnderCrystal.innerRotation + par9;
    112            float f3 = MathHelper.sin(f2 * 0.2F) / 2.0F + 0.5F;
    113            f3 = (f3 * f3 + f3) * 0.2F;
    114            float f4 = (float)(par1EntityDragon.healingEnderCrystal.posX - par1EntityDragon.posX - (par1EntityDragon.prevPosX - par1EntityDragon.posX) * (double)(1.0F - par9));
    115            float f5 = (float)((double)f3 + par1EntityDragon.healingEnderCrystal.posY - 1.0D - par1EntityDragon.posY - (par1EntityDragon.prevPosY - par1EntityDragon.posY) * (double)(1.0F - par9));
    116            float f6 = (float)(par1EntityDragon.healingEnderCrystal.posZ - par1EntityDragon.posZ - (par1EntityDragon.prevPosZ - par1EntityDragon.posZ) * (double)(1.0F - par9));
    117            float f7 = MathHelper.sqrt_float(f4 * f4 + f6 * f6);
    118            float f8 = MathHelper.sqrt_float(f4 * f4 + f5 * f5 + f6 * f6);
    119            GL11.glPushMatrix();
    120            GL11.glTranslatef((float)par2, (float)par4 + 2.0F, (float)par6);
    121            GL11.glRotatef((float)(-Math.atan2((double)f6, (double)f4)) * 180.0F / (float)Math.PI - 90.0F, 0.0F, 1.0F, 0.0F);
    122            GL11.glRotatef((float)(-Math.atan2((double)f7, (double)f5)) * 180.0F / (float)Math.PI - 90.0F, 1.0F, 0.0F, 0.0F);
    123            Tessellator tessellator = 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 f9 = 0.0F - ((float)par1EntityDragon.ticksExisted + par9) * 0.01F;
    129            float f10 = MathHelper.sqrt_float(f4 * f4 + f5 * f5 + f6 * f6) / 32.0F - ((float)par1EntityDragon.ticksExisted + par9) * 0.01F;
    130            tessellator.startDrawing(5);
    131            byte b0 = 8;
    132
    133            for (int i = 0; i <= b0; ++i)
    134            {
    135                float f11 = MathHelper.sin((float)(i % b0) * (float)Math.PI * 2.0F / (float)b0) * 0.75F;
    136                float f12 = MathHelper.cos((float)(i % b0) * (float)Math.PI * 2.0F / (float)b0) * 0.75F;
    137                float f13 = (float)(i % b0) * 1.0F / (float)b0;
    138                tessellator.setColorOpaque_I(0);
    139                tessellator.addVertexWithUV((double)(f11 * 0.2F), (double)(f12 * 0.2F), 0.0D, (double)f13, (double)f10);
    140                tessellator.setColorOpaque_I(16777215);
    141                tessellator.addVertexWithUV((double)f11, (double)f12, (double)f8, (double)f13, (double)f9);
    142            }
    143
    144            tessellator.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 tessellator = Tessellator.instance;
    159
    160        if (par1EntityDragon.deathTicks > 0)
    161        {
    162            RenderHelper.disableStandardItemLighting();
    163            float f1 = ((float)par1EntityDragon.deathTicks + par2) / 200.0F;
    164            float f2 = 0.0F;
    165
    166            if (f1 > 0.8F)
    167            {
    168                f2 = (f1 - 0.8F) / 0.2F;
    169            }
    170
    171            Random random = 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 i = 0; (float)i < (f1 + f1 * f1) / 2.0F * 60.0F; ++i)
    183            {
    184                GL11.glRotatef(random.nextFloat() * 360.0F, 1.0F, 0.0F, 0.0F);
    185                GL11.glRotatef(random.nextFloat() * 360.0F, 0.0F, 1.0F, 0.0F);
    186                GL11.glRotatef(random.nextFloat() * 360.0F, 0.0F, 0.0F, 1.0F);
    187                GL11.glRotatef(random.nextFloat() * 360.0F, 1.0F, 0.0F, 0.0F);
    188                GL11.glRotatef(random.nextFloat() * 360.0F, 0.0F, 1.0F, 0.0F);
    189                GL11.glRotatef(random.nextFloat() * 360.0F + f1 * 90.0F, 0.0F, 0.0F, 1.0F);
    190                tessellator.startDrawing(6);
    191                float f3 = random.nextFloat() * 20.0F + 5.0F + f2 * 10.0F;
    192                float f4 = random.nextFloat() * 2.0F + 1.0F + f2 * 2.0F;
    193                tessellator.setColorRGBA_I(16777215, (int)(255.0F * (1.0F - f2)));
    194                tessellator.addVertex(0.0D, 0.0D, 0.0D);
    195                tessellator.setColorRGBA_I(16711935, 0);
    196                tessellator.addVertex(-0.866D * (double)f4, (double)f3, (double)(-0.5F * f4));
    197                tessellator.addVertex(0.866D * (double)f4, (double)f3, (double)(-0.5F * f4));
    198                tessellator.addVertex(0.0D, (double)f3, (double)(1.0F * f4));
    199                tessellator.addVertex(-0.866D * (double)f4, (double)f3, (double)(-0.5F * f4));
    200                tessellator.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 f1 = 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 c0 = 61680;
    239            int j = c0 % 65536;
    240            int k = c0 / 65536;
    241            OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)j / 1.0F, (float)k / 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, f1);
    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}