Get All Blocks in World

Discussion in 'Spigot Plugin Development' started by ZanderMan9, May 19, 2015.

  1. How do I get all blocks, not just loaded ones, but every single one, in a world? I need to loop through blocks and do replacements (I know there can be serious performance problems here, but don't worry about that.)

    Ideally I'd like to get all chunks, so I can make the loop a little more well threaded. Any pointers in the right direction would be a great help. I've already looked at .getLoadedChunks(), and it seems .getBlocks() doesn't even exist.
  2. Loop through each Chunk c in world.getLoadedChunks.
    Then loop through each block in that loaded chunk.
  3. Did you even read his message..

    @ZanderMan9 I think this can help:

    Code (Text):

    int bx = chunk.getX()<<4;
    int bz = chunk.getZ()<<4;
    World world = event.getWorld();
    for(int xx = bx; xx < bx+16; xx++) {
        for(int zz = bz; zz < bz+16; zz++) {
            for(int yy = 0; yy < 128; yy++) {
                    Block block = world.getBlockAt(xx,yy,zz);
    • Agree Agree x 1
  4. I was afraid I might have to do something like that. What do the << operators do? (Sorry, I'm really more of a C# guy) Also, where am I getting the chunk variable from?
  5. You get the chunk variable from your getLoadedChunks() loop.
    Learn more about the operators here:
  6. getLoadedChunks() doesn't account for the blocks which aren't loaded in does it? Do I maybe need to modify the world file somehow? Or maybe force it to load all the chunks and then loop over them while they're loaded?
  7. Getting all chunks is hard. Maybe check for the event when a new chunk loads ?
    • Agree Agree x 1
  8. well if you really want to, you could read region files
    • Agree Agree x 1
  9. I thought about that, and it COULD work, but it'd be too complicated. I'm just going to skip this part of the project; it isn't essential to the whole thing.
  10. What are you doing anyways? Just listen to the ChunkLoadEvent to change the blocks you want.
  11. I really doubt you want to ignore performance... With 5x5 chunks alone this will likely take more than an hour of processing.
  12. Why do you want each chunk? Maybe it isn't necessary.