turt2live

Untitled

Mar 26th, 2012
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1.     public RegionWall getWallLocation(Location location){
  2.         Location min = region.getMinimumPoint();
  3.         Location max = region.getMaximumPoint();
  4.         Location northWall = new Location(world, (min.getX() > max.getX() ? min.getX() : max.getX()), location.getY(), location.getZ());
  5.         Location southWall = new Location(world, (min.getX() > max.getX() ? max.getX() : min.getX()), location.getY(), location.getZ());
  6.         Location eastWall = new Location(world, location.getX(), location.getY(), (min.getZ() > max.getZ() ? min.getZ() : max.getZ()));
  7.         Location westWall = new Location(world, location.getX(), location.getY(), (min.getZ() > max.getZ() ? max.getZ() : min.getZ()));
  8.         double toNorth = Math.abs(northWall.distanceSquared(location));
  9.         double toSouth = Math.abs(southWall.distanceSquared(location));
  10.         double toEast = Math.abs(eastWall.distanceSquared(location));
  11.         double toWest = Math.abs(westWall.distanceSquared(location));
  12.         if(toNorth <= toSouth && toNorth <= toEast && toNorth <= toWest){
  13.             return new RegionWall(Wall.NORTH, northWall);
  14.         }else if(toSouth <= toNorth && toSouth <= toEast && toSouth <= toWest){
  15.             return new RegionWall(Wall.SOUTH, southWall);
  16.         }else if(toEast <= toNorth && toEast <= toSouth && toEast <= toWest){
  17.             return new RegionWall(Wall.EAST, eastWall);
  18.         }else if(toWest <= toNorth && toWest <= toEast && toWest <= toSouth){
  19.             return new RegionWall(Wall.WEST, westWall);
  20.         }
  21.         return null;
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment