Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-5573

Load chunk takes 7 to 8 seconds and generates hundreds of chunks with custom world generator

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • None
    • None
    • This server is running CraftBukkit version git-Spigot-c574e08-d171d7e (MC: 1.15.2) (Implementing API version 1.15.2-R0.1-SNAPSHOT)
    • Yes

      Chunk loading of ungenerated chunks for a flat, void world is taking a huge amount of time (7 to 10 seconds) and blocks the server. This occurs with the recent 1.15.2 builds and does not occur on earlier versions. It appears to be due to the server generating hundreds of chunks as a result of trying to load just one of them.

      Please see the attached test plugin and source. The output of the console is:

      [19:09:55] [Server thread/INFO]: Trying to load chunk at Location{world=CraftWorld{name=test_the_end},x=102122.0,y=120.0,z=105098.0,pitch=0.0,yaw=0.0}
      [19:10:04] [Server thread/INFO]: Chunk took 9040ms to load and 525 chunks were generated in the process
      [19:10:04] [Server thread/INFO]: Block took 0ms to set
      [19:10:04] [Server thread/INFO]: Starting
      [19:10:04] [Server thread/INFO]: Trying to load chunk at Location{world=CraftWorld{name=test_the_end},x=107711.0,y=120.0,z=106458.0,pitch=0.0,yaw=0.0}
      [19:10:13] [Server thread/INFO]: Chunk took 8914ms to load and 525 chunks were generated in the process
      [19:10:14] [Server thread/INFO]: Block took 450ms to set
      [19:10:14] [Server thread/INFO]: Starting
      [19:10:14] [Server thread/INFO]: Trying to load chunk at Location{world=CraftWorld{name=test_the_end},x=108275.0,y=120.0,z=107997.0,pitch=0.0,yaw=0.0}
      [19:10:22] [Server thread/INFO]: Chunk took 8341ms to load and 491 chunks were generated in the process
      [19:10:22] [Server thread/INFO]: Block took 0ms to set
      [19:10:22] [Server thread/INFO]: Starting
      [19:10:22] [Server thread/INFO]: Trying to load chunk at Location{world=CraftWorld{name=test_the_end},x=101562.0,y=120.0,z=109116.0,pitch=0.0,yaw=0.0}
      [19:10:31] [Server thread/INFO]: Chunk took 8825ms to load and 525 chunks were generated in the process
      [19:10:31] [Server thread/INFO]: Block took 0ms to set

      In the test plugin I picked the End world to test, but it can occur in the Nether or Overworld too.

      Am I doing anything wrong in terms of generating these worlds? Do you have any idea why loading one chunk causes the server to go and generate such huge numbers of chunks? Is it looking for something?

      Here's the source of the onEnable for quick reference:

          @Override
          public void onEnable() {
              // Create worlds
              Bukkit.getLogger().info("Creating/loading worlds");
              createWorlds();
              Bukkit.getLogger().info("Worlds created");
              Random rand = new Random();
              // Wait 10 seconds so everything loads and then run every 3 seconds
              Bukkit.getScheduler().runTaskTimer(this, () -> {
                  chunkCount = 0;
                  Bukkit.getLogger().info("Starting");            
                  World world = endWorld;
                  // Pick a random location that probably hasn't been generated before
                  Location loc = new Location(world, rand.nextInt(10000) + 100000, 120, rand.nextInt(10000) + 100000);
                  long timer = System.currentTimeMillis();
                  Bukkit.getLogger().info("Trying to load chunk at " + loc);
                  loc.getChunk().load();
                  long chunkLoadTime = System.currentTimeMillis();
                  Bukkit.getLogger().info("Chunk took " + (chunkLoadTime - timer) + "ms to load and " + chunkCount + " chunks were generated in the process");            
                  loc.getBlock().setType(Material.BEDROCK);
                  Bukkit.getLogger().info("Block took " + (System.currentTimeMillis() - chunkLoadTime) + "ms to set");
              }, 200L, 60L);
          }
          
          public void createWorlds() {
              overWorld = WorldCreator.name(worldName).type(WorldType.FLAT).environment(Environment.NORMAL).generator(chunkGen).createWorld();
              netherWorld = WorldCreator.name(worldName + "_nether").type(WorldType.FLAT).environment(Environment.NETHER).generator(chunkGen).createWorld();
              endWorld = WorldCreator.name(worldName + "_the_end").type(WorldType.FLAT).environment(Environment.THE_END).generator(chunkGen).createWorld();
          }
      

      Thanks!

            Unassigned Unassigned
            tastybento tastybento
            Votes:
            6 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: