Example usage for net.minecraftforge.event ForgeEventFactory onExplosionDetonate

List of usage examples for net.minecraftforge.event ForgeEventFactory onExplosionDetonate

Introduction

In this page you can find the example usage for net.minecraftforge.event ForgeEventFactory onExplosionDetonate.

Prototype

public static void onExplosionDetonate(World world, Explosion explosion, List<Entity> list, double diameter) 

Source Link

Usage

From source file:stevekung.mods.moreplanets.planets.kapteynb.world.UraniumExplosion.java

License:Creative Commons License

@Override
public void doExplosionA() {
    float f = this.explosionSize;
    HashSet hashset = new HashSet();
    int i;/*from   ww  w  . ja  va2  s  .  c o m*/
    int j;
    int k;
    double d5;
    double d6;
    double d7;

    for (i = 0; i < this.field_77289_h; ++i) {
        for (j = 0; j < this.field_77289_h; ++j) {
            for (k = 0; k < this.field_77289_h; ++k) {
                if (i == 0 || i == this.field_77289_h - 1 || j == 0 || j == this.field_77289_h - 1 || k == 0
                        || k == this.field_77289_h - 1) {
                    double d0 = i / (this.field_77289_h - 1.0F) * 2.0F - 1.0F;
                    double d1 = j / (this.field_77289_h - 1.0F) * 2.0F - 1.0F;
                    double d2 = k / (this.field_77289_h - 1.0F) * 2.0F - 1.0F;
                    double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
                    d0 /= d3;
                    d1 /= d3;
                    d2 /= d3;
                    float f1 = this.explosionSize * (0.7F + this.worldObj.rand.nextFloat() * 0.6F);
                    d5 = this.explosionX;
                    d6 = this.explosionY;
                    d7 = this.explosionZ;

                    for (float f2 = 0.3F; f1 > 0.0F; f1 -= f2 * 0.75F) {
                        int j1 = MathHelper.floor_double(d5);
                        int k1 = MathHelper.floor_double(d6);
                        int l1 = MathHelper.floor_double(d7);
                        Block block = this.worldObj.getBlock(j1, k1, l1);

                        if (block.getMaterial() != Material.air) {
                            float f3 = this.exploder != null
                                    ? this.exploder.func_145772_a(this, this.worldObj, j1, k1, l1, block)
                                    : block.getExplosionResistance(this.exploder, this.worldObj, j1, k1, l1,
                                            this.explosionX, this.explosionY, this.explosionZ);
                            f1 -= (f3 + 0.3F) * f2;
                        }
                        if (f1 > 0.0F && (this.exploder == null
                                || this.exploder.func_145774_a(this, this.worldObj, j1, k1, l1, block, f1))) {
                            hashset.add(new ChunkPosition(j1, k1, l1));
                        }
                        d5 += d0 * f2;
                        d6 += d1 * f2;
                        d7 += d2 * f2;
                    }
                }
            }
        }
    }

    this.affectedBlockPositions.addAll(hashset);
    this.explosionSize *= 2.0F;
    i = MathHelper.floor_double(this.explosionX - this.explosionSize - 1.0D);
    j = MathHelper.floor_double(this.explosionX + this.explosionSize + 1.0D);
    k = MathHelper.floor_double(this.explosionY - this.explosionSize - 1.0D);
    int i2 = MathHelper.floor_double(this.explosionY + this.explosionSize + 1.0D);
    int l = MathHelper.floor_double(this.explosionZ - this.explosionSize - 1.0D);
    int j2 = MathHelper.floor_double(this.explosionZ + this.explosionSize + 1.0D);
    List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this.exploder,
            AxisAlignedBB.getBoundingBox(i, k, l, j, i2, j2));
    ForgeEventFactory.onExplosionDetonate(this.worldObj, this, list, this.explosionSize);
    Vec3 vec3 = Vec3.createVectorHelper(this.explosionX, this.explosionY, this.explosionZ);

    for (int i1 = 0; i1 < list.size(); ++i1) {
        Entity entity = (Entity) list.get(i1);
        double d4 = entity.getDistance(this.explosionX, this.explosionY, this.explosionZ) / this.explosionSize;

        if (d4 <= 1.0D) {
            d5 = entity.posX - this.explosionX;
            d6 = entity.posY + entity.getEyeHeight() - this.explosionY;
            d7 = entity.posZ - this.explosionZ;
            double d9 = MathHelper.sqrt_double(d5 * d5 + d6 * d6 + d7 * d7);

            if (d9 != 0.0D) {
                d5 /= d9;
                d6 /= d9;
                d7 /= d9;
                double d10 = this.worldObj.getBlockDensity(vec3, entity.boundingBox);
                double d11 = (1.0D - d4) * d10;
                entity.attackEntityFrom(DamageSource.setExplosionSource(this),
                        (int) ((d11 * d11 + d11) / 2.0D * 8.0D * this.explosionSize + 1.0D));
                double d8 = EnchantmentProtection.func_92092_a(entity, d11);
                entity.motionX += d5 * d8;
                entity.motionY += d6 * d8;
                entity.motionZ += d7 * d8;

                if (entity instanceof EntityPlayer) {
                    this.field_77288_k.put(entity, Vec3.createVectorHelper(d5 * d11, d6 * d11, d7 * d11));
                }
            }
        }
    }
    this.explosionSize = f;
}