debug fix air

This commit is contained in:
Jesse Boyd 2018-03-16 23:37:36 +11:00
parent 65939fa878
commit 789c923106
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
3 changed files with 104 additions and 3 deletions

View File

@ -68,6 +68,12 @@ public class AnvilCommands {
*/ */
@Deprecated @Deprecated
public static <G, T extends MCAFilter<G>> T runWithWorld(Player player, String folder, T filter, boolean force) { public static <G, T extends MCAFilter<G>> T runWithWorld(Player player, String folder, T filter, boolean force) {
return runWithWorld(player, folder, filter, force, false);
}
@Deprecated
public static <G, T extends MCAFilter<G>> T runWithWorld(Player player, String folder, T filter, boolean force, boolean unsafe) {
boolean copy = false; boolean copy = false;
if (FaweAPI.getWorld(folder) != null) { if (FaweAPI.getWorld(folder) != null) {
if (!force) { if (!force) {
@ -78,7 +84,7 @@ public class AnvilCommands {
} }
FaweQueue defaultQueue = SetQueue.IMP.getNewQueue(folder, true, false); FaweQueue defaultQueue = SetQueue.IMP.getNewQueue(folder, true, false);
MCAQueue queue = new MCAQueue(defaultQueue); MCAQueue queue = new MCAQueue(defaultQueue);
if (copy) { if (copy && !unsafe) {
return queue.filterCopy(filter, RegionWrapper.GLOBAL()); return queue.filterCopy(filter, RegionWrapper.GLOBAL());
} else { } else {
return queue.filterWorld(filter); return queue.filterWorld(filter);
@ -284,9 +290,21 @@ public class AnvilCommands {
desc = "Trim all air in the world" desc = "Trim all air in the world"
) )
@CommandPermissions("worldedit.anvil.trimallair") @CommandPermissions("worldedit.anvil.trimallair")
public void trimAllAir(Player player, String folder) throws WorldEditException { public void trimAllAir(Player player, String folder, @Switch('u') boolean unsafe) throws WorldEditException {
TrimAirFilter filter = new TrimAirFilter(); TrimAirFilter filter = new TrimAirFilter();
TrimAirFilter result = runWithWorld(player, folder, filter, true); TrimAirFilter result = runWithWorld(player, folder, filter, true, unsafe);
if (result != null) player.print(BBC.getPrefix() + BBC.VISITOR_BLOCK.format(result.getTotal()));
}
@Command(
aliases = {"debugfixair", },
desc = "debug"
)
@CommandPermissions("worldedit.anvil.debugfixair")
public void debugfixair(Player player, String folder) throws WorldEditException {
DebugFixAir filter = new DebugFixAir();
DebugFixAir result = runWithWorld(player, folder, filter, true, true);
if (result != null) player.print(BBC.getPrefix() + BBC.VISITOR_BLOCK.format(result.getTotal())); if (result != null) player.print(BBC.getPrefix() + BBC.VISITOR_BLOCK.format(result.getTotal()));
} }

View File

@ -0,0 +1,82 @@
package com.boydti.fawe.jnbt.anvil.filters;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.jnbt.anvil.MCAChunk;
import com.boydti.fawe.jnbt.anvil.MCAFile;
import com.boydti.fawe.jnbt.anvil.MCAFilterCounter;
import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.object.number.MutableLong;
import com.sk89q.worldedit.blocks.BlockID;
public class DebugFixAir extends MCAFilterCounter {
@Override
public MCAChunk applyChunk(MCAChunk chunk, MutableLong cache) {
none:
{
some:
{
for (int layer = 0; layer < chunk.ids.length; layer++) {
byte[] idLayer = chunk.ids[layer];
if (idLayer == null) continue;
for (int i = 0; i < 4096; i++) {
if (idLayer[i] != 0) {
if (layer != 0) break some;
break none;
}
}
{ // Possibly dead code depending on the generator
chunk.ids[layer] = null;
chunk.data[layer] = null;
chunk.setModified();
}
}
cache.add(Character.MAX_VALUE);
chunk.setDeleted(true);
return null;
}
return null;
}
for (int i = 0; i < 5; i++) {
if (chunk.ids[i] == null) return null;
}
// layer 0
boolean modified = false;
byte[] ids0 = chunk.ids[0];
for (int i = 0; i < 256; i++) {
if (ids0[i] == 0) {
if (!modified) {
modified = true;
}
for (int layer = 0; layer < 4; layer++) {
byte[] arr = chunk.ids[layer];
for (int y = i; y < 4096; y += 256) {
arr[y] = BlockID.DIRT;
}
}
ids0[i] = BlockID.BEDROCK;
chunk.ids[4][i] = BlockID.GRASS;
cache.add(256);
}
}
if (modified) chunk.setModified();
return null;
}
@Override
public void finishFile(MCAFile file, MutableLong cache) {
Fawe.debug(" - apply " + file.getFile());
boolean[] deleteFile = { true };
file.forEachCachedChunk(new RunnableVal<MCAChunk>() {
@Override
public void run(MCAChunk value) {
if (!value.isDeleted()) {
deleteFile[0] = false;
}
}
});
if (deleteFile[0]) {
file.setDeleted(true);
}
}
}

View File

@ -23,6 +23,7 @@ public class TrimAirFilter extends MCAFilterCounter {
chunk.setModified(); chunk.setModified();
} }
} }
cache.add(Character.MAX_VALUE);
chunk.setDeleted(true); chunk.setDeleted(true);
return null; return null;
} }