fix for longstanding issue of chunks which didn't exist in a region file still being unnecessarily wiped by the Trim process, also adding to the reported number of individual trimmed chunks. Now chunks which were already nonexistent aren't "trimmed" for no reason and the reported number of individual trimmed chunks is exactly correct.

This commit is contained in:
Brettflan 2013-07-12 01:56:27 -05:00
parent 0a827e69e8
commit 893701637a

View File

@ -275,23 +275,30 @@ public class WorldTrimTask implements Runnable
int offsetX = CoordXZ.regionToChunk(regionX); int offsetX = CoordXZ.regionToChunk(regionX);
int offsetZ = CoordXZ.regionToChunk(regionZ); int offsetZ = CoordXZ.regionToChunk(regionZ);
long wipePos = 0; long wipePos = 0;
int chunkCount = 0;
try try
{ {
RandomAccessFile unChunk = new RandomAccessFile(regionFile, "rwd"); RandomAccessFile unChunk = new RandomAccessFile(regionFile, "rwd");
for (CoordXZ wipe : trimChunks) for (CoordXZ wipe : trimChunks)
{ // wipe this extraneous chunk's pointer... note that this method isn't perfect since the actual chunk data is left orphaned, {
// if the chunk pointer is empty (chunk doesn't technically exist), no need to wipe the already empty pointer
if (!worldData.doesChunkExist(wipe.x, wipe.z))
continue;
// wipe this extraneous chunk's pointer... note that this method isn't perfect since the actual chunk data is left orphaned,
// but Minecraft will overwrite the orphaned data sector if/when another chunk is created in the region, so it's not so bad // but Minecraft will overwrite the orphaned data sector if/when another chunk is created in the region, so it's not so bad
wipePos = 4 * ((wipe.x - offsetX) + ((wipe.z - offsetZ) * 32)); wipePos = 4 * ((wipe.x - offsetX) + ((wipe.z - offsetZ) * 32));
unChunk.seek(wipePos); unChunk.seek(wipePos);
unChunk.writeInt(0); unChunk.writeInt(0);
chunkCount++;
} }
unChunk.close(); unChunk.close();
// if DynMap is installed, re-render the trimmed chunks ... disabled since it's not currently working, oh well // if DynMap is installed, re-render the trimmed chunks ... disabled since it's not currently working, oh well
// DynMapFeatures.renderChunks(world.getName(), trimChunks); // DynMapFeatures.renderChunks(world.getName(), trimChunks);
reportTrimmedChunks += trimChunks.size(); reportTrimmedChunks += chunkCount;
} }
catch (FileNotFoundException ex) catch (FileNotFoundException ex)
{ {