diff --git a/worldedit-bukkit/adapters/adapter-1_17_1/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_17_R1_2/PaperweightPlatformAdapter.java b/worldedit-bukkit/adapters/adapter-1_17_1/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_17_R1_2/PaperweightPlatformAdapter.java index a34bbb3f3..9ae0da2bd 100644 --- a/worldedit-bukkit/adapters/adapter-1_17_1/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_17_R1_2/PaperweightPlatformAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_17_1/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_17_R1_2/PaperweightPlatformAdapter.java @@ -303,11 +303,20 @@ public final class PaperweightPlatformAdapter extends NMSAdapter { final int[] blocksCopy = FaweCache.INSTANCE.SECTION_BLOCKS.get(); try { int num_palette; + final short[] nonEmptyBlockCount = fastMode ? new short[1] : null; if (get == null) { - num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter - ); + num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, nonEmptyBlockCount); } else { - num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter); + num_palette = createPalette( + layer, + blockToPalette, + paletteToBlock, + blocksCopy, + get, + set, + adapter, + nonEmptyBlockCount + ); } // BlockStates int bitsPerEntry = MathMan.log2nlz(num_palette - 1); @@ -377,6 +386,12 @@ public final class PaperweightPlatformAdapter extends NMSAdapter { if (!fastMode) { levelChunkSection.recalcBlockCounts(); + } else { + try { + fieldNonEmptyBlockCount.set(levelChunkSection, nonEmptyBlockCount[0]); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } } return levelChunkSection; } catch (final Throwable e) { diff --git a/worldedit-bukkit/adapters/adapter-1_18/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R1/PaperweightPlatformAdapter.java b/worldedit-bukkit/adapters/adapter-1_18/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R1/PaperweightPlatformAdapter.java index 7a9065305..29e0bc472 100644 --- a/worldedit-bukkit/adapters/adapter-1_18/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R1/PaperweightPlatformAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_18/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R1/PaperweightPlatformAdapter.java @@ -341,9 +341,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter { try { int num_palette; if (get == null) { - num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter); + num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, null); } else { - num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter); + num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter, null); } int bitsPerEntry = MathMan.log2nlz(num_palette - 1); diff --git a/worldedit-bukkit/adapters/adapter-1_18_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R2/PaperweightPlatformAdapter.java b/worldedit-bukkit/adapters/adapter-1_18_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R2/PaperweightPlatformAdapter.java index e44da5991..4c18fa15d 100644 --- a/worldedit-bukkit/adapters/adapter-1_18_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R2/PaperweightPlatformAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_18_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R2/PaperweightPlatformAdapter.java @@ -342,9 +342,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter { try { int num_palette; if (get == null) { - num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter); + num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, null); } else { - num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter); + num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter, null); } int bitsPerEntry = MathMan.log2nlz(num_palette - 1); diff --git a/worldedit-bukkit/adapters/adapter-legacy/src/main/resources/worldedit-adapters.jar b/worldedit-bukkit/adapters/adapter-legacy/src/main/resources/worldedit-adapters.jar index 15a9459a4..136135971 100644 Binary files a/worldedit-bukkit/adapters/adapter-legacy/src/main/resources/worldedit-adapters.jar and b/worldedit-bukkit/adapters/adapter-legacy/src/main/resources/worldedit-adapters.jar differ diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/NMSAdapter.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/NMSAdapter.java index 9726f7089..c41a3e168 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/NMSAdapter.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/NMSAdapter.java @@ -14,13 +14,19 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl { int[] paletteToBlock, int[] blocksCopy, char[] set, - CachedBukkitAdapter adapter + CachedBukkitAdapter adapter, + short[] nonEmptyBlockCount ) { + short nonAir = 4096; int num_palette = 0; for (int i = 0; i < 4096; i++) { char ordinal = set[i]; - if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) { - ordinal = BlockTypesCache.ReservedIDs.AIR; + switch (ordinal) { + case BlockTypesCache.ReservedIDs.__RESERVED__ -> { + ordinal = BlockTypesCache.ReservedIDs.AIR; + nonAir--; + } + case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR, BlockTypesCache.ReservedIDs.VOID_AIR -> nonAir--; } int palette = blockToPalette[ordinal]; if (palette == Integer.MAX_VALUE) { @@ -46,6 +52,10 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl { int palette = blockToPalette[ordinal]; blocksCopy[i] = palette; } + + if (nonEmptyBlockCount != null) { + nonEmptyBlockCount[0] = nonAir; + } return num_palette; } @@ -56,20 +66,29 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl { int[] blocksCopy, Function get, char[] set, - CachedBukkitAdapter adapter + CachedBukkitAdapter adapter, + short[] nonEmptyBlockCount ) { + short nonAir = 4096; int num_palette = 0; char[] getArr = null; for (int i = 0; i < 4096; i++) { char ordinal = set[i]; - if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) { - if (getArr == null) { - getArr = get.apply(layer); - } - ordinal = getArr[i]; - if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) { - ordinal = BlockTypesCache.ReservedIDs.AIR; + switch (ordinal) { + case BlockTypesCache.ReservedIDs.__RESERVED__ -> { + if (getArr == null) { + getArr = get.apply(layer); + } + ordinal = getArr[i]; + switch (ordinal) { + case BlockTypesCache.ReservedIDs.__RESERVED__ -> { + ordinal = BlockTypesCache.ReservedIDs.AIR; + nonAir--; + } + case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR, BlockTypesCache.ReservedIDs.VOID_AIR -> nonAir--; + } } + case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR, BlockTypesCache.ReservedIDs.VOID_AIR -> nonAir--; } int palette = blockToPalette[ordinal]; if (palette == Integer.MAX_VALUE) { @@ -88,7 +107,7 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl { System.arraycopy(adapter.getOrdinalToIbdID(), 0, blockToPalette, 0, adapter.getOrdinalToIbdID().length); } for (int i = 0; i < 4096; i++) { - char ordinal= set[i]; + char ordinal = set[i]; if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) { if (getArr == null) { getArr = get.apply(layer); @@ -101,6 +120,9 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl { blocksCopy[i] = palette; } + if (nonEmptyBlockCount != null) { + nonEmptyBlockCount[0] = nonAir; + } return num_palette; }