package com.ForgeEssentials.WorldBorder;

import net.minecraft.util.MathHelper;
import net.minecraft.world.WorldServer;

import com.ForgeEssentials.util.Localization;

/**
 * Does the actual filling, with limited chuncks per tick.
 * 
 * @author Dries007
 * 
 */

public class TickTaskFillRound extends TickTaskFill
{
	public TickTaskFillRound(WorldServer world)
	{
		isComplete = false;
		this.world = world;
		X = minX = ModuleWorldBorder.minX - ModuleWorldBorder.overGenerate;
		Z = minZ = ModuleWorldBorder.minZ - ModuleWorldBorder.overGenerate;
		maxX = ModuleWorldBorder.maxX + ModuleWorldBorder.overGenerate;
		maxZ = ModuleWorldBorder.maxZ + ModuleWorldBorder.overGenerate;
		centerX = ModuleWorldBorder.X;
		centerZ = ModuleWorldBorder.Z;
		rad = ModuleWorldBorder.rad;

		eta = ((MathHelper.abs_int((maxX - minX) / 16) * MathHelper.abs_int((minZ - maxZ) / 16)));

		warnEveryone(Localization.get(Localization.WB_FILL_START));
		warnEveryone(Localization.get(Localization.WB_FILL_ETA).replaceAll("%eta", getETA()));
	}

	@Override
	public void tick()
	{
		super.tick();

		int i = 0;
		while (i < chunksAtick && !isComplete)
		{
			if ((rad + ModuleWorldBorder.overGenerate) < ModuleWorldBorder.getDistanceRound(centerX, centerZ, X, Z))
			{
				if(!world.theChunkProviderServer.chunkExists((X >> 4), (Z >> 4)))
				{
					i++;
					world.theChunkProviderServer.provideChunk((X >> 4), (Z >> 4));
					world.theChunkProviderServer.unloadChunksIfNotNearSpawn((X >> 4), (Z >> 4));
					world.theChunkProviderServer.unload100OldestChunks();
				}
				
				if (X <= maxX)
				{
					X += 16;
				}
				else
				{
					// New row!
					if (Z <= maxZ)
					{
						Z += 16;
						X = minX;
					}
					else
					{
						// Done!
						isComplete = true;
					}
				}
			}
		}
	}
}

@@ -1552,11 +1552,10 @@
 %0A%09%09%09
-%09%0A%09
+%7D%0A
 %09%09%09i
@@ -1568,17 +1568,16 @@
 = maxX)%0A
-%09
 %09%09%09%7B%0A%09%09%09
@@ -1577,17 +1577,16 @@
 %09%09%7B%0A%09%09%09%09
-%09
 X += 16;
@@ -1589,20 +1589,18 @@
  16;%0A%09%09%09
-%09
 %7D%0A
-%09
 %09%09%09else%0A
@@ -1598,28 +1598,26 @@
 %0A%09%09%09else%0A%09%09%09
-%09
 %7B%0A
-%09
 %09%09%09%09// New r
@@ -1620,17 +1620,16 @@
 ew row!%0A
-%09
 %09%09%09%09if (
@@ -1639,28 +1639,26 @@
 = maxZ)%0A%09%09%09%09
-%09
 %7B%0A
-%09
 %09%09%09%09%09Z += 16
@@ -1659,17 +1659,16 @@
  += 16;%0A
-%09
 %09%09%09%09%09X =
@@ -1678,20 +1678,18 @@
 nX;%0A%09%09%09%09
-%09
 %7D%0A
-%09
 %09%09%09%09else
@@ -1689,17 +1689,16 @@
 %09%09%09else%0A
-%09
 %09%09%09%09%7B%0A%09%09
@@ -1700,17 +1700,16 @@
 %09%7B%0A%09%09%09%09%09
-%09
 // Done!
@@ -1709,17 +1709,16 @@
 / Done!%0A
-%09
 %09%09%09%09%09isC
@@ -1737,15 +1737,8 @@
 ue;%0A
-%09%09%09%09%09%7D%0A
 %09%09%09%09

Update src/FE_SRC_COMMON/com/ForgeEssentials/WorldBorder/TickTaskFillRound.java