Chunk generation spiral pattern

Discussion in 'Plugin Development' started by Josvth, Jan 12, 2012.

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

    Josvth

    Hello everybody,

    I'm trying to make a chunk generation methode that takes a center location and generates all chunks in a square radius around it. I think the best way to do this is in a spiral pattern. So you start with the chunk of the center location and spiral around it.

    Does anybody know a good way to do this? I've tried programming a spiral pattern but it didn't quite work out and it looks messy.
     
  2. Offline

    Nitnelave

    I would do nested for loops :
    pseudo-code :
    Code:
    for i from 1 to (number of layers to generate)
        k = -i
        for j from -i to i
            generate chunks
        j=i
        for k from -i to i
            generate chunks
        k=i
        for j from i to -i
            generate
        j=-i
        for k=i to -i
            generate
    
    that will get you a spiral (a square one, actually)
     
  3. Offline

    ryanhamshire

    You can also see some spiral code in PopulationDensity's source. It assigns players a place to start building in a spiral pattern away from the spawn. See DataStore.findNextRegion().
     
  4. Offline

    Josvth

    Thanks for your replies!

    I've managed to write my own spiral code however.

    Calling this thread closed.
     
  5. Could you post it? I'd be interested to see it.
     
Thread Status:
Not open for further replies.

Share This Page