Solved Manipulating blocks in unloaded chunks

Discussion in 'Plugin Development' started by Jogy34, Nov 17, 2013.

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

    Jogy34

    For one of my plugins I'm essentially teleporting a structure around however if the location that I'm supposed to build it is in an unloaded chunk, it won't build it and on the other end if when I move it, it's in an unloaded chunk I can't destroy it. I do attempt to load the chunk before I manipulate any blocks.

    I don't want to post code as most of what you would see doesn't have anything to do with the problem but this is essentially what I'm doing:

    Code:java
    1.  
    2. //both
    3. loc.getChunk().load(true); //loc is the location that I need to build the structure
    4. //And, as you can see, I am trying to load the chunk before manipulating any blocks
    5.  
    6. int x = loc.getBlockX();
    7. int y = loc.getBlockY();
    8. int z = loc.getBlockZ();
    9.  
    10. //building
    11. world.getBlock(x + something, y + something, z + something).setTypeIdAndData(id, data, false);
    12.  
    13. //destroying
    14. world.getBlock(x + something, y + something, z + something).setTypeId(0, false);
    15.  
    16. //There are a bunch of one of the lines above to build the entire structure but they all use the same format
     
  2. Offline

    the_merciless

    My guess would be that you need to build the structure in the chunk load event. So use loc.getChunk().load(true); and save that chunk as a variable or in a map or something. Then on the chunkLoadEvent check if the chunk being loaded matches and build the structure.
     
  3. Offline

    Jogy34

    I don't think that when chunk.load() is called that it calls a ChunkLoadEvent.
     
  4. Offline

    the_merciless

    The chunkLoadEvent is called when the chunk finishes loading
     
  5. Offline

    Jogy34

    I started searching through the craftbukkit code to see if the ChunkLoadEvent is still called even when a chunk doesn't load naturally through a chunk.load(true); call and I noticed that when you tell it not to generate the chunk it does something completely differently (I had previously thought that it would generate the chunk and then do whatever else it did when you didn't tell it to generate). I tried putting a false in the load method instead of a true and it worked some how.
     
  6. Offline

    the_merciless

  7. Offline

    Jogy34

Thread Status:
Not open for further replies.

Share This Page