added more to block reference, added validation code and surroundings code to utility
This commit is contained in:
parent
ce0afb8bb5
commit
fa63606d90
2 changed files with 159 additions and 0 deletions
|
@ -6,6 +6,9 @@ import org.bukkit.Material;
|
||||||
|
|
||||||
public class BlockRef
|
public class BlockRef
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* A list of all valid hammer blocks (must be valid pickaxe blocks)
|
||||||
|
*/
|
||||||
public static ArrayList<Material> ValidHammerBlocks = new ArrayList<Material>()
|
public static ArrayList<Material> ValidHammerBlocks = new ArrayList<Material>()
|
||||||
{{
|
{{
|
||||||
add(Material.COAL_ORE);
|
add(Material.COAL_ORE);
|
||||||
|
@ -31,12 +34,19 @@ public class BlockRef
|
||||||
add(Material.DIORITE);
|
add(Material.DIORITE);
|
||||||
add(Material.ANDESITE);
|
add(Material.ANDESITE);
|
||||||
add(Material.GRANITE);
|
add(Material.GRANITE);
|
||||||
|
add(Material.ICE);
|
||||||
|
add(Material.BLUE_ICE);
|
||||||
|
add(Material.FROSTED_ICE);
|
||||||
|
add(Material.PACKED_ICE);
|
||||||
|
|
||||||
add(Material.END_STONE);
|
add(Material.END_STONE);
|
||||||
add(Material.NETHERRACK);
|
add(Material.NETHERRACK);
|
||||||
add(Material.NETHER_QUARTZ_ORE);
|
add(Material.NETHER_QUARTZ_ORE);
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of all valid excavator blocks (must be valid shovel blocks)
|
||||||
|
*/
|
||||||
public static ArrayList<Material> ValidExcavatorBlocks = new ArrayList<Material>()
|
public static ArrayList<Material> ValidExcavatorBlocks = new ArrayList<Material>()
|
||||||
{{
|
{{
|
||||||
add(Material.DIRT);
|
add(Material.DIRT);
|
||||||
|
@ -55,4 +65,28 @@ public class BlockRef
|
||||||
|
|
||||||
add(Material.SOUL_SAND);
|
add(Material.SOUL_SAND);
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of all valid hammers (pickaxes)
|
||||||
|
*/
|
||||||
|
public static ArrayList<Material> ValidHammers = new ArrayList<Material>()
|
||||||
|
{{
|
||||||
|
add(Material.WOODEN_PICKAXE);
|
||||||
|
add(Material.STONE_PICKAXE);
|
||||||
|
add(Material.IRON_PICKAXE);
|
||||||
|
add(Material.GOLDEN_PICKAXE);
|
||||||
|
add(Material.DIAMOND_PICKAXE);
|
||||||
|
}};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of all valid excavators (shovels)
|
||||||
|
*/
|
||||||
|
public static ArrayList<Material> ValidExcavators = new ArrayList<Material>()
|
||||||
|
{{
|
||||||
|
add(Material.WOODEN_SHOVEL);
|
||||||
|
add(Material.STONE_SHOVEL);
|
||||||
|
add(Material.IRON_SHOVEL);
|
||||||
|
add(Material.GOLDEN_SHOVEL);
|
||||||
|
add(Material.DIAMOND_SHOVEL);
|
||||||
|
}};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,141 @@
|
||||||
package lightling.gibsoniacraft.util;
|
package lightling.gibsoniacraft.util;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
public class ToolUtil
|
public class ToolUtil
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Determines whether a block is mineable
|
||||||
|
* @param mat The material being checked
|
||||||
|
* @return Whether the block is mineable
|
||||||
|
*/
|
||||||
public boolean IsMineable(Material mat)
|
public boolean IsMineable(Material mat)
|
||||||
{
|
{
|
||||||
return BlockRef.ValidHammerBlocks.contains(mat);
|
return BlockRef.ValidHammerBlocks.contains(mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether a block is diggable
|
||||||
|
* @param mat The material being checked
|
||||||
|
* @return Whether the block is diggable
|
||||||
|
*/
|
||||||
public boolean IsDiggable(Material mat)
|
public boolean IsDiggable(Material mat)
|
||||||
{
|
{
|
||||||
return BlockRef.ValidExcavatorBlocks.contains(mat);
|
return BlockRef.ValidExcavatorBlocks.contains(mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether an item is a valid hammer
|
||||||
|
* @param mat The material being checked
|
||||||
|
* @return Whether the item is a valid hammer
|
||||||
|
*/
|
||||||
|
public boolean IsHammer(Material mat)
|
||||||
|
{
|
||||||
|
return BlockRef.ValidHammers.contains(mat);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether an item is a valid excavator
|
||||||
|
* @param mat The material being checked
|
||||||
|
* @return Whether the item is a valid excavator
|
||||||
|
*/
|
||||||
|
public boolean IsExcavator(Material mat)
|
||||||
|
{
|
||||||
|
return BlockRef.ValidExcavators.contains(mat);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether a valid hammer can take place
|
||||||
|
* @param ham The item that should be a hammer
|
||||||
|
* @param block The block that should be mineable
|
||||||
|
* @return Valid or invalid action
|
||||||
|
*/
|
||||||
|
public boolean IsHammerable(Material ham, Material block)
|
||||||
|
{
|
||||||
|
return IsMineable(block) && IsHammer(ham);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether a valid excavation can take place
|
||||||
|
* @param exc The item that should be an excavator
|
||||||
|
* @param block The block that should be diggable
|
||||||
|
* @return Valid or invalid action
|
||||||
|
*/
|
||||||
|
public boolean IsExcavatable(Material exc, Material block)
|
||||||
|
{
|
||||||
|
return IsDiggable(block) && IsExcavator(exc);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grabs the surrounding blocks in the world from the one that was mined/dug, and adds them to a list
|
||||||
|
* @param blockFace The face that was targeted (changes the direction of the 3x3 grid)
|
||||||
|
* @param target The block that was targeted
|
||||||
|
* @return A list containing the surrounding blocks
|
||||||
|
*/
|
||||||
|
public static ArrayList<Block> GetSurroundingBlocks(BlockFace blockFace, Block target)
|
||||||
|
{
|
||||||
|
// Create the list to work with
|
||||||
|
ArrayList<Block> blocks = new ArrayList<Block>();
|
||||||
|
|
||||||
|
// Reference the world-space
|
||||||
|
World world = target.getWorld();
|
||||||
|
|
||||||
|
// Determine the anchor XYZ coordinates
|
||||||
|
int x = target.getX();
|
||||||
|
int y = target.getY();
|
||||||
|
int z = target.getZ();
|
||||||
|
|
||||||
|
// Determine the direction of the 3x3 grid
|
||||||
|
switch (blockFace)
|
||||||
|
{
|
||||||
|
case UP:
|
||||||
|
case DOWN: {
|
||||||
|
blocks.add(world.getBlockAt(x + 1, y, z));
|
||||||
|
blocks.add(world.getBlockAt(x - 1, y, z));
|
||||||
|
blocks.add(world.getBlockAt(x, y, z + 1));
|
||||||
|
blocks.add(world.getBlockAt(x, y, z - 1));
|
||||||
|
blocks.add(world.getBlockAt(x + 1, y, z + 1));
|
||||||
|
blocks.add(world.getBlockAt(x - 1, y, z + 1));
|
||||||
|
blocks.add(world.getBlockAt(x + 1, y, z - 1));
|
||||||
|
blocks.add(world.getBlockAt(x - 1, y, z - 1));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case EAST:
|
||||||
|
case WEST: {
|
||||||
|
blocks.add(world.getBlockAt(x, y, z + 1));
|
||||||
|
blocks.add(world.getBlockAt(x, y, z - 1));
|
||||||
|
blocks.add(world.getBlockAt(x, y + 1, z));
|
||||||
|
blocks.add(world.getBlockAt(x, y - 1, z));
|
||||||
|
blocks.add(world.getBlockAt(x, y + 1, z + 1));
|
||||||
|
blocks.add(world.getBlockAt(x, y - 1, z + 1));
|
||||||
|
blocks.add(world.getBlockAt(x, y + 1, z - 1));
|
||||||
|
blocks.add(world.getBlockAt(x, y - 1, z - 1));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case NORTH:
|
||||||
|
case SOUTH: {
|
||||||
|
blocks.add(world.getBlockAt(x + 1, y, z));
|
||||||
|
blocks.add(world.getBlockAt(x - 1, y, z));
|
||||||
|
blocks.add(world.getBlockAt(x, y + 1, z));
|
||||||
|
blocks.add(world.getBlockAt(x, y - 1, z));
|
||||||
|
blocks.add(world.getBlockAt(x + 1, y + 1, z));
|
||||||
|
blocks.add(world.getBlockAt(x - 1, y + 1, z));
|
||||||
|
blocks.add(world.getBlockAt(x + 1, y - 1, z));
|
||||||
|
blocks.add(world.getBlockAt(x - 1, y - 1, z));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
blocks.removeAll(Collections.singleton((Object)null));
|
||||||
|
|
||||||
|
return blocks;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue