    001    package net.minecraft.src;
    002
    003    import java.util.ArrayList;
    004    import java.util.HashMap;
    005    import java.util.HashSet;
    006    import java.util.Iterator;
    007    import java.util.List;
    008    import java.util.Map;
    009    import java.util.Random;
    010
    011    public class Explosion
    012    {
    013        /** whether or not the explosion sets fire to blocks around it */
    014        public boolean isFlaming = false;
    015        public boolean field_82755_b = true;
    016        private int field_77289_h = 16;
    017        private Random explosionRNG = new Random();
    018        private World worldObj;
    019        public double explosionX;
    020        public double explosionY;
    021        public double explosionZ;
    022        public Entity exploder;
    023        public float explosionSize;
    024        public List field_77281_g = new ArrayList();
    025        private Map field_77288_k = new HashMap();
    026
    027        public Explosion(World par1World, Entity par2Entity, double par3, double par5, double par7, float par9)
    028        {
    029            this.worldObj = par1World;
    030            this.exploder = par2Entity;
    031            this.explosionSize = par9;
    032            this.explosionX = par3;
    033            this.explosionY = par5;
    034            this.explosionZ = par7;
    035        }
    036
    037        /**
    038         * Does the first part of the explosion (destroy blocks)
    039         */
    040        public void doExplosionA()
    041        {
    042            float var1 = this.explosionSize;
    043            HashSet var2 = new HashSet();
    044            int var3;
    045            int var4;
    046            int var5;
    047            double var15;
    048            double var17;
    049            double var19;
    050
    051            for (var3 = 0; var3 < this.field_77289_h; ++var3)
    052            {
    053                for (var4 = 0; var4 < this.field_77289_h; ++var4)
    054                {
    055                    for (var5 = 0; var5 < this.field_77289_h; ++var5)
    056                    {
    057                        if (var3 == 0 || var3 == this.field_77289_h - 1 || var4 == 0 || var4 == this.field_77289_h - 1 || var5 == 0 || var5 == this.field_77289_h - 1)
    058                        {
    059                            double var6 = (double)((float)var3 / ((float)this.field_77289_h - 1.0F) * 2.0F - 1.0F);
    060                            double var8 = (double)((float)var4 / ((float)this.field_77289_h - 1.0F) * 2.0F - 1.0F);
    061                            double var10 = (double)((float)var5 / ((float)this.field_77289_h - 1.0F) * 2.0F - 1.0F);
    062                            double var12 = Math.sqrt(var6 * var6 + var8 * var8 + var10 * var10);
    063                            var6 /= var12;
    064                            var8 /= var12;
    065                            var10 /= var12;
    066                            float var14 = this.explosionSize * (0.7F + this.worldObj.rand.nextFloat() * 0.6F);
    067                            var15 = this.explosionX;
    068                            var17 = this.explosionY;
    069                            var19 = this.explosionZ;
    070
    071                            for (float var21 = 0.3F; var14 > 0.0F; var14 -= var21 * 0.75F)
    072                            {
    073                                int var22 = MathHelper.floor_double(var15);
    074                                int var23 = MathHelper.floor_double(var17);
    075                                int var24 = MathHelper.floor_double(var19);
    076                                int var25 = this.worldObj.getBlockId(var22, var23, var24);
    077
    078                                if (var25 > 0)
    079                                {
    080                                    Block var26 = Block.blocksList[var25];
    081                                    float var27 = this.exploder != null ? this.exploder.func_82146_a(this, var26, var22, var23, var24) : var26.getExplosionResistance(this.exploder, worldObj, var22, var23, var24, explosionX, explosionY, explosionZ);
    082                                    var14 -= (var27 + 0.3F) * var21;
    083                                }
    084
    085                                if (var14 > 0.0F)
    086                                {
    087                                    var2.add(new ChunkPosition(var22, var23, var24));
    088                                }
    089
    090                                var15 += var6 * (double)var21;
    091                                var17 += var8 * (double)var21;
    092                                var19 += var10 * (double)var21;
    093                            }
    094                        }
    095                    }
    096                }
    097            }
    098
    099            this.field_77281_g.addAll(var2);
    100            this.explosionSize *= 2.0F;
    101            var3 = MathHelper.floor_double(this.explosionX - (double)this.explosionSize - 1.0D);
    102            var4 = MathHelper.floor_double(this.explosionX + (double)this.explosionSize + 1.0D);
    103            var5 = MathHelper.floor_double(this.explosionY - (double)this.explosionSize - 1.0D);
    104            int var28 = MathHelper.floor_double(this.explosionY + (double)this.explosionSize + 1.0D);
    105            int var7 = MathHelper.floor_double(this.explosionZ - (double)this.explosionSize - 1.0D);
    106            int var29 = MathHelper.floor_double(this.explosionZ + (double)this.explosionSize + 1.0D);
    107            List var9 = this.worldObj.getEntitiesWithinAABBExcludingEntity(this.exploder, AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)var3, (double)var5, (double)var7, (double)var4, (double)var28, (double)var29));
    108            Vec3 var30 = this.worldObj.func_82732_R().getVecFromPool(this.explosionX, this.explosionY, this.explosionZ);
    109
    110            for (int var11 = 0; var11 < var9.size(); ++var11)
    111            {
    112                Entity var31 = (Entity)var9.get(var11);
    113                double var13 = var31.getDistance(this.explosionX, this.explosionY, this.explosionZ) / (double)this.explosionSize;
    114
    115                if (var13 <= 1.0D)
    116                {
    117                    var15 = var31.posX - this.explosionX;
    118                    var17 = var31.posY + (double)var31.getEyeHeight() - this.explosionY;
    119                    var19 = var31.posZ - this.explosionZ;
    120                    double var33 = (double)MathHelper.sqrt_double(var15 * var15 + var17 * var17 + var19 * var19);
    121
    122                    if (var33 != 0.0D)
    123                    {
    124                        var15 /= var33;
    125                        var17 /= var33;
    126                        var19 /= var33;
    127                        double var32 = (double)this.worldObj.getBlockDensity(var30, var31.boundingBox);
    128                        double var34 = (1.0D - var13) * var32;
    129                        var31.attackEntityFrom(DamageSource.explosion, (int)((var34 * var34 + var34) / 2.0D * 8.0D * (double)this.explosionSize + 1.0D));
    130                        var31.motionX += var15 * var34;
    131                        var31.motionY += var17 * var34;
    132                        var31.motionZ += var19 * var34;
    133
    134                        if (var31 instanceof EntityPlayer)
    135                        {
    136                            this.field_77288_k.put((EntityPlayer)var31, this.worldObj.func_82732_R().getVecFromPool(var15 * var34, var17 * var34, var19 * var34));
    137                        }
    138                    }
    139                }
    140            }
    141
    142            this.explosionSize = var1;
    143        }
    144
    145        /**
    146         * Does the second part of the explosion (sound, particles, drop spawn)
    147         */
    148        public void doExplosionB(boolean par1)
    149        {
    150            this.worldObj.playSoundEffect(this.explosionX, this.explosionY, this.explosionZ, "random.explode", 4.0F, (1.0F + (this.worldObj.rand.nextFloat() - this.worldObj.rand.nextFloat()) * 0.2F) * 0.7F);
    151
    152            if (this.explosionSize >= 2.0F && this.field_82755_b)
    153            {
    154                this.worldObj.spawnParticle("hugeexplosion", this.explosionX, this.explosionY, this.explosionZ, 1.0D, 0.0D, 0.0D);
    155            }
    156            else
    157            {
    158                this.worldObj.spawnParticle("largeexplode", this.explosionX, this.explosionY, this.explosionZ, 1.0D, 0.0D, 0.0D);
    159            }
    160
    161            Iterator var2;
    162            ChunkPosition var3;
    163            int var4;
    164            int var5;
    165            int var6;
    166            int var7;
    167
    168            if (this.field_82755_b)
    169            {
    170                var2 = this.field_77281_g.iterator();
    171
    172                while (var2.hasNext())
    173                {
    174                    var3 = (ChunkPosition)var2.next();
    175                    var4 = var3.x;
    176                    var5 = var3.y;
    177                    var6 = var3.z;
    178                    var7 = this.worldObj.getBlockId(var4, var5, var6);
    179
    180                    if (par1)
    181                    {
    182                        double var8 = (double)((float)var4 + this.worldObj.rand.nextFloat());
    183                        double var10 = (double)((float)var5 + this.worldObj.rand.nextFloat());
    184                        double var12 = (double)((float)var6 + this.worldObj.rand.nextFloat());
    185                        double var14 = var8 - this.explosionX;
    186                        double var16 = var10 - this.explosionY;
    187                        double var18 = var12 - this.explosionZ;
    188                        double var20 = (double)MathHelper.sqrt_double(var14 * var14 + var16 * var16 + var18 * var18);
    189                        var14 /= var20;
    190                        var16 /= var20;
    191                        var18 /= var20;
    192                        double var22 = 0.5D / (var20 / (double)this.explosionSize + 0.1D);
    193                        var22 *= (double)(this.worldObj.rand.nextFloat() * this.worldObj.rand.nextFloat() + 0.3F);
    194                        var14 *= var22;
    195                        var16 *= var22;
    196                        var18 *= var22;
    197                        this.worldObj.spawnParticle("explode", (var8 + this.explosionX * 1.0D) / 2.0D, (var10 + this.explosionY * 1.0D) / 2.0D, (var12 + this.explosionZ * 1.0D) / 2.0D, var14, var16, var18);
    198                        this.worldObj.spawnParticle("smoke", var8, var10, var12, var14, var16, var18);
    199                    }
    200
    201                    if (var7 > 0)
    202                    {
    203                        Block.blocksList[var7].dropBlockAsItemWithChance(this.worldObj, var4, var5, var6, this.worldObj.getBlockMetadata(var4, var5, var6), 0.3F, 0);
    204
    205                        if (this.worldObj.setBlockAndMetadataWithUpdate(var4, var5, var6, 0, 0, this.worldObj.isRemote))
    206                        {
    207                            this.worldObj.notifyBlocksOfNeighborChange(var4, var5, var6, 0);
    208                        }
    209
    210                        Block.blocksList[var7].onBlockDestroyedByExplosion(this.worldObj, var4, var5, var6);
    211                    }
    212                }
    213            }
    214
    215            if (this.isFlaming)
    216            {
    217                var2 = this.field_77281_g.iterator();
    218
    219                while (var2.hasNext())
    220                {
    221                    var3 = (ChunkPosition)var2.next();
    222                    var4 = var3.x;
    223                    var5 = var3.y;
    224                    var6 = var3.z;
    225                    var7 = this.worldObj.getBlockId(var4, var5, var6);
    226                    int var24 = this.worldObj.getBlockId(var4, var5 - 1, var6);
    227
    228                    if (var7 == 0 && Block.opaqueCubeLookup[var24] && this.explosionRNG.nextInt(3) == 0)
    229                    {
    230                        this.worldObj.setBlockWithNotify(var4, var5, var6, Block.fire.blockID);
    231                    }
    232                }
    233            }
    234        }
    235
    236        public Map func_77277_b()
    237        {
    238            return this.field_77288_k;
    239        }
    240    }