From be21968805c5c34b4e7b4c6882fa00ead26d00dc Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 12 Apr 2015 23:20:52 +1200 Subject: [PATCH] UtilBlock: Added a method that may or may not tell you the blocks destroyed in an explosion --- .../mineplex/core/common/util/UtilBlock.java | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java index a1d040f18..fec6f0710 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java @@ -4,11 +4,16 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import net.minecraft.server.v1_7_R4.Blocks; +import net.minecraft.server.v1_7_R4.MathHelper; +import net.minecraft.server.v1_7_R4.WorldServer; + import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.craftbukkit.v1_7_R4.CraftWorld; import org.bukkit.inventory.ItemStack; public class UtilBlock @@ -377,6 +382,74 @@ public class UtilBlock return block.getRelative(BlockFace.UP); } + + /** + * + * @param location of explosion + * @param strength of explosion + * @param damageBlocksEqually - Treat all blocks as durability of dirt + * @param ensureDestruction - Ensure that the closest blocks are destroyed at least + * @return + */ + public static ArrayList getExplosionBlocks(Location location, float strength, boolean damageBlocksEqually) + { + ArrayList toExplode = new ArrayList(); + WorldServer world = ((CraftWorld) location.getWorld()).getHandle(); + + for (int i = 0; i < 16; i++) + { + for (int j = 0; j < 16; j++) + { + for (int k = 0; k < 16; k++) + { + if ((i == 0) || (i == 16 - 1) || (j == 0) || (j == 16 - 1) || (k == 0) || (k == 16 - 1)) + { + double d3 = i / (16 - 1.0F) * 2.0F - 1.0F; + double d4 = j / (16 - 1.0F) * 2.0F - 1.0F; + double d5 = k / (16 - 1.0F) * 2.0F - 1.0F; + double d6 = Math.sqrt(d3 * d3 + d4 * d4 + d5 * d5); + + d3 /= d6; + d4 /= d6; + d5 /= d6; + float f1 = strength * (0.7F + UtilMath.random.nextFloat() * 0.6F); + + double d0 = location.getX(); + double d1 = location.getY(); + double d2 = location.getZ(); + + for (float f2 = 0.3F; f1 > 0.0F; f1 -= f2 * 0.75F) + { + int l = MathHelper.floor(d0); + int i1 = MathHelper.floor(d1); + int j1 = MathHelper.floor(d2); + Block block = location.getWorld().getBlockAt(l, i1, j1); + + if (block.getType() != Material.AIR) + { + float f3 = (damageBlocksEqually ? Blocks.DIRT : world.getType(block.getX(), block.getY(), + block.getZ())).a((net.minecraft.server.v1_7_R4.Entity) null); + + f1 -= (f3 + 0.3F) * f2; + } + + if ((f1 > 0.0F) && (i1 < 256) && (i1 >= 0)) + { + toExplode.add(block); + } + + d0 += d3 * f2; + d1 += d4 * f2; + d2 += d5 * f2; + } + } + } + } + } + + return toExplode; + } + public static ArrayList getSurrounding(Block block, boolean diagonals) { ArrayList blocks = new ArrayList();