UtilBlock: Added a method that may or may not tell you the blocks destroyed in an explosion

This commit is contained in:
libraryaddict 2015-04-12 23:20:52 +12:00
parent 03fb8c203e
commit be21968805
1 changed files with 73 additions and 0 deletions

View File

@ -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<Block> getExplosionBlocks(Location location, float strength, boolean damageBlocksEqually)
{
ArrayList<Block> toExplode = new ArrayList<Block>();
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<Block> getSurrounding(Block block, boolean diagonals)
{
ArrayList<Block> blocks = new ArrayList<Block>();