Claiming chunks around a chunk

Discussion in 'Plugin Development' started by xXMaTTHDXx, Jul 29, 2014.

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

    xXMaTTHDXx

    If the title doesnt make sense ill try yo explain it better, if I have 1 chunk, I want to claim or save they x and z's of the chunks around it 3x3 chunks I have the core chunk then I want to create a 3x3 chunks around it.
     
  2. Offline

    Chiller

    xXMaTTHDXx

    Why not just use some simple math?

    leftTop = world.getChunkAt(chunk.getX() - 1, chunk.getZ() - 1);
    leftMiddle = world.getChunkAt(chunk.getX() - 1, chunk.getZ());
    leftBottom = world.getChunkAt(chunk.getX() - 1, chunk.getZ() + 1);

    middleTop = world.getChunkAt(chunk.getX(), chunk.getZ() - 1);
    middleBottom = world.getChunkAt(chunk.getX(), chunk.getZ() + 1);

    rightTop = world.getChunkAt(chunk.getX() + 1, chunk.getZ() - 1);
    rightMiddle = world.getChunkAt(chunk.getX() + 1, chunk.getZ());
    rightBottom = world.getChunkAt(chunk.getX() + 1, chunk.getZ() + 1);

    xXMaTTHDXx

    Or if you only need the surrounding chunks and don't need to know which is which use a for loop

    Code:java
    1. for (int x = -1; x <= 1; x++)
    2. {
    3. for (int z = -1; z <= 1; z++)
    4. {
    5. Chunk chunk = world.getChunkAt(origChunk.getX() + x, origChunk.getZ() + z);
    6. }
    7. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  3. If you can get a Location from within the center chunk you can add/subtract 16 to the X/Z values of that Location and then use the new Location to grab the surrounding chunks. For example, add 16 to the X of the original Location and grab the chunk at the new location. Then add 16 to the X and Z of the original Location and grab the chunk at that Location. Then just add 16 to the Z of the original Location and grab the chunk at that Location.

    I'm not going to go through all eight of the chunks but if you don't get the idea I can elaborate.
     
  4. Offline

    xXMaTTHDXx

    Thanks guys! ill be sure to use whichever fits best with my code, ill try it out shortly.
     
Thread Status:
Not open for further replies.

Share This Page