Jump to content

Need help on Explosion Class


yuckyh

Recommended Posts

Spoiler

public void doExplosionA() {
    Set<BlockPos> set = Sets.newHashSet();
    int i = true;

    int k;
    int l;
    for(int j = 0; j < 16; ++j) {
        for(k = 0; k < 16; ++k) {
            for(l = 0; l < 16; ++l) {
                if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
                    double d0 = (double)((float)j / 15.0F * 2.0F - 1.0F);
                    double d1 = (double)((float)k / 15.0F * 2.0F - 1.0F);
                    double d2 = (double)((float)l / 15.0F * 2.0F - 1.0F);
                    double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
                    d0 /= d3;
                    d1 /= d3;
                    d2 /= d3;
                    float f = this.size * (0.7F + this.world.rand.nextFloat() * 0.6F);
                    double d4 = this.x;
                    double d6 = this.y;
                    double d8 = this.z;

                    for(float var21 = 0.3F; f > 0.0F; f -= 0.22500001F) {
                        BlockPos blockpos = new BlockPos(d4, d6, d8);
                        IBlockState iblockstate = this.world.getBlockState(blockpos);
                        IFluidState ifluidstate = this.world.getFluidState(blockpos);
                        if (!iblockstate.isAir(this.world, blockpos) || !ifluidstate.isEmpty()) {
                            float f2 = Math.max(iblockstate.getExplosionResistance(this.world, blockpos, this.exploder, this), ifluidstate.getExplosionResistance(this.world, blockpos, this.exploder, this));
                            if (this.exploder != null) {
                                f2 = this.exploder.getExplosionResistance(this, this.world, blockpos, iblockstate, ifluidstate, f2);
                            }

                            f -= (f2 + 0.3F) * 0.3F;
                        }

                        if (f > 0.0F && (this.exploder == null || this.exploder.canExplosionDestroyBlock(this, this.world, blockpos, iblockstate, f))) {
                            set.add(blockpos);
                        }

                        d4 += d0 * 0.30000001192092896D;
                        d6 += d1 * 0.30000001192092896D;
                        d8 += d2 * 0.30000001192092896D;
                    }
                }
            }
        }
    }

    this.affectedBlockPositions.addAll(set);
    float f3 = this.size * 2.0F;
    k = MathHelper.floor(this.x - (double)f3 - 1.0D);
    l = MathHelper.floor(this.x + (double)f3 + 1.0D);
    int i2 = MathHelper.floor(this.y - (double)f3 - 1.0D);
    int i1 = MathHelper.floor(this.y + (double)f3 + 1.0D);
    int j2 = MathHelper.floor(this.z - (double)f3 - 1.0D);
    int j1 = MathHelper.floor(this.z + (double)f3 + 1.0D);
    List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this.exploder, new AxisAlignedBB((double)k, (double)i2, (double)j2, (double)l, (double)i1, (double)j1));
    ForgeEventFactory.onExplosionDetonate(this.world, this, list, (double)f3);
    Vec3d vec3d = new Vec3d(this.x, this.y, this.z);

    for(int k2 = 0; k2 < list.size(); ++k2) {
        Entity entity = (Entity)list.get(k2);
        if (!entity.isImmuneToExplosions()) {
            double d12 = entity.getDistance(this.x, this.y, this.z) / (double)f3;
            if (d12 <= 1.0D) {
                double d5 = entity.posX - this.x;
                double d7 = entity.posY + (double)entity.getEyeHeight() - this.y;
                double d9 = entity.posZ - this.z;
                double d13 = (double)MathHelper.sqrt(d5 * d5 + d7 * d7 + d9 * d9);
                if (d13 != 0.0D) {
                    d5 /= d13;
                    d7 /= d13;
                    d9 /= d13;
                    double d14 = (double)this.world.getBlockDensity(vec3d, entity.getBoundingBox());
                    double d10 = (1.0D - d12) * d14;
                    entity.attackEntityFrom(this.getDamageSource(), (float)((int)((d10 * d10 + d10) / 2.0D * 7.0D * (double)f3 + 1.0D)));
                    double d11 = d10;
                    if (entity instanceof EntityLivingBase) {
                        d11 = EnchantmentProtection.getBlastDamageReduction((EntityLivingBase)entity, d10);
                    }

                    entity.motionX += d5 * d11;
                    entity.motionY += d7 * d11;
                    entity.motionZ += d9 * d11;
                    if (entity instanceof EntityPlayer) {
                        EntityPlayer entityplayer = (EntityPlayer)entity;
                        if (!entityplayer.isSpectator() && (!entityplayer.isCreative() || !entityplayer.abilities.isFlying)) {
                            this.playerKnockbackMap.put(entityplayer, new Vec3d(d5 * d10, d7 * d10, d9 * d10));
                        }
                    }
                }
            }
        }
    }

}

public void doExplosionB(boolean p_77279_1_) {
    this.world.playSound((EntityPlayer)null, this.x, this.y, this.z, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 4.0F, (1.0F + (this.world.rand.nextFloat() - this.world.rand.nextFloat()) * 0.2F) * 0.7F);
    if (this.size >= 2.0F && this.damagesTerrain) {
        this.world.spawnParticle(Particles.EXPLOSION_EMITTER, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
    } else {
        this.world.spawnParticle(Particles.EXPLOSION, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
    }

    Iterator var2;
    BlockPos blockpos;
    if (this.damagesTerrain) {
        var2 = this.affectedBlockPositions.iterator();

        while(var2.hasNext()) {
            blockpos = (BlockPos)var2.next();
            IBlockState iblockstate = this.world.getBlockState(blockpos);
            Block block = iblockstate.getBlock();
            if (p_77279_1_) {
                double d0 = (double)((float)blockpos.getX() + this.world.rand.nextFloat());
                double d1 = (double)((float)blockpos.getY() + this.world.rand.nextFloat());
                double d2 = (double)((float)blockpos.getZ() + this.world.rand.nextFloat());
                double d3 = d0 - this.x;
                double d4 = d1 - this.y;
                double d5 = d2 - this.z;
                double d6 = (double)MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
                d3 /= d6;
                d4 /= d6;
                d5 /= d6;
                double d7 = 0.5D / (d6 / (double)this.size + 0.1D);
                d7 *= (double)(this.world.rand.nextFloat() * this.world.rand.nextFloat() + 0.3F);
                d3 *= d7;
                d4 *= d7;
                d5 *= d7;
                this.world.spawnParticle(Particles.POOF, (d0 + this.x) / 2.0D, (d1 + this.y) / 2.0D, (d2 + this.z) / 2.0D, d3, d4, d5);
                this.world.spawnParticle(Particles.SMOKE, d0, d1, d2, d3, d4, d5);
            }

            if (!iblockstate.isAir(this.world, blockpos)) {
                if (block.canDropFromExplosion(this)) {
                    iblockstate.dropBlockAsItemWithChance(this.world, blockpos, 1.0F / this.size, 0);
                }

                iblockstate.onBlockExploded(this.world, blockpos, this);
            }
        }
    }

    if (this.causesFire) {
        var2 = this.affectedBlockPositions.iterator();

        while(var2.hasNext()) {
            blockpos = (BlockPos)var2.next();
            if (this.world.getBlockState(blockpos).isAir(this.world, blockpos) && this.world.getBlockState(blockpos.down()).isOpaqueCube(this.world, blockpos.down()) && this.random.nextInt(3) == 0) {
                this.world.setBlockState(blockpos, Blocks.FIRE.getDefaultState());
            }
        }
    }

}

Can someone give me an explained version of this code as comments because I want to create a custom explosion thing

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.