Placing bedrock border around world crashing server

Discussion in 'Plugin Development' started by dajako, Jul 13, 2015.

Thread Status:
Not open for further replies.
  1. I am attempting to place bedrock on the highest block around the a world. I am doing this shortly after it is created and when none of it has been loaded. I have tried loading the chunks when placing the blocks but the server still crashes.

    Here is my code:
    Code:
    public static void setBorder(int r) {
            World w = Bukkit.getWorld("UHCWorld");
            Location loc = new Location(w, 0, w.getHighestBlockYAt(0, 0), 0);
    
            Location locX = loc.add(-r, 0, -r);
            // Location locY = loc.add(-r, 0, -r);
    
            for (locX.getX(); locX.getX() < loc.getX() + r; locX
                    .setX(locX.getX() + 1)) {
                locX.setY(w.getHighestBlockYAt(locX));
                //locX.getChunk().load(true);
                w.getBlockAt(locX).setType(Material.BEDROCK);
    
                w.getBlockAt(
                        new Location(w, locX.getX(), w
                                .getHighestBlockYAt(new Location(w, locX.getX(), 0,
                                        loc.getY() + r)), loc.getY() + r)).setType(
                        Material.BEDROCK);
            }
        }
     
  2. Notice that for realy large radiuses, the bedrock plavcing will take a really LONG time, Are you sure it just crashes instead of laggs/hangs for 30 minutes while its placing the blocks?

    EDIT: your loop is (almost) infinite, you updating your location while looping over it, this will cause your statement of loc.getX() < loc.getX() + r to always stay true, it will only stop near Integer.MAX_VALUE when it overflows
     
  3. I tried it with a radius of 5 to be sure and it still crashes. I'll get a copy of the error if I can.
     
  4. See my updated post
     
    dajako likes this.
  5. How is that near infinite? I don't quite understand?

    BTW, that X coordinate is equal to 0-r
     
  6. Offline

    schwabfl

    Use something like
    Code:
    for (int x = minX; x < maxX; x++) {
        for (/* same with z */) {
            for (/* same with y from 0 to 256 */) {
                // set the block at x, y, z;
            }
        }
    }
    but check first, if minX > maxX or minZ > maxZ
     
Thread Status:
Not open for further replies.

Share This Page