turt2live

Untitled

Mar 27th, 2012
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.07 KB | None | 0 0
  1. public RegionWall getFaceLocation(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.     Location ceil = new Location(world, location.getX(), (min.getY() > max.getY() ? min.getY() : max.getY()), location.getZ());
  9.     Location floor = new Location(world, location.getX(), (min.getY() > max.getY() ? max.getY() : min.getY()), location.getZ());
  10.     double toNorth = Math.abs(northWall.distanceSquared(location));
  11.     double toSouth = Math.abs(southWall.distanceSquared(location));
  12.     double toEast = Math.abs(eastWall.distanceSquared(location));
  13.     double toWest = Math.abs(westWall.distanceSquared(location));
  14.     double toFloor = Math.abs(floor.distanceSquared(location));
  15.     double toCeil = Math.abs(ceil.distanceSquared(location));
  16.     if(toNorth <= toSouth && toNorth <= toEast && toNorth <= toWest){
  17.         return new RegionWall(Wall.NORTH, northWall);
  18.     }else if(toSouth <= toNorth && toSouth <= toEast && toSouth <= toWest){
  19.         return new RegionWall(Wall.SOUTH, southWall);
  20.     }else if(toEast <= toNorth && toEast <= toSouth && toEast <= toWest){
  21.         return new RegionWall(Wall.EAST, eastWall);
  22.     }else if(toWest <= toNorth && toWest <= toEast && toWest <= toSouth){
  23.         return new RegionWall(Wall.WEST, westWall);
  24.     }else if(toCeil <= toNorth && toCeil <= toEast && toCeil <= toWest && toCeil <= toFloor && toCeil <= toSouth){
  25.         return new RegionWall(Wall.CEILING, ceil);
  26.     }else if(toFloor <= toNorth && toFloor <= toEast && toFloor <= toWest && toFloor <= toCeil && toFloor <= toSouth){
  27.         return new RegionWall(Wall.FLOOR, floor);
  28.     }
  29.     return null;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment