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