[SOLVED] How do I force a chunk to populate?

Discussion in 'Plugin Development' started by Courier, Sep 8, 2012.

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

    Courier

    When you load a chunk which doesn't exist, the chunk will be generated. However, it is not populated until a player walks near it. How can I force the chunk to populate immediately? This needs to work with the default generator as well as custom generators.
     
  2. Offline

    Courier

  3. I want to know that, too. Especially as I need to re-populate chunks. ^^
     
  4. Offline

    Courier

    I figured out a way to do it, at least with default worlds. I don't know if it works for Bukkit generators, but if it doesn't, they should be pretty simple.


    Here is the code:
    Code:java
    1. //[plain]
    2. /**
    3.  * I'm not sure what this will do if the chunk is already populated.
    4.  * @author Courier <[email protected]>
    5.  * @param world The world the chunk is in
    6.  * @param x The x coordinate of the chunk
    7.  * @param z The z coordinate of the chunk
    8.  */
    9. private static void populateChunk(World world, int x, int z)
    10. {
    11. net.minecraft.server.WorldServer nmsWorld = ((CraftWorld)world).getHandle();
    12. net.minecraft.server.ChunkProviderServer nmsChunkProviderServer = nmsWorld.chunkProviderServer;
    13. for(int cx = x - 1; cx <= x + 1; cx++)
    14. for(int cz = z - 1; cz <= z + 1; cz++)
    15. nmsChunkProviderServer.getChunkAt(cx, cz);
    16. nmsChunkProviderServer.getChunkAt(nmsChunkProviderServer, x, z);
    17. }
    18. //[/plain]
     
  5. Offline

    MoonStorm

Thread Status:
Not open for further replies.

Share This Page