WorldEdit Region regeneration

Discussion in 'Plugin Development' started by Vecox, Dec 5, 2011.

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

    Vecox

    Hey guys,
    I need to utilize a (modified) version of the WorldEdit region regeneration method.This works pretty well but there is one bug I am unable to localize. This bug does occur in the original WE code as well. Sometimes when you regenerate a region there are parts around it that will change. For example villages may appear or holes may be regenerated although they are outside of the region.
    sk89q commented on this bug 4 months ago and marked it as urgent but it is still there. He didn't seem to be too confident about being able to fix it.Here is the original code :
    Code:
     public boolean regenerate(Region region, EditSession editSession) {
            BaseBlock[] history = new BaseBlock[16 * 16 * 128];
    
            for (Vector2D chunk : region.getChunks()) {
                Vector min = new Vector(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16);
    
                // First save all the blocks inside
                for (int x = 0; x < 16; ++x) {
                    for (int y = 0; y < 128; ++y) {
                        for (int z = 0; z < 16; ++z) {
                            Vector pt = min.add(x, y, z);
                            int index = y * 16 * 16 + z * 16 + x;
                            history[index] = editSession.getBlock(pt);
                        }
                    }
                }
    
                try {
                    world.regenerateChunk(chunk.getBlockX(), chunk.getBlockZ());
                } catch (Throwable t) {
                    t.printStackTrace();
                }
    
                // Then restore
                for (int x = 0; x < 16; ++x) {
                    for (int y = 0; y < 128; ++y) {
                        for (int z = 0; z < 16; ++z) {
                            Vector pt = min.add(x, y, z);
                            int index = y * 16 * 16 + z * 16 + x;
    
                            // We have to restore the block if it was outside
                            if (!region.contains(pt)) {
                                editSession.smartSetBlock(pt, history[index]);
                            } else { // Otherwise fool with history
                                editSession.rememberChange(pt, history[index],
                                        editSession.rawGetBlock(pt));
                            }
                        }
                    }
                }
            }
    If a completely different implementation is necessary that won't be any problem as long as it works cleanly :)
     
  2. Offline

    halley

    I imagine it's just a natural (unfortunate) outcome of the "block populator" design. Chunks are generated with one set of algorithms, and then a separate pass is allowed to come in and plant extras like buildings, trees and shrines... on a roughly-similar-but-not-exactly-equal region of the world. It would be challenging to get two separate algorithms to be 100% repeatable even if they used the same random number series. Failing to mask the regions so they're exactly equal just makes it all the more obvious with half-buildings, etc.
     
  3. Offline

    Vecox

    By expanding the region before saving the chunks I was able to get rid of terrain changing. But there are still some parts of villages that appear for example. The reason seems to be what halley said but why does the function above fail to restore the areas where those houses appear? Does ist somehow run after a delay so it places those blocks after I finished regenerating?
     
Thread Status:
Not open for further replies.

Share This Page