diff --git a/src/main/java/buildcraftAdditions/tileEntities/Bases/TileKineticEnergyBufferBase.java b/src/main/java/buildcraftAdditions/tileEntities/Bases/TileKineticEnergyBufferBase.java index 1826b0c4..e6331206 100644 --- a/src/main/java/buildcraftAdditions/tileEntities/Bases/TileKineticEnergyBufferBase.java +++ b/src/main/java/buildcraftAdditions/tileEntities/Bases/TileKineticEnergyBufferBase.java @@ -29,6 +29,7 @@ import buildcraftAdditions.networking.PacketHandler; import buildcraftAdditions.tileEntities.TileKineticEnergyBufferTier1; import buildcraftAdditions.tileEntities.interfaces.IOwnableMachine; +import buildcraftAdditions.utils.LargeExplosion; import buildcraftAdditions.utils.PlayerUtils; import buildcraftAdditions.utils.Utils; @@ -181,7 +182,7 @@ public void activateSelfDestruct() { } public void byeBye() { - Explosion explosion = worldObj.createExplosion(destroyer, xCoord, yCoord, zCoord, (energy / 900000) + 5, true); + LargeExplosion explosion = new LargeExplosion(worldObj, destroyer, xCoord, yCoord, zCoord, (energy / 9000000) + 5, false, true); explosion.doExplosionA(); explosion.doExplosionB(true); } diff --git a/src/main/java/buildcraftAdditions/utils/LargeExplosion.java b/src/main/java/buildcraftAdditions/utils/LargeExplosion.java new file mode 100644 index 00000000..9a255518 --- /dev/null +++ b/src/main/java/buildcraftAdditions/utils/LargeExplosion.java @@ -0,0 +1,226 @@ +package buildcraftAdditions.utils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.enchantment.EnchantmentProtection; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.DamageSource; +import net.minecraft.util.MathHelper; +import net.minecraft.util.Vec3; +import net.minecraft.world.ChunkPosition; +import net.minecraft.world.Explosion; +import net.minecraft.world.World; + +/** + * Copyright (c) 2014-2015, AEnterprise + * http://buildcraftadditions.wordpress.com/ + * Buildcraft Additions is distributed under the terms of GNU GPL v3.0 + * Please check the contents of the license located in + * http://buildcraftadditions.wordpress.com/wiki/licensing-stuff/ + */ +public class LargeExplosion { //this is mostly the same as the vanilla explosion class but this was the best way to make my changes. + + public boolean isFlaming; + public boolean isSmoking; + private int smoothness = 200; + private Random explosionRNG = new Random(); + private World world; + public double explosionX; + public double explosionY; + public double explosionZ; + public Entity exploder; + public float explosionSize; + public List affectedBlockPositions = new ArrayList(); + private Map field_77288_k = new HashMap(); + + private Explosion TNT = new Explosion(this.world, this.exploder, this.explosionX, this.explosionY, this.explosionZ, this.explosionSize); + + public LargeExplosion(World world, Entity entity, double explosionX, double explosionY, double explosionZ, float size, boolean isFlaming, boolean isSmoking) { + this.world = world; + this.exploder = entity; + this.explosionX = explosionX; + this.explosionY = explosionY; + this.explosionZ = explosionZ; + this.explosionSize = size; + this.isFlaming = isFlaming; + this.isSmoking = isSmoking; + } + + public void doExplosionA() { + float f = this.explosionSize; + HashSet hashset = new HashSet(); + + for (int i = 0; i < this.smoothness; i++) { + for (int j = 0; j < this.smoothness; j++) { + for (int k = 0; k < this.smoothness; k++) { + if ((i == 0) || (i == this.smoothness - 1) || (j == 0) || (j == this.smoothness - 1) || (k == 0) || (k == this.smoothness - 1)) { + double d3 = i / (this.smoothness - 1.0F) * 2.0F - 1.0F; + double d4 = j / (this.smoothness - 1.0F) * 2.0F - 1.0F; + double d5 = k / (this.smoothness - 1.0F) * 2.0F - 1.0F; + double d6 = Math.sqrt(d3 * d3 + d4 * d4 + d5 * d5); + d3 /= d6; + d4 /= d6; + d5 /= d6; + float f1 = this.explosionSize * (0.7F + this.world.rand.nextFloat() * 0.6F); + double d0 = this.explosionX; + double d1 = this.explosionY; + double d2 = this.explosionZ; + + for (float f2 = 0.3F; f1 > 0.0F; f1 -= f2 * 0.75F) { + int l = MathHelper.floor_double(d0); + int i1 = MathHelper.floor_double(d1); + int j1 = MathHelper.floor_double(d2); + Block block = this.world.getBlock(l, i1, j1); + + if ((block == Blocks.stone) || (block == Blocks.cobblestone) || (block == Blocks.coal_ore) || (block == Blocks.iron_ore) || (block == Blocks.gold_ore) || (block == Blocks.diamond_ore) || (block.getMaterial() == Material.rock)) { + float f3 = this.exploder != null ? this.exploder.func_145772_a(this.TNT, this.world, l, i1, j1, block) : block.getExplosionResistance(this.exploder, this.world, l, i1, j1, this.explosionX, this.explosionY, this.explosionZ); + f1 -= (f3 - 1.7F) * f2; + } + if ((block.getMaterial() != Material.air) && (block != Blocks.stone) && (block != Blocks.cobblestone) && (block != Blocks.coal_ore) && (block != Blocks.iron_ore) && (block != Blocks.gold_ore) && (block != Blocks.diamond_ore) && (block.getMaterial() != Material.rock)) { + float f3 = this.exploder != null ? this.exploder.func_145772_a(this.TNT, this.world, l, i1, j1, block) : block.getExplosionResistance(this.exploder, this.world, l, i1, j1, this.explosionX, this.explosionY, this.explosionZ); + f1 -= (f3 + 0.3F) * f2; + } + + if ((f1 > 0.0F) && ((this.exploder == null) || (this.exploder.func_145774_a(this.TNT, this.world, l, i1, j1, block, f1)))) { + hashset.add(new ChunkPosition(l, i1, j1)); + } + + d0 += d3 * f2; + d1 += d4 * f2 * 1.5D; + d2 += d5 * f2; + } + } + } + } + } + + this.affectedBlockPositions.addAll(hashset); + this.explosionSize *= 2.0F; + int i = MathHelper.floor_double(this.explosionX - this.explosionSize - 1.0D); + int j = MathHelper.floor_double(this.explosionX + this.explosionSize + 1.0D); + int k = MathHelper.floor_double(this.explosionY - this.explosionSize - 1.0D); + int l1 = MathHelper.floor_double(this.explosionY + this.explosionSize + 1.0D); + int i2 = MathHelper.floor_double(this.explosionZ - this.explosionSize - 1.0D); + int j2 = MathHelper.floor_double(this.explosionZ + this.explosionSize + 1.0D); + List list = this.world.getEntitiesWithinAABBExcludingEntity(this.exploder, AxisAlignedBB.getBoundingBox(i, k, i2, j, l1, j2)); + Vec3 vec3 = Vec3.createVectorHelper(this.explosionX, this.explosionY, this.explosionZ); + + for (int k2 = 0; k2 < list.size(); k2++) { + Entity entity = (Entity) list.get(k2); + double d7 = entity.getDistance(this.explosionX, this.explosionY, this.explosionZ) / this.explosionSize; + + if (d7 <= 1.0D) { + double d0 = entity.posX - this.explosionX; + double d1 = entity.posY + entity.getEyeHeight() - this.explosionY; + double d2 = entity.posZ - this.explosionZ; + double d8 = MathHelper.sqrt_double(d0 * d0 + d1 * d1 + d2 * d2); + + if (d8 != 0.0D) { + d0 /= d8; + d1 /= d8; + d2 /= d8; + double d9 = this.world.getBlockDensity(vec3, entity.boundingBox); + double d10 = (1.0D - d7) * d9; + entity.attackEntityFrom(DamageSource.setExplosionSource(this.TNT), (int) ((d10 * d10 + d10) / 2.0D * 8.0D * this.explosionSize + 1.0D)); + double d11 = EnchantmentProtection.func_92092_a(entity, d10); + entity.motionX += d0 * d11; + entity.motionY += d1 * d11; + entity.motionZ += d2 * d11; + + if ((entity instanceof EntityPlayer)) { + this.field_77288_k.put((EntityPlayer) entity, Vec3.createVectorHelper(d0 * d10, d1 * d10, d2 * d10)); + } + } + } + } + + this.explosionSize = f; + } + + public void doExplosionB(boolean par1) { + this.world.playSoundEffect(this.explosionX, this.explosionY, this.explosionZ, "random.explode", 4.0F, (1.0F + (this.world.rand.nextFloat() - this.world.rand.nextFloat()) * 0.2F) * 0.7F); + + if ((this.explosionSize >= 2.0F) && (this.isSmoking)) { + this.world.spawnParticle("hugeexplosion", this.explosionX, this.explosionY, this.explosionZ, 1.0D, 0.0D, 0.0D); + } else { + this.world.spawnParticle("largeexplode", this.explosionX, this.explosionY, this.explosionZ, 1.0D, 0.0D, 0.0D); + } + + if (this.isSmoking) { + Iterator iterator = this.affectedBlockPositions.iterator(); + + while (iterator.hasNext()) { + ChunkPosition chunkposition = (ChunkPosition) iterator.next(); + int i = chunkposition.chunkPosX; + int j = chunkposition.chunkPosY; + int k = chunkposition.chunkPosZ; + Block block = this.world.getBlock(i, j, k); + + if (par1) { + double d0 = i + this.world.rand.nextFloat(); + double d1 = j + this.world.rand.nextFloat(); + double d2 = k + this.world.rand.nextFloat(); + double d3 = d0 - this.explosionX; + double d4 = d1 - this.explosionY; + double d5 = d2 - this.explosionZ; + double d6 = MathHelper.sqrt_double(d3 * d3 + d4 * d4 + d5 * d5); + d3 /= d6; + d4 /= d6; + d5 /= d6; + double d7 = 0.5D / (d6 / this.explosionSize + 0.1D); + d7 *= (this.world.rand.nextFloat() * this.world.rand.nextFloat() + 0.3F); + d3 *= d7; + d4 *= d7; + d5 *= d7; + this.world.spawnParticle("explode", (d0 + this.explosionX * 1.0D) / 2.0D, (d1 + this.explosionY * 1.0D) / 2.0D, (d2 + this.explosionZ * 1.0D) / 2.0D, d3, d4, d5); + this.world.spawnParticle("smoke", d0, d1, d2, d3, d4, d5); + } + + if (block.getMaterial() != Material.air) { + if (block.canDropFromExplosion(this.TNT)) { + block.dropBlockAsItemWithChance(this.world, i, j, k, this.world.getBlockMetadata(i, j, k), 1.0F / this.explosionSize, 0); + } + + block.onBlockExploded(this.world, i, j, k, this.TNT); + } + } + } + + if (this.isFlaming) { + Iterator iterator = this.affectedBlockPositions.iterator(); + + while (iterator.hasNext()) { + ChunkPosition chunkposition = (ChunkPosition) iterator.next(); + int i = chunkposition.chunkPosX; + int j = chunkposition.chunkPosY; + int k = chunkposition.chunkPosZ; + Block block = this.world.getBlock(i, j, k); + Block block1 = this.world.getBlock(i, j - 1, k); + + if ((block.getMaterial() == Material.air) && (block1.isOpaqueCube()) && (this.explosionRNG.nextInt(3) == 0)) { + this.world.setBlock(i, j, k, Blocks.fire); + } + } + } + } + + public Map func_77277_b() { + return this.field_77288_k; + } + + public EntityLivingBase getExplosivePlacedBy() { + return (this.exploder instanceof EntityLivingBase) ? (EntityLivingBase) this.exploder : null; + } +}