From 789c9231069468eb4dfc4f4b6c49b298f30f07fd Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Fri, 16 Mar 2018 23:37:36 +1100 Subject: [PATCH] debug fix air --- .../boydti/fawe/command/AnvilCommands.java | 24 +++++- .../fawe/jnbt/anvil/filters/DebugFixAir.java | 82 +++++++++++++++++++ .../jnbt/anvil/filters/TrimAirFilter.java | 1 + 3 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 core/src/main/java/com/boydti/fawe/jnbt/anvil/filters/DebugFixAir.java diff --git a/core/src/main/java/com/boydti/fawe/command/AnvilCommands.java b/core/src/main/java/com/boydti/fawe/command/AnvilCommands.java index 921167f7..f1437efb 100644 --- a/core/src/main/java/com/boydti/fawe/command/AnvilCommands.java +++ b/core/src/main/java/com/boydti/fawe/command/AnvilCommands.java @@ -68,6 +68,12 @@ public class AnvilCommands { */ @Deprecated public static > T runWithWorld(Player player, String folder, T filter, boolean force) { + return runWithWorld(player, folder, filter, force, false); + } + + + @Deprecated + public static > T runWithWorld(Player player, String folder, T filter, boolean force, boolean unsafe) { boolean copy = false; if (FaweAPI.getWorld(folder) != null) { if (!force) { @@ -78,7 +84,7 @@ public class AnvilCommands { } FaweQueue defaultQueue = SetQueue.IMP.getNewQueue(folder, true, false); MCAQueue queue = new MCAQueue(defaultQueue); - if (copy) { + if (copy && !unsafe) { return queue.filterCopy(filter, RegionWrapper.GLOBAL()); } else { return queue.filterWorld(filter); @@ -284,9 +290,21 @@ public class AnvilCommands { desc = "Trim all air in the world" ) @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 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())); } diff --git a/core/src/main/java/com/boydti/fawe/jnbt/anvil/filters/DebugFixAir.java b/core/src/main/java/com/boydti/fawe/jnbt/anvil/filters/DebugFixAir.java new file mode 100644 index 00000000..96ab3a19 --- /dev/null +++ b/core/src/main/java/com/boydti/fawe/jnbt/anvil/filters/DebugFixAir.java @@ -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() { + @Override + public void run(MCAChunk value) { + if (!value.isDeleted()) { + deleteFile[0] = false; + } + } + }); + if (deleteFile[0]) { + file.setDeleted(true); + } + } +} diff --git a/core/src/main/java/com/boydti/fawe/jnbt/anvil/filters/TrimAirFilter.java b/core/src/main/java/com/boydti/fawe/jnbt/anvil/filters/TrimAirFilter.java index 67aa4ad4..178db7ee 100644 --- a/core/src/main/java/com/boydti/fawe/jnbt/anvil/filters/TrimAirFilter.java +++ b/core/src/main/java/com/boydti/fawe/jnbt/anvil/filters/TrimAirFilter.java @@ -23,6 +23,7 @@ public class TrimAirFilter extends MCAFilterCounter { chunk.setModified(); } } + cache.add(Character.MAX_VALUE); chunk.setDeleted(true); return null; }