Does world.getBiome generate chunks? (Is this the right way to find a biome?)

Discussion in 'Plugin Development' started by Pokechu22, May 6, 2015.

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

    Pokechu22

    I'm trying to find the location of a specified biome in a world. Is the following code a good way to do it, or is calling World.getBiome going to generate a bunch of chunks along the way and make a giant mess? (Imagine cases of searching for MUSHROOM_ISLAND with this -- that checks several hundred thousand blocks in some cases).

    Code:
    public Location findBiome(Biome biome, World world) {
        int x = 0;
        int z = 0;
       
        while (world.getBiome(x, z) != biome) {
            x++;
            z++;
        }
       
        return new Location(world, x, world.getHighestBlockYAt(x, z) + 4, z);
    }
    Thanks.
     
  2. Offline

    Skionz

    @Pokechu22 So you are just trying to get the first biome? Right now you are checking each chunk diagonally which eventually would work, but you are probably going to miss a closer biome. You could check each biome by going around the edge of a square of chunks.
     
  3. Offline

    Pokechu22

    @Skionz Yes, that's what I'm doing. I can see going around in a square being faster, but I'm not sure if it actually would be. (Probably, the only way to test this is to just to try both algorithms and see which is faster on average). I feel like doing a square would capture more redundant biomes, since it'll run lines thru the same area twice.

    Maybe a large grid would work instead.

    Of course, the most important question here is whether or not I need to optimize for generating the fewest chunks. As it stands, I'm pretty sure it doesn't, since the map still had to generate itself when I teleported to the distant location where the biome was found, but I'm not sure.
     
  4. Offline

    Skionz

    Going in a square will be more accurate, but less efficient. If you just go diagonally, you are going to miss a lot of biomes.
     
Thread Status:
Not open for further replies.

Share This Page