Check if a player is in a cuboid

Discussion in 'Resources' started by Developing, Dec 8, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Developing

    I thought this might come in handy and hence i posted it.

    Note: I found this when i was browsing through the forums. The code does not belong to me.

    Check if player is in a cuboid:
    Code:java
    1. public boolean checkCuboid(Player player, Block block1, Block block2)
    2. {
    3. checkCuboid(player.getLocation(), block1.getLocation(), block2.getLocation());
    4. }
    5. public boolean checkCuboid(Location checkLoc, Location loc1, Location loc2)
    6. {
    7.  
    8.  
    9. int x1 = Math.min(loc1.getX(), loc2.getX());
    10. int y1 = Math.min(loc1.getY(), loc2.getY());
    11. int z1 = Math.min(loc1.getZ(), loc2.getZ());
    12.  
    13.  
    14. int x2 = Math.min(loc1.getX(), loc1.getX());
    15. int y2 = Math.min(loc1.getY(), loc1.getY());
    16. int z2 = Math.min(loc1.getZ(), loc1.getZ());
    17.  
    18. double cx = checkLoc.getX();
    19. double cy = checkLoc.getY();
    20. double cz = checkLoc.getZ();
    21. return (cx > x1 && cx < x2 && cy > y1 && cy < y2 && cy > z1 && cz < z2);
    22. }
     
Thread Status:
Not open for further replies.

Share This Page