Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.58 KB | None | 0 0
  1. public class BlockInterations {
  2.     Main pl;
  3.  
  4.     public List<Material> blacklist = Lists.newArrayList();
  5.  
  6.     public BlockInterations(Main plugin) {
  7.         pl = plugin;
  8.         blacklist.add(Material.BEDROCK);
  9.         blacklist.add(Material.END_PORTAL);
  10.         blacklist.add(Material.END_PORTAL_FRAME);
  11.         blacklist.add(Material.NETHER_PORTAL);
  12.         blacklist.add(Material.BARRIER);
  13.         blacklist.add(Material.AIR);
  14.         blacklist.add(Material.CAVE_AIR);
  15.         blacklist.add(Material.VOID_AIR);
  16.         blacklist.add(Material.LAVA);
  17.         blacklist.add(Material.WATER);
  18.         blacklist.add(Material.DRAGON_EGG);
  19.         blacklist.add(Material.END_GATEWAY);
  20.         blacklist.add(Material.SPAWNER);
  21.     }
  22.  
  23.     public BlockFace getCardinalDirection(Player player) {
  24.         if(player.getLocation().getPitch() <= -45)return BlockFace.DOWN;
  25.         if(player.getLocation().getPitch() >= 45)return BlockFace.UP;
  26.         double rotation = (player.getLocation().getYaw() - 90) % 360;
  27.         if (rotation < 0)rotation += 360.0;
  28.         if (135 <= rotation && rotation < 225)return BlockFace.WEST;
  29.         else if (225 <= rotation && rotation < 315) return BlockFace.NORTH;
  30.         else if (315 <= rotation && rotation < 361) return BlockFace.EAST;
  31.         else if (0 <= rotation && rotation < 45) return BlockFace.EAST;
  32.         else if (45 <= rotation && rotation < 135) return BlockFace.SOUTH;
  33.         else return null;
  34.     }
  35.  
  36.     public void veinMineBlock(Block b, Player p, int level) {
  37.         List<Block> harvest = Lists.newArrayList();
  38.         List<Block> tested = Lists.newArrayList();
  39.         List<Block> untested = Lists.newArrayList();
  40.         harvest.add(b);
  41.         untested.add(b);
  42.         List<BlockFace> faces = Lists.newArrayList(BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST, BlockFace.NORTH, BlockFace.UP, BlockFace.DOWN);
  43.         while (true) {
  44.             if ((harvest.size() >= 500)) {
  45.                 break;
  46.             } else if (untested.size() == 0) {
  47.                 break;
  48.             } else {
  49.                 List<Block> tempTest = Lists.newArrayList();
  50.                 tempTest.addAll(untested);
  51.                 for (Block block : tempTest) {
  52.                     if (tested.contains(block)) continue;
  53.                     for (BlockFace face : faces) {
  54.                         Block temp = block.getRelative(face);
  55.                         if (temp.getType().equals(b.getType())) {
  56.                             if(canBuild(p, b.getLocation().clone())){
  57.                                 continue;
  58.                             }else {
  59.                                 if (harvest.contains(temp)) continue;
  60.                                 harvest.add(temp);
  61.                                 if (!tested.contains(temp)) untested.add(temp);
  62.                             }
  63.                         }
  64.                         continue;
  65.                     }
  66.                     tested.add(block);
  67.                     untested.remove(block);
  68.                 }
  69.             }
  70.         }
  71.         ItemStack item = p.getInventory().getItemInMainHand();
  72.         int hunger = 0;
  73.         int maxHunger = 25*level;
  74.         for (Block block : harvest) {
  75.             block.breakNaturally(item);
  76.             if(level == 1) {
  77.                 Damageable damageable = (Damageable) item.getItemMeta();
  78.                 damageable.setDamage(damageable.getDamage() + 1);
  79.                 if (item.getType().getMaxDurability() > damageable.getDamage()) item.setItemMeta((ItemMeta) damageable);
  80.                 else {
  81.                     p.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
  82.                     return;
  83.                 }
  84.             }
  85.             if(hunger == maxHunger){
  86.                 if(p.getFoodLevel() == 1){
  87.                     break;
  88.                 }
  89.                 p.setFoodLevel(p.getFoodLevel()-1);
  90.                 hunger = -1;
  91.             }
  92.             hunger++;
  93.         }
  94.         if(level == 2){
  95.             Damageable damageable = (Damageable) item.getItemMeta();
  96.             damageable.setDamage(damageable.getDamage() + 1);
  97.             if (item.getType().getMaxDurability() > damageable.getDamage()) item.setItemMeta((ItemMeta) damageable);
  98.             else {
  99.                 p.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
  100.                 return;
  101.             }
  102.         }
  103.     }
  104.  
  105.     public boolean canBuild(Player p, Location l) {
  106.         if(Main.griefPreventionUse == true)return (GriefPrevention.instance.allowBuild(p, l) != null);
  107.         else return false;
  108.     }
  109.  
  110.     public List<Location> getHollowCube(Location loc, double particleDistance) {
  111.         List<Location> result = Lists.newArrayList();
  112.         World world = loc.getWorld();
  113.         double minX = loc.getBlockX();
  114.         double minY = loc.getBlockY();
  115.         double minZ = loc.getBlockZ();
  116.         double maxX = loc.getBlockX()+1;
  117.         double maxY = loc.getBlockY()+1;
  118.         double maxZ = loc.getBlockZ()+1;
  119.  
  120.         for (double x = minX; x <= maxX; x+=particleDistance) {
  121.             for (double y = minY; y <= maxY; y+=particleDistance) {
  122.                 for (double z = minZ; z <= maxZ; z+=particleDistance) {
  123.                     int components = 0;
  124.                     if (x == minX || x == maxX) components++;
  125.                     if (y == minY || y == maxY) components++;
  126.                     if (z == minZ || z == maxZ) components++;
  127.                     if (components >= 2) {
  128.                         result.add(new Location(world, x, y, z));
  129.                     }
  130.                 }
  131.             }
  132.         }
  133.         return result;
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement