trimflatfilter

This commit is contained in:
Jesse Boyd 2019-04-06 14:45:39 +11:00
parent 92e50d5897
commit dd28c78a36
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
2 changed files with 85 additions and 0 deletions

View File

@ -310,6 +310,18 @@ public class AnvilCommands {
} }
@Command(
aliases = {"trimallflat", },
desc = "Trim all flat chunks"
)
@CommandPermissions("worldedit.anvil.trimallflat")
public void trimAllAir(Player player, String folder, @Switch('u') boolean unsafe) throws WorldEditException {
TrimFlatFilter filter = new TrimFlatFilter();
TrimFlatFilter result = runWithWorld(player, folder, filter, true, unsafe);
if (result != null) player.print(BBC.getPrefix() + BBC.VISITOR_BLOCK.format(result.getTotal()));
}
@Command( @Command(
aliases = {"debugfixair", }, aliases = {"debugfixair", },
desc = "debug - do not use" desc = "debug - do not use"

View File

@ -0,0 +1,73 @@
package com.boydti.fawe.jnbt.anvil.filters;
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;
public class TrimFlatFilter extends MCAFilterCounter {
@Override
public MCAChunk applyChunk(MCAChunk chunk, MutableLong cache) {
// Check other layers
for (int layer = 1; 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) {
return null;
}
}
{ // Possibly dead code depending on the generator
chunk.ids[layer] = null;
chunk.data[layer] = null;
chunk.setModified();
}
}
byte[] layer0 = chunk.ids[0];
int index = 0;
for (int y = 0; y <= 3; y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++, index++) {
int id = layer0[index] & 0xFF;
switch (id) {
case 2: // grass
case 3: // dirt
case 7: // bedrock
continue;
default:
return;
}
}
}
}
for (int y = 4; y < 16; y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++, index++) {
if (layer0[index] != 0) return;
}
}
}
// Check floor layers
cache.add(Character.MAX_VALUE);
chunk.setDeleted(true);
return null;
}
@Override
public void finishFile(MCAFile file, MutableLong cache) {
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);
}
}
}