Solved Large area block iteration

Discussion in 'Plugin Development' started by CraftCreeper6, Jul 17, 2019.

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

    CraftCreeper6

    Hi there, I'm working on clearing a 12 chunk x 12 chunk, floor to sky limit, completely clearing.

    I've managed to implement some lag prevention and I must say it's working great. There's just a few problems, when looping over all the blocks and adding them to a queue that will be executed later, I noticed that some blocks don't get added.

    Here's a screenshot of what I mean.
    [​IMG]
    (https://imgur.com/a/LdDIEDm)

    The code for the removal of blocks is as follows:
    Code:
    for (int x = xBorder-chunkAllowance; x < (xBorder + 16)+chunkAllowance; x++)
            {
                for (int z = zBorder-chunkAllowance; z < (zBorder + 16)+chunkAllowance; z++)
                {
                    for (int y = 0; y < 257; y++)
                    {
                        Block block = world.getBlockAt(new Location(world, x, y, z));
                        if (block.getType() != Material.AIR)
                        {
                       
                            if (block.getType() == Material.CHEST)
                            {
                                Chest c = (Chest) block.getState();
                           
                                c.getInventory().clear();
                            }
                       
                            this.addToQueue(Material.AIR, x, y, z);
                        }
                        count++;
                    }
                }
            }
    I have done several debugs and figured out that they are never added to the queue.

    I suppose I've narrowed it down to that for loop, it could be due to lag, but even severely increasing the interval at which blocks are placed does not prevent this.

    Any help is appreciated.

    EDIT: I lied (unintentionally), I just retested the queue and it DOES contain the blocks. And I also figured out the issue, when I break the block, I check that I should be breaking it (between the interval), whilst also popping from the queue, this is wrong. I should first check that it is between the interval and THEN pop from the queue.

    Good example of the phrase,
    The moment you tell someone else about a problem, you'll immediately understand it yourself.

    SOLVED.
     
    Last edited: Jul 17, 2019
  2. Offline

    Kars

    @CraftCreeper6 Excuse me but, since you mentioned wanting to be as efficient as possible.

    You are wasting performance iterating over every block that exists. You can decrease the Y axis iteration by an undetermined amount by using getHighestBlockAt.

    Just thought i'd let you know.

    Edit:
    Nevermind, it only considers transparent blocks.
     
Thread Status:
Not open for further replies.

Share This Page