Get a random block around the player (x, z)

Discussion in 'Plugin Development' started by stelar7, Sep 25, 2011.

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

    stelar7

    How do i get a random block around the player? on the x,z plane not y..
     
  2. Random random = new Random();

    player.getLocation().getRelative(random.nextInt(5) - 2, 0, random.nextInt(5) - 2);
     
  3. Offline

    stelar7

  4. Because random.nextInt(5) returns a value from 0, 1, 2, 3, 4. You would then only get locations in the positive direction. If you subtract 2, you will get relative locations from -2, -1, 0, 1, 2 from the player, which, combined with Z, can be in a square around him.

    Example:
    Without -2:
    P = player
    X = any block

    --> positive X
    X X X X X
    X X X X X
    P X X X X ^
    X X X X X | positive Z
    X X X X X |

    With -2:
    --> positive X
    X X X X X
    X X X X X
    X X P X X ^
    X X X X X | positive Z
    X X X X X |
     
  5. Offline

    stelar7

    ah, ok...

    Thanks!
     
Thread Status:
Not open for further replies.

Share This Page