Solved Location management

Discussion in 'Plugin Development' started by CraftCreeper6, Jul 18, 2019.

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

    CraftCreeper6

    Hi there,

    What's the best way to go about placing a 12x12 chunk area in a world, I don't want it to overlap any other players "dedicated areas" but I also don't want to place them at a specific offset, as this can cause problems such as chunks being in straight lines, which if there are hundreds of thousands of people can cause problems.

    I was thinking of some kind of circular graph that I can decipher x and z coordinates off but I'm not sure how to get the chunk boundary from that.
    Another thing I could do is generate two randoms with max double, then check if an island is too close, regenerate the randoms until it finds a location, this could work, but I'm certain this isn't optimised.

    An example could be something like Skyblock, islands are created such that they don't overlap another island, and they aren't in straight lines. So I'm just wondering what the best way to do this is.

    Any help/suggestion is appreciated.
     
    Last edited: Jul 18, 2019
  2. Offline

    Kars

    Chunk corners are located at set intervals. Say chunk 1's top left corner is at 0,0 and chunk 2 is at 16,0. Your chunks are of a different size but you could use this, so "chunk" 2 would be at 12,0 for you.

    Generate a bunch of random numbers and multiply them by the interval (12), then iterate through the area to check if there is something there.
     
  3. Offline

    CraftCreeper6

    @Kars
    So you're suggesting that random numbers is likely the best way to do this? That's fine if so, I just want it to be optimised to prevent lag.
     
  4. Offline

    Kars

    @CraftCreeper6
    You want to generate this chunk of yours in a random location, yes? Then random numbers is the only way to do it. You said you don't want them in a straight line.
     
    CraftCreeper6 likes this.
  5. Offline

    CraftCreeper6

    Decided to go with a type of random.
    Code:
    int random1 = random.nextInt(156236);
                int random2 = random.nextInt(156236);
          
                double xBorder = random1*(16*12);
                double zBorder = random2*(16*12);
    156236 is based on my world border, essentially, divide your world border by 2, then divide it by 16*the number of chunks in a linear direction. I took some away to allow for leniency.

    Then, multiplying by a constant ensures that it will always be a chunk border.

    Thanks for your help @Kars
     
Thread Status:
Not open for further replies.

Share This Page