How many chunks can minecraft generate simultaneously?

Discussion in 'Plugin Development' started by alu-, Jan 10, 2014.

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


    I've loaded like 2000 chunks, but it looks like only some of them are generating. Are there some rules to forcing chunks to generate?
  2. Offline


    Bukkit will generate chunks inside async threads and load them inside next main thread tick.

    To answer your question more "directly" i wil ask you to post code used to load chunks, probably it have some flaw.
    Also loading 2000 chunks will require more then 5gb of ram.
  3. Offline


    I'm going to post the complete code when I get off work. This is basically what I'm doing:
    1. Create a new world
    2. Chunk c = world.getChunkAt()
    3. c.load(true)

    Only one or two region files are growing, then they all just stops. world.getLoadedChunks still reports all chunks as being loaded thou.
    This has been tested with Bukkit RB, BukkitBeta and Spigot. No plugins except the one I wrote.
    I'm thinking I'm loading chunks to fast, could this be the cause of the stall?
  4. Offline


    chunk generation consume time, you can't have all chunks loaded instantly.
  5. Offline


    Yes, this is what I have surmised as well. So, how many chunks can one load before the new, or old, chunks skip generation?
  6. Offline


    For 2000? I doubt it. Regardless, that's not what will hold you back, it's the cpu power needed to generate and process them all.
  7. Offline


    RawCode this is my code. It produces 484 region files in a few seconds. One file is at ~2MB, one at ½MB and the rest at like 16-24KB.

    1. this.sWorldName = "World-" + (System.currentTimeMillis() / 1000L);
    3. // Create new world
    4. World newWorld = this.server.createWorld(new WorldCreator(sWorldName).environment(World.Environment.NORMAL).generateStructures(true));
    6. // Load and generate chunks
    7. int minX = 0 - 1 - 320;
    8. int minZ = 0 - 1 - 320;
    9. int maxX = 0 + 17 + 320;
    10. int maxZ = 0 + 17 + 320;
    11. Chunk c;
    12. for (int sx = minX; sx < maxX; sx += 16) {
    13. for (int sz = minZ; sz < maxZ; sz += 16) {
    14. c = newWorld.getChunkAt(sx, sz);
    15. if (c.load(true) == false) {
    16. this.logger.warning("Could not load/generate chunk " + sx + "," + sz + " on world " + this.sWorldName);
    17. }
    18. }
    19. }
    20. c = null;

    The process will indeed take memory and processing power. This is not an issue thou. I can wait the time it takes, although I want the process to be as short as possible. Hence the initial question.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 6, 2016
  8. Offline


    Garris0n alu-

    There is no way to speedup process without changing bukkit code.
    Best way to pregenerate world is to alter bukkit worldpreinit section (part of code related to generation of area around spawn) and set spawn area to very large value.

    In this case server wont do anything else, only world generation.

    method for this located inside
    protected void g()@MinecraftServer.class
  9. Offline


    That's one way of doing it, sure. But my world generation is stalling, completely. I'm looking into using NMS classes to check if the chunks have been generated, and if not generate them. First part is complete, other part not so much. :)
  10. Offline


    dont generate all chunks at same moment, it wont fly no matter how good your code is.

    also some debug output will help.
  11. Offline


    I'm going to store all ungenerated chunks, then trigger x amount of generation, and when they are done trigger more.
    Not being a java dev kinda hurts thou. Going thru github/craftbukkit/nms and MCP kinda led me towards ChunkProviderServer. Any input would greatly be appreciated.
  12. Offline


    1. public void Sector_Force(int ID){
    3. //Делим координаты на 16 сразу
    4. int x = ID / 1000 * 10;
    5. int z = ID % 1000 * 10;
    7. //Использование внутреннего кода может быть не обязательно
    8. //Будет проверено позже, но это явно лучше чем 100500 обёрток
    9. MinecraftServer S = MinecraftServer.getServer();
    10. WorldServer W = S.worlds.get(0);
    12. //нам не требуется заполнять весь сектор, только 9 чанков, остров и вокруг.
    13. for (int a = 1; a <= 4; a += 1) {
    14. for (int b = 1; b <= 4; b += 1) {
    15. W.chunkProviderServer.getChunkAt(x + a, z + b);
    16. }}
    17. }

    This code from my private plugin, it used to generate areas of world 3*3 chunks at arbitrary coordinates, chaning logic a bit will allow to generate larger area if required.

    this is pure NMS with minimal overhead.
  13. Offline


    Also keep in mind generating a chunk is just part of the process.
    Every chunk needs to be populated with ores, trees and other objects.
    This populationstep needs its time or you end up with an empty world.
Thread Status:
Not open for further replies.

Share This Page