Water Level Rising

Discussion in 'Programming' started by ZipItCraft, Jun 19, 2016.

  1. Hello, I am making a game where I am trying to rise water level within specific rectangle each 4 seconds.
    Currently I am iterating though the blocks there, checking if their type is not AIR, if so replace them with stationary water, but it is causing terrible lag.

    My current code:
    Code (Text):
                if ((LocationUtilities.instance.decodeLocation("Additional.water-center").getY() + waterlevel) < Main.instance.getConfig().getInt("water-height")) {
                    for (int x = LocationUtilities.instance.decodeLocation("Additional.water-center").getBlockX() + Main.instance.getConfig().getInt("water-to-x"); x >= LocationUtilities.instance.decodeLocation("Additional.water-center").getBlockX() - Main.instance.getConfig().getInt("water-to-x"); x--) {
                        for (int z = LocationUtilities.instance.decodeLocation("Additional.water-center").getBlockZ() + Main.instance.getConfig().getInt("water-to-z"); z >= LocationUtilities.instance.decodeLocation("Additional.water-center").getBlockZ() - Main.instance.getConfig().getInt("water-to-z"); z--) {
                            if (world.getBlockAt(new Location(world, x, ((LocationUtilities.instance.decodeLocation("Additional.water-center").getY() + waterlevel) - 1), z)).getType().equals(Material.AIR)) {
                                world.getBlockAt(new Location(world, x, ((LocationUtilities.instance.decodeLocation("Additional.water-center").getY() + waterlevel) - 1), z)).setType(Material.STATIONARY_WATER);
                            }
                        }
                    }
                    waterlevel++;
                }
    What could be a better way to reduce the lag?

    Thanks.
     
  2. You could try
    Code (Text):

      for (int x = minx; x <= maxx; x++) {
                        for (int y = miny; y <= maxy; y++) {
                            for (int z = minz; z <= maxz; z++) {
                                //set block
                            }
                        }
                    }
     
     
    • Agree Agree x 1