Get all blocks in new chunk

Discussion in 'Plugin Development' started by darkmage0252, Feb 1, 2012.

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

    darkmage0252

    How would i go about getting all the blocks in a newly generated chunk?
     
  2. Offline

    Kierrow

    If you attempt this, you would have to listen to a ChunkPopulateEvent.
    Structure your code like this:

    Code:
    @EventHandler
    public void onChunkPopulate(ChunkPopulateEvent event) {
        Chunk chunk = event.getChunk();
        for (int x = 0; x < 16; x++) {
            for (int z = 0; z < 16; z++) {
                for (int y = 0; y < 128; y++) {
                    Block current = chunk.getBlock(x, y, z);
                    //this gives you every block...
                }
            }
        }
    }
    I though would not recommend this method as it would probably take the world generator quite some time
    longer to generate the world, of course, depending on what you are actually doing with the chunk.

    I hope this helps.
     
  3. Offline

    Roadkill909

    Oh god, the magnitude of computation. Whatever you're doing, be as efficient as possible inside those for loops, or your plugin will cause world gens to take minutes as opposed to seconds, and will lower overall server performance.
     
Thread Status:
Not open for further replies.

Share This Page