Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BlockInterations {
- Main pl;
- public List<Material> blacklist = Lists.newArrayList();
- public BlockInterations(Main plugin) {
- pl = plugin;
- blacklist.add(Material.BEDROCK);
- blacklist.add(Material.END_PORTAL);
- blacklist.add(Material.END_PORTAL_FRAME);
- blacklist.add(Material.NETHER_PORTAL);
- blacklist.add(Material.BARRIER);
- blacklist.add(Material.AIR);
- blacklist.add(Material.CAVE_AIR);
- blacklist.add(Material.VOID_AIR);
- blacklist.add(Material.LAVA);
- blacklist.add(Material.WATER);
- blacklist.add(Material.DRAGON_EGG);
- blacklist.add(Material.END_GATEWAY);
- blacklist.add(Material.SPAWNER);
- }
- public BlockFace getCardinalDirection(Player player) {
- if(player.getLocation().getPitch() <= -45)return BlockFace.DOWN;
- if(player.getLocation().getPitch() >= 45)return BlockFace.UP;
- double rotation = (player.getLocation().getYaw() - 90) % 360;
- if (rotation < 0)rotation += 360.0;
- if (135 <= rotation && rotation < 225)return BlockFace.WEST;
- else if (225 <= rotation && rotation < 315) return BlockFace.NORTH;
- else if (315 <= rotation && rotation < 361) return BlockFace.EAST;
- else if (0 <= rotation && rotation < 45) return BlockFace.EAST;
- else if (45 <= rotation && rotation < 135) return BlockFace.SOUTH;
- else return null;
- }
- public void veinMineBlock(Block b, Player p, int level) {
- List<Block> harvest = Lists.newArrayList();
- List<Block> tested = Lists.newArrayList();
- List<Block> untested = Lists.newArrayList();
- harvest.add(b);
- untested.add(b);
- List<BlockFace> faces = Lists.newArrayList(BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST, BlockFace.NORTH, BlockFace.UP, BlockFace.DOWN);
- while (true) {
- if ((harvest.size() >= 500)) {
- break;
- } else if (untested.size() == 0) {
- break;
- } else {
- List<Block> tempTest = Lists.newArrayList();
- tempTest.addAll(untested);
- for (Block block : tempTest) {
- if (tested.contains(block)) continue;
- for (BlockFace face : faces) {
- Block temp = block.getRelative(face);
- if (temp.getType().equals(b.getType())) {
- if(canBuild(p, b.getLocation().clone())){
- continue;
- }else {
- if (harvest.contains(temp)) continue;
- harvest.add(temp);
- if (!tested.contains(temp)) untested.add(temp);
- }
- }
- continue;
- }
- tested.add(block);
- untested.remove(block);
- }
- }
- }
- ItemStack item = p.getInventory().getItemInMainHand();
- int hunger = 0;
- int maxHunger = 25*level;
- for (Block block : harvest) {
- block.breakNaturally(item);
- if(level == 1) {
- Damageable damageable = (Damageable) item.getItemMeta();
- damageable.setDamage(damageable.getDamage() + 1);
- if (item.getType().getMaxDurability() > damageable.getDamage()) item.setItemMeta((ItemMeta) damageable);
- else {
- p.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
- return;
- }
- }
- if(hunger == maxHunger){
- if(p.getFoodLevel() == 1){
- break;
- }
- p.setFoodLevel(p.getFoodLevel()-1);
- hunger = -1;
- }
- hunger++;
- }
- if(level == 2){
- Damageable damageable = (Damageable) item.getItemMeta();
- damageable.setDamage(damageable.getDamage() + 1);
- if (item.getType().getMaxDurability() > damageable.getDamage()) item.setItemMeta((ItemMeta) damageable);
- else {
- p.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
- return;
- }
- }
- }
- public boolean canBuild(Player p, Location l) {
- if(Main.griefPreventionUse == true)return (GriefPrevention.instance.allowBuild(p, l) != null);
- else return false;
- }
- public List<Location> getHollowCube(Location loc, double particleDistance) {
- List<Location> result = Lists.newArrayList();
- World world = loc.getWorld();
- double minX = loc.getBlockX();
- double minY = loc.getBlockY();
- double minZ = loc.getBlockZ();
- double maxX = loc.getBlockX()+1;
- double maxY = loc.getBlockY()+1;
- double maxZ = loc.getBlockZ()+1;
- for (double x = minX; x <= maxX; x+=particleDistance) {
- for (double y = minY; y <= maxY; y+=particleDistance) {
- for (double z = minZ; z <= maxZ; z+=particleDistance) {
- int components = 0;
- if (x == minX || x == maxX) components++;
- if (y == minY || y == maxY) components++;
- if (z == minZ || z == maxZ) components++;
- if (components >= 2) {
- result.add(new Location(world, x, y, z));
- }
- }
- }
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement