Set empty block count when using fastmode on 1.17 (#1710)

* Set empty block count when using fastmode on 1.17
Fixes #1666

* Update legacy adapters
This commit is contained in:
Jordan 2022-04-21 12:11:23 +01:00 committed by GitHub
parent f5ef0cadb6
commit 65349392a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 19 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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);

View File

@ -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<Integer, char[]> 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;
}