Solved Cuboid question

Discussion in 'Plugin Development' started by L33m4n123, Mar 19, 2014.

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

    L33m4n123

    Hey,

    Couldn't find anything related to that issue. if I somehow missed it though just let me know.

    What I try to achieve is check if a player is in a cuboid. Works semi. Now the issue is, that if I set the Cuboid I get the location of the two corner Blocks that are set [works] Now, however, if you get a Blocks Location its an Integer. So for example

    Corner One Blocks Location: x: 50, y: 10, z: 50
    Corner Two Block Location: x: 30, y:5.0, z:30

    turning those into vectors and check if the Players Location is within these two works semi good.

    Now that it selected ints and not doubles it took the North-West corner of the Block. Thats how Minecraft does the Locations. So if you for example have a cuboid set in a

    5x5 area and then check if the player is in there with my method it only checks in a 4x4. It leaves the south and the east row completely out.

    Now my question is. How would I go ahaed and get the Blocks that are on the South and on the East and still include them in the region check?

    Hope its somewhat understandable what I mean
     
  2. Offline

    Barinade

    int x1=1,x2=100,y1=64,y2=80,z1=1,z2=100;
    for (int x = Math.min(x1,x2); x<=Math.max(x1,x2);x++) {
    //and the same for y/z
    if (x == Math.max(x1,x2) {
    //east wall
    } else if (x == Math.min(x1,x2) {
    //west wall
    }
    }
     
    L33m4n123 likes this.
  3. Offline

    L33m4n123

    Ahh. D'oh. Could have thought about that myself. lol.
     
  4. Offline

    Barinade

    int x,y,z; //player's location
    boolean inCuboid = (x>=Math.min(x1,x2) && x <= Math.max(x1,x2) && y >= Math.min(y1,y2) && y <= Math.max(y1,y2) && z >= Math.min(z1,z2) && z <= Math.max(z1,z2));
     
  5. Offline

    L33m4n123


    Yeah I know how to get if they are in the cuboid. thats working fine. And I use it now a bit different. I use Bukkits Vector class. There I still have to get the max and min location. And just add to the max Location 1 to X and Z value as this is the South East and it works fine
     
Thread Status:
Not open for further replies.

Share This Page