Safe Y at X,Z

Discussion in 'Plugin Development' started by LRFLEW, Jul 26, 2011.

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

    LRFLEW

    I used to know this, but now that I need it, I can't find it. How do I find the safe hight (Y) at a position (X,Z). By safe, I mean the greatest Y value that's over a block. I could create my code to do this myself, but I was certain that there was something in the API that did it for me. Any help?
     
  2. Code:
    world.getHighestBlockAt(int x, int z)
    // or
    world.getHighestBlockAt(Location loc)
    I believe that's what you are looking for ;)
     
  3. Offline

    LRFLEW

    thanks

    Actually, I thought there was one that gave a location :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
  4. Code:
    new Location(world, x, world.getHighestBlockAt(x,z), z)
    
    should work for that
     
  5. Offline

    LRFLEW

    you mean
    Code:
    new Location(world, x, world.getHighestBlockYAt(x,z), z);
     
  6. Offline

    DrBowe

    It would be getHighestBlockYAt(x, z)
    EDIT:
    Ninja'd by the OP himself ;)

    Also, bear in mind that this will completely disregard caves, or other large openings underground.
     
  7. Offline

    Zalastri

    Do you have a way that won't disregard caves? I'd like to have a terrain generator set features WITHIN a cave, so the lowest y value that is useable would be preferable. Or the first air space from the bottom.
     
  8. Offline

    LRFLEW

    I don't think there's anything in the api that can do it, but you can use a variant of what I would have used had there not been an api for what I wanted.

    This function will find the lowest air block in a world. (note, this may or not be a cave. It could be the ground if there is no caves there) You may want one to find ALL caves :)
    Code:
        public int firstAir (World w, int x, int z) {
            for (int i = 0; i < 128; i++)
                if (w.getBlockTypeIdAt(x, i, z) == 0)
                    return i;
            return -1;
        }
     
Thread Status:
Not open for further replies.

Share This Page