Way to Speed up Generating Structures

Discussion in 'Spigot Plugin Development' started by Kori88, May 19, 2016.

  1. I'm making a plugin that will be frequently generating a large number of blocks in the Sky in a single tick. I'm currently doing some stress testing by generating cubes of various sizes.

    The following code (generates a 100x2x100 cube) takes so long I time out before it even finishes:
    Code (Text):
         
            for (int blockIndexX = 0; blockIndexX < 100; blockIndexX++)
            {
                for (int blockIndexY = 0; blockIndexY < 2; blockIndexY++)
                {
                    for (int blockIndexZ = 0; blockIndexZ < 100; blockIndexZ++)
                    {
                            Location currentLocation = player.getLocation();
                            currentLocation.add(blockIndexX, blockIndexY, blockIndexZ);
                            currentLocation.getBlock().setType(Material.COBBLESTONE);
                    }
                }
            }
     
    However, this code (a 100x100x2 cube), that updates the same number of blocks, finishes in less than a second:
    Code (Text):
         
            for (int blockIndexX = 0; blockIndexX < 100; blockIndexX++)
            {
                for (int blockIndexY = 0; blockIndexY < 100; blockIndexY++)
                {
                    for (int blockIndexZ = 0; blockIndexZ < 2; blockIndexZ++)
                    {
                            Location currentLocation = player.getLocation();
                            currentLocation.add(blockIndexX, blockIndexY, blockIndexZ);
                            currentLocation.getBlock().setType(Material.COBBLESTONE);
                    }
                }
            }
     
    I'm assuming this has something to do with Minecraft updating every block underneath a new block with stuff like lighting, blocking rain etc., so wider structures take much longer to generate. This is supported by the fact that the 100x2x100 cube gets created much faster if the player is on flat ground. Is there any way I can prevent Minecraft from making these updates or am I out of luck on this one?

    Edit: The structure gets generated instantly if I used glass instead of cobblestone.
    Edit2: The amount of time it takes to generate gets progressively longer the farther from the ground it is created.
     
    #1 Kori88, May 19, 2016
    Last edited: May 19, 2016