Skip to content

Commit

Permalink
Set empty block count when using fastmode on 1.17 (#1710)
Browse files Browse the repository at this point in the history
* Set empty block count when using fastmode on 1.17
Fixes #1666

* Update legacy adapters
  • Loading branch information
dordsor21 authored Apr 21, 2022
1 parent f5ef0ca commit 6534939
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,20 @@ public static LevelChunkSection newChunkSection(
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);
Expand Down Expand Up @@ -377,6 +386,12 @@ public static LevelChunkSection newChunkSection(

if (!fastMode) {
levelChunkSection.recalcBlockCounts();
} else {
try {
fieldNonEmptyBlockCount.set(levelChunkSection, nonEmptyBlockCount[0]);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
return levelChunkSection;
} catch (final Throwable e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,9 @@ public static LevelChunkSection newChunkSection(
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ public static LevelChunkSection newChunkSection(
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);
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ public static int createPalette(
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) {
Expand All @@ -46,6 +52,10 @@ public static int createPalette(
int palette = blockToPalette[ordinal];
blocksCopy[i] = palette;
}

if (nonEmptyBlockCount != null) {
nonEmptyBlockCount[0] = nonAir;
}
return num_palette;
}

Expand All @@ -56,20 +66,29 @@ public static int createPalette(
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) {
Expand All @@ -88,7 +107,7 @@ public static int createPalette(
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);
Expand All @@ -101,6 +120,9 @@ public static int createPalette(
blocksCopy[i] = palette;
}

if (nonEmptyBlockCount != null) {
nonEmptyBlockCount[0] = nonAir;
}
return num_palette;
}

Expand Down

0 comments on commit 6534939

Please sign in to comment.