How can I ensure a chunk is loaded/generated before changing blocks in it

Discussion in 'Plugin Development' started by majinnaibu, Aug 30, 2014.

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

    majinnaibu

    I'm building things at coordinates that might not have been loaded/generated yet. How can I ensure the chunk is ready for me to start changing blocks before I do so?

    If I do nothing and the chunk hasn't generated yet and I place stone or grass, when the chunk does generate stone might become ore or be removed, and grass might have stuff growing on it (ferns, tall grass, flowers trees, ...).
     
  2. Offline

    dchaosknight

  3. Offline

    majinnaibu

    Thanks for the links. Now I feel stupid because I was looking through the javadocs and didn't see that method.

    Update: It's not quite working the way I'd hoped. I call chunk.load(true) and it returns true then I call block.setType(Material.AIR) and when I go to the chunk in the world some of the air blocks are trees and flowers. Most of the blocks I'm setting stay (grass, cobblestone, stone), but sometimes the grass and stone get replaced by sand, air, or ores.

    I do this for each block x and z. I'm writing a column from y=62 to y=127.
    Code:java
    1. Block block = world.getBlockAt(x, y, z);
    2. Chunk chunk = world.getChunkAt(block);
    3. if(!chunk.isLoaded()){
    4. if(!chunk.load(true)){
    5. log.severe("Failed to load a chunk");
    6. }
    7. }
    8.  
    9. //Set the block data
    10.  


    I assume the chunks will be unloaded as needed and that I shouldn't need to force unload them before a player enters one.
     
Thread Status:
Not open for further replies.

Share This Page