Get chunks around players chunk

Discussion in 'Spigot Plugin Development' started by ExtendedHorizons, Jun 21, 2015.

  1. I was wondering if theres a way to get surrounding chunks of the players chunk (Example down bellow 1st comment). Then after getting those chunks do what WorldEdit does with //expand vert. Thanks!

    ~Extended
     
  2. ---
    -+-
    ---
    is what the surrounding chunks look like. Also + is the players chunk
     
  3. Get the chunk's coordinates, then get some new chunks by adding to the coordinates of the original chunk.
     
  4. I understand the concept but im wondering if theres math to do it in a better way then just
    x-1, z
    x+1, z
    x, z-1
    x, z+1

    x-1, z-1
    x+1, z+1
    x+1, z-1
    x-1, z+1
    1 being 16
     
  5. Creeoer

    Supporter

    Use for loops
     
    • Agree Agree x 1
  6. Might wanna tag @bo0tzz
     
  7. This.
     
  8. Make a for loop that will run over coordinates, by that you can get chunks at location, just like my explosive pick plugin!
     
  9. Code (Text):
    public Collection<Chunk> getChunksAroundPlayer(Player player) {
            int[] offset = {-1,0,1}

            World world = player.getWorld();
            int baseX = player.getLocation().getChunk().getX();
            int baseZ = player.getLocation().getChunk().getZ();

            Collection<Chunk> chunksAroundPlayer = new HashSet<>();
            for(int x : offset) {
                for(int z : offset) {
                    Chunk chunk = world.getChunkAt(baseX + x, baseZ + z);
                    chunksAroundPlayer.add(chunk);
                }
            } return chunksAroundPlayer;
        }
     
    • Like Like x 2
    • Agree Agree x 1