Get surrounding chunks

Discussion in 'Plugin Development' started by libraryaddict, Sep 17, 2012.

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

    libraryaddict

    Code:
    Player p = event.getPlayer();
          Chunk chunk = p.getWorld().getChunkAt(p.getLocation());
          EntityPlayer player = ((CraftPlayer) p).getHandle();
          for (int i = -16; i <= 16; i = i + 16) {
            for (int a = -16; a <= 16; a = a + 16) {
              chunk = p.getWorld().getChunkAt(p.getLocation().getBlockX() + i,
                  p.getLocation().getBlockZ() + a);
              player.chunkCoordIntPairQueue.add(new ChunkCoordIntPair(chunk.getX(),
                  chunk.getZ()));
            }
          }
    So for some reason or another, this doesn't work.
    Could someone explain why and how I should do it?
     
  2. Offline

    Courier

    I believe getChunkAt accepts the coordinate of the chunk, so the chunk that is blocks 16-31 is called chunk 1.
     
  3. Offline

    desht

    That is indeed correct - you need chunk co-ordinates, not block co-ordinates. Divide by 16 or bit-shift by 4, e.g.:
    PHP:
    chunk p.getWorld().getChunkAt((p.getLocation().getBlockX() + i) >> 4,
                  (
    p.getLocation().getBlockZ() + a) >> 4);
     
  4. Offline

    libraryaddict

    Thanks :D
     
Thread Status:
Not open for further replies.

Share This Page