Advertisement
Guest User

Untitled

a guest
Dec 25th, 2022
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. /**
  2. * Calculates a random location (based on player location) in certain radius
  3. *
  4. * @param player - target
  5. * @param radius - certain radius
  6. * @return a random location
  7. */
  8. private Location getRandomLocationAroundPlayer(Player player, int radius) {
  9. ThreadLocalRandom random = ThreadLocalRandom.current();
  10.  
  11. Location output = player.getLocation().clone();
  12.  
  13. int randomX = (random.nextBoolean() ? 1 : -1) * random.nextInt(radius);
  14. int randomZ = (random.nextBoolean() ? 1 : -1) * random.nextInt(radius);
  15.  
  16. return output.add(randomX, 0.0D, randomZ);
  17. }
  18.  
  19. /**
  20. * Checks if a place around given location is clear for entity model
  21. *
  22. * @param location - certain location
  23. * @return true if place is clear of false
  24. */
  25. private boolean aroundIsClear(Location location) {
  26. BlockFace[] faces = new BlockFace[] { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH,
  27. BlockFace.WEST, BlockFace.UP };
  28.  
  29. for (BlockFace blockFace : faces) {
  30. Block relative = location.getBlock().getRelative(blockFace);
  31. if (relative.getType() != Material.AIR)
  32. return false;
  33. }
  34.  
  35. return true;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement