    001    package net.minecraft.client.particle;
    002
    003    import cpw.mods.fml.relauncher.Side;
    004    import cpw.mods.fml.relauncher.SideOnly;
    005    import net.minecraft.client.Minecraft;
    006    import net.minecraft.client.renderer.Tessellator;
    007    import net.minecraft.nbt.NBTTagCompound;
    008    import net.minecraft.nbt.NBTTagList;
    009    import net.minecraft.util.MathHelper;
    010    import net.minecraft.world.World;
    011
    012    @SideOnly(Side.CLIENT)
    013    public class EntityFireworkStarterFX extends EntityFX
    014    {
    015        private int field_92042_ax = 0;
    016        private final EffectRenderer field_92040_ay;
    017        private NBTTagList field_92039_az;
    018        boolean field_92041_a;
    019
    020        public EntityFireworkStarterFX(World par1World, double par2, double par4, double par6, double par8, double par10, double par12, EffectRenderer par14EffectRenderer, NBTTagCompound par15NBTTagCompound)
    021        {
    022            super(par1World, par2, par4, par6, 0.0D, 0.0D, 0.0D);
    023            this.motionX = par8;
    024            this.motionY = par10;
    025            this.motionZ = par12;
    026            this.field_92040_ay = par14EffectRenderer;
    027            this.particleMaxAge = 8;
    028
    029            if (par15NBTTagCompound != null)
    030            {
    031                this.field_92039_az = par15NBTTagCompound.getTagList("Explosions");
    032
    033                if (this.field_92039_az != null && this.field_92039_az.tagCount() == 0)
    034                {
    035                    this.field_92039_az = null;
    036                }
    037                else if (this.field_92039_az != null)
    038                {
    039                    this.particleMaxAge = this.field_92039_az.tagCount() * 2 - 1;
    040
    041                    for (int var16 = 0; var16 < this.field_92039_az.tagCount(); ++var16)
    042                    {
    043                        NBTTagCompound var17 = (NBTTagCompound)this.field_92039_az.tagAt(var16);
    044
    045                        if (var17.getBoolean("Flicker"))
    046                        {
    047                            this.field_92041_a = true;
    048                            this.particleMaxAge += 15;
    049                            break;
    050                        }
    051                    }
    052                }
    053            }
    054        }
    055
    056        public void renderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7) {}
    057
    058        /**
    059         * Called to update the entity's position/logic.
    060         */
    061        public void onUpdate()
    062        {
    063            boolean var1;
    064
    065            if (this.field_92042_ax == 0 && this.field_92039_az != null)
    066            {
    067                var1 = this.func_92037_i();
    068                boolean var2 = false;
    069
    070                if (this.field_92039_az.tagCount() >= 3)
    071                {
    072                    var2 = true;
    073                }
    074                else
    075                {
    076                    for (int var3 = 0; var3 < this.field_92039_az.tagCount(); ++var3)
    077                    {
    078                        NBTTagCompound var4 = (NBTTagCompound)this.field_92039_az.tagAt(var3);
    079
    080                        if (var4.getByte("Type") == 1)
    081                        {
    082                            var2 = true;
    083                            break;
    084                        }
    085                    }
    086                }
    087
    088                String var15 = "fireworks." + (var2 ? "largeBlast" : "blast") + (var1 ? "_far" : "");
    089                this.worldObj.playSound(this.posX, this.posY, this.posZ, var15, 20.0F, 0.95F + this.rand.nextFloat() * 0.1F, true);
    090            }
    091
    092            if (this.field_92042_ax % 2 == 0 && this.field_92039_az != null && this.field_92042_ax / 2 < this.field_92039_az.tagCount())
    093            {
    094                int var13 = this.field_92042_ax / 2;
    095                NBTTagCompound var14 = (NBTTagCompound)this.field_92039_az.tagAt(var13);
    096                byte var17 = var14.getByte("Type");
    097                boolean var18 = var14.getBoolean("Trail");
    098                boolean var5 = var14.getBoolean("Flicker");
    099                int[] var6 = var14.getIntArray("Colors");
    100                int[] var7 = var14.getIntArray("FadeColors");
    101
    102                if (var17 == 1)
    103                {
    104                    this.func_92035_a(0.5D, 4, var6, var7, var18, var5);
    105                }
    106                else if (var17 == 2)
    107                {
    108                    this.func_92038_a(0.5D, new double[][] {{0.0D, 1.0D}, {0.3455D, 0.309D}, {0.9511D, 0.309D}, {0.3795918367346939D, -0.12653061224489795D}, {0.6122448979591837D, -0.8040816326530612D}, {0.0D, -0.35918367346938773D}}, var6, var7, var18, var5, false);
    109                }
    110                else if (var17 == 3)
    111                {
    112                    this.func_92038_a(0.5D, new double[][] {{0.0D, 0.2D}, {0.2D, 0.2D}, {0.2D, 0.6D}, {0.6D, 0.6D}, {0.6D, 0.2D}, {0.2D, 0.2D}, {0.2D, 0.0D}, {0.4D, 0.0D}, {0.4D, -0.6D}, {0.2D, -0.6D}, {0.2D, -0.4D}, {0.0D, -0.4D}}, var6, var7, var18, var5, true);
    113                }
    114                else if (var17 == 4)
    115                {
    116                    this.func_92036_a(var6, var7, var18, var5);
    117                }
    118                else
    119                {
    120                    this.func_92035_a(0.25D, 2, var6, var7, var18, var5);
    121                }
    122
    123                int var8 = var6[0];
    124                float var9 = (float)((var8 & 16711680) >> 16) / 255.0F;
    125                float var10 = (float)((var8 & 65280) >> 8) / 255.0F;
    126                float var11 = (float)((var8 & 255) >> 0) / 255.0F;
    127                EntityFireworkOverlayFX var12 = new EntityFireworkOverlayFX(this.worldObj, this.posX, this.posY, this.posZ);
    128                var12.setRBGColorF(var9, var10, var11);
    129                this.field_92040_ay.addEffect(var12);
    130            }
    131
    132            ++this.field_92042_ax;
    133
    134            if (this.field_92042_ax > this.particleMaxAge)
    135            {
    136                if (this.field_92041_a)
    137                {
    138                    var1 = this.func_92037_i();
    139                    String var16 = "fireworks." + (var1 ? "twinkle_far" : "twinkle");
    140                    this.worldObj.playSound(this.posX, this.posY, this.posZ, var16, 20.0F, 0.9F + this.rand.nextFloat() * 0.15F, true);
    141                }
    142
    143                this.setDead();
    144            }
    145        }
    146
    147        private boolean func_92037_i()
    148        {
    149            Minecraft var1 = Minecraft.getMinecraft();
    150            return var1 == null || var1.renderViewEntity == null || var1.renderViewEntity.getDistanceSq(this.posX, this.posY, this.posZ) >= 256.0D;
    151        }
    152
    153        private void func_92034_a(double par1, double par3, double par5, double par7, double par9, double par11, int[] par13ArrayOfInteger, int[] par14ArrayOfInteger, boolean par15, boolean par16)
    154        {
    155            EntityFireworkSparkFX var17 = new EntityFireworkSparkFX(this.worldObj, par1, par3, par5, par7, par9, par11, this.field_92040_ay);
    156            var17.func_92045_e(par15);
    157            var17.func_92043_f(par16);
    158            int var18 = this.rand.nextInt(par13ArrayOfInteger.length);
    159            var17.func_92044_a(par13ArrayOfInteger[var18]);
    160
    161            if (par14ArrayOfInteger != null && par14ArrayOfInteger.length > 0)
    162            {
    163                var17.func_92046_g(par14ArrayOfInteger[this.rand.nextInt(par14ArrayOfInteger.length)]);
    164            }
    165
    166            this.field_92040_ay.addEffect(var17);
    167        }
    168
    169        private void func_92035_a(double par1, int par3, int[] par4ArrayOfInteger, int[] par5ArrayOfInteger, boolean par6, boolean par7)
    170        {
    171            double var8 = this.posX;
    172            double var10 = this.posY;
    173            double var12 = this.posZ;
    174
    175            for (int var14 = -par3; var14 <= par3; ++var14)
    176            {
    177                for (int var15 = -par3; var15 <= par3; ++var15)
    178                {
    179                    for (int var16 = -par3; var16 <= par3; ++var16)
    180                    {
    181                        double var17 = (double)var15 + (this.rand.nextDouble() - this.rand.nextDouble()) * 0.5D;
    182                        double var19 = (double)var14 + (this.rand.nextDouble() - this.rand.nextDouble()) * 0.5D;
    183                        double var21 = (double)var16 + (this.rand.nextDouble() - this.rand.nextDouble()) * 0.5D;
    184                        double var23 = (double)MathHelper.sqrt_double(var17 * var17 + var19 * var19 + var21 * var21) / par1 + this.rand.nextGaussian() * 0.05D;
    185                        this.func_92034_a(var8, var10, var12, var17 / var23, var19 / var23, var21 / var23, par4ArrayOfInteger, par5ArrayOfInteger, par6, par7);
    186
    187                        if (var14 != -par3 && var14 != par3 && var15 != -par3 && var15 != par3)
    188                        {
    189                            var16 += par3 * 2 - 1;
    190                        }
    191                    }
    192                }
    193            }
    194        }
    195
    196        private void func_92038_a(double par1, double[][] par3ArrayOfDouble, int[] par4ArrayOfInteger, int[] par5ArrayOfInteger, boolean par6, boolean par7, boolean par8)
    197        {
    198            double var9 = par3ArrayOfDouble[0][0];
    199            double var11 = par3ArrayOfDouble[0][1];
    200            this.func_92034_a(this.posX, this.posY, this.posZ, var9 * par1, var11 * par1, 0.0D, par4ArrayOfInteger, par5ArrayOfInteger, par6, par7);
    201            float var13 = this.rand.nextFloat() * (float)Math.PI;
    202            double var14 = par8 ? 0.034D : 0.34D;
    203
    204            for (int var16 = 0; var16 < 3; ++var16)
    205            {
    206                double var17 = (double)var13 + (double)((float)var16 * (float)Math.PI) * var14;
    207                double var19 = var9;
    208                double var21 = var11;
    209
    210                for (int var23 = 1; var23 < par3ArrayOfDouble.length; ++var23)
    211                {
    212                    double var24 = par3ArrayOfDouble[var23][0];
    213                    double var26 = par3ArrayOfDouble[var23][1];
    214
    215                    for (double var28 = 0.25D; var28 <= 1.0D; var28 += 0.25D)
    216                    {
    217                        double var30 = (var19 + (var24 - var19) * var28) * par1;
    218                        double var32 = (var21 + (var26 - var21) * var28) * par1;
    219                        double var34 = var30 * Math.sin(var17);
    220                        var30 *= Math.cos(var17);
    221
    222                        for (double var36 = -1.0D; var36 <= 1.0D; var36 += 2.0D)
    223                        {
    224                            this.func_92034_a(this.posX, this.posY, this.posZ, var30 * var36, var32, var34 * var36, par4ArrayOfInteger, par5ArrayOfInteger, par6, par7);
    225                        }
    226                    }
    227
    228                    var19 = var24;
    229                    var21 = var26;
    230                }
    231            }
    232        }
    233
    234        private void func_92036_a(int[] par1ArrayOfInteger, int[] par2ArrayOfInteger, boolean par3, boolean par4)
    235        {
    236            double var5 = this.rand.nextGaussian() * 0.05D;
    237            double var7 = this.rand.nextGaussian() * 0.05D;
    238
    239            for (int var9 = 0; var9 < 70; ++var9)
    240            {
    241                double var10 = this.motionX * 0.5D + this.rand.nextGaussian() * 0.15D + var5;
    242                double var12 = this.motionZ * 0.5D + this.rand.nextGaussian() * 0.15D + var7;
    243                double var14 = this.motionY * 0.5D + this.rand.nextDouble() * 0.5D;
    244                this.func_92034_a(this.posX, this.posY, this.posZ, var10, var14, var12, par1ArrayOfInteger, par2ArrayOfInteger, par3, par4);
    245            }
    246        }
    247
    248        public int getFXLayer()
    249        {
    250            return 0;
    251        }
    252    }