    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.renderer.Tessellator;
    007import net.minecraft.entity.Entity;
    008import net.minecraft.entity.effect.EntityLightningBolt;
    009import org.lwjgl.opengl.GL11;
    010
    011@SideOnly(Side.CLIENT)
    012public class RenderLightningBolt extends Render
    013{
    014    /**
    015     * Actually renders the lightning bolt. This method is called through the doRender method.
    016     */
    017    public void doRenderLightningBolt(EntityLightningBolt par1EntityLightningBolt, double par2, double par4, double par6, float par8, float par9)
    018    {
    019        Tessellator tessellator = Tessellator.instance;
    020        GL11.glDisable(GL11.GL_TEXTURE_2D);
    021        GL11.glDisable(GL11.GL_LIGHTING);
    022        GL11.glEnable(GL11.GL_BLEND);
    023        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
    024        double[] adouble = new double[8];
    025        double[] adouble1 = new double[8];
    026        double d3 = 0.0D;
    027        double d4 = 0.0D;
    028        Random random = new Random(par1EntityLightningBolt.boltVertex);
    029
    030        for (int i = 7; i >= 0; --i)
    031        {
    032            adouble[i] = d3;
    033            adouble1[i] = d4;
    034            d3 += (double)(random.nextInt(11) - 5);
    035            d4 += (double)(random.nextInt(11) - 5);
    036        }
    037
    038        for (int j = 0; j < 4; ++j)
    039        {
    040            Random random1 = new Random(par1EntityLightningBolt.boltVertex);
    041
    042            for (int k = 0; k < 3; ++k)
    043            {
    044                int l = 7;
    045                int i1 = 0;
    046
    047                if (k > 0)
    048                {
    049                    l = 7 - k;
    050                }
    051
    052                if (k > 0)
    053                {
    054                    i1 = l - 2;
    055                }
    056
    057                double d5 = adouble[l] - d3;
    058                double d6 = adouble1[l] - d4;
    059
    060                for (int j1 = l; j1 >= i1; --j1)
    061                {
    062                    double d7 = d5;
    063                    double d8 = d6;
    064
    065                    if (k == 0)
    066                    {
    067                        d5 += (double)(random1.nextInt(11) - 5);
    068                        d6 += (double)(random1.nextInt(11) - 5);
    069                    }
    070                    else
    071                    {
    072                        d5 += (double)(random1.nextInt(31) - 15);
    073                        d6 += (double)(random1.nextInt(31) - 15);
    074                    }
    075
    076                    tessellator.startDrawing(5);
    077                    float f2 = 0.5F;
    078                    tessellator.setColorRGBA_F(0.9F * f2, 0.9F * f2, 1.0F * f2, 0.3F);
    079                    double d9 = 0.1D + (double)j * 0.2D;
    080
    081                    if (k == 0)
    082                    {
    083                        d9 *= (double)j1 * 0.1D + 1.0D;
    084                    }
    085
    086                    double d10 = 0.1D + (double)j * 0.2D;
    087
    088                    if (k == 0)
    089                    {
    090                        d10 *= (double)(j1 - 1) * 0.1D + 1.0D;
    091                    }
    092
    093                    for (int k1 = 0; k1 < 5; ++k1)
    094                    {
    095                        double d11 = par2 + 0.5D - d9;
    096                        double d12 = par6 + 0.5D - d9;
    097
    098                        if (k1 == 1 || k1 == 2)
    099                        {
    100                            d11 += d9 * 2.0D;
    101                        }
    102
    103                        if (k1 == 2 || k1 == 3)
    104                        {
    105                            d12 += d9 * 2.0D;
    106                        }
    107
    108                        double d13 = par2 + 0.5D - d10;
    109                        double d14 = par6 + 0.5D - d10;
    110
    111                        if (k1 == 1 || k1 == 2)
    112                        {
    113                            d13 += d10 * 2.0D;
    114                        }
    115
    116                        if (k1 == 2 || k1 == 3)
    117                        {
    118                            d14 += d10 * 2.0D;
    119                        }
    120
    121                        tessellator.addVertex(d13 + d5, par4 + (double)(j1 * 16), d14 + d6);
    122                        tessellator.addVertex(d11 + d7, par4 + (double)((j1 + 1) * 16), d12 + d8);
    123                    }
    124
    125                    tessellator.draw();
    126                }
    127            }
    128        }
    129
    130        GL11.glDisable(GL11.GL_BLEND);
    131        GL11.glEnable(GL11.GL_LIGHTING);
    132        GL11.glEnable(GL11.GL_TEXTURE_2D);
    133    }
    134
    135    /**
    136     * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
    137     * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
    138     * (Render<T extends Entity) and this method has signature public void doRender(T entity, double d, double d1,
    139     * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
    140     */
    141    public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
    142    {
    143        this.doRenderLightningBolt((EntityLightningBolt)par1Entity, par2, par4, par6, par8, par9);
    144    }
    145}