Get all blocks in a chunk

Discussion in 'Plugin Development' started by scarabcoder, Sep 11, 2014.

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

    scarabcoder

    Hey guys,
    I am trying to create a plugin that refills chests in a given area. I am able to get all the Chunks in a specified area, but the Chunk class has no 'getBlocks[]' method. How would I go about looping through an entire chunk? Or, if it would be easier, how would I loop through all the blocks in a given area?
     
  2. scarabcoder
    Hey. The easiest way would be to use a shift operator to get the corners of the chunk, then loop through all the blocks between x and x + 16, because 16 is the chunk size. Same thing for z:
    Code:java
    1. int x = chunk.getX() << 4;
    2. int z = chunk.getZ() << 4;
    3.  
    4. World world = chunk.getWorld();
    5.  
    6. for(int xx = x; xx < x + 16; xx++) {
    7. for(int zz = z; zz < z + 16; zz++) {
    8. for(int yy = 0; yy < 256; yy++) {
    9. Block block = world.getBlockAt(xx, yy, zz);
    10. // stuff
    11. }
    12. }
    13. }
     
  3. Offline

    fireblast709

    Assist Orrrrrrr... you just use the chunk and local chunk coordinates (0 till 15 for x and z, 0 till (worldheight - 1) for y)
     
    Garris0n likes this.
Thread Status:
Not open for further replies.

Share This Page