This commit is contained in:
dordsor21 2023-07-05 22:03:13 +01:00
parent 67fd31ce4c
commit a669be2041
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
5 changed files with 34 additions and 17 deletions

View File

@ -445,7 +445,11 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
bitMask |= 1 << layer; bitMask |= 1 << layer;
char[] setArr = set.load(layerNo); // setArr is modified by PaperweightPlatformAdapter#newChunkSection. This is in order to write changes to
// this chunk GET when #updateGet is called. Future dords, please listen this time.
char[] tmp = set.load(layerNo);
char[] setArr = new char[tmp.length];
System.arraycopy(tmp, 0, setArr, 0, tmp.length);
// synchronise on internal section to avoid circular locking with a continuing edit if the chunk was // synchronise on internal section to avoid circular locking with a continuing edit if the chunk was
// submitted to keep loaded internal chunks to queue target size. // submitted to keep loaded internal chunks to queue target size.

View File

@ -491,7 +491,11 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
bitMask |= 1 << getSectionIndex; bitMask |= 1 << getSectionIndex;
char[] setArr = set.load(layerNo); // setArr is modified by PaperweightPlatformAdapter#newChunkSection. This is in order to write changes to
// this chunk GET when #updateGet is called. Future dords, please listen this time.
char[] tmp = set.load(layerNo);
char[] setArr = new char[tmp.length];
System.arraycopy(tmp, 0, setArr, 0, tmp.length);
// synchronise on internal section to avoid circular locking with a continuing edit if the chunk was // synchronise on internal section to avoid circular locking with a continuing edit if the chunk was
// submitted to keep loaded internal chunks to queue target size. // submitted to keep loaded internal chunks to queue target size.

View File

@ -490,7 +490,11 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
bitMask |= 1 << getSectionIndex; bitMask |= 1 << getSectionIndex;
char[] setArr = set.load(layerNo); // setArr is modified by PaperweightPlatformAdapter#newChunkSection. This is in order to write changes to
// this chunk GET when #updateGet is called. Future dords, please listen this time.
char[] tmp = set.load(layerNo);
char[] setArr = new char[tmp.length];
System.arraycopy(tmp, 0, setArr, 0, tmp.length);
// synchronise on internal section to avoid circular locking with a continuing edit if the chunk was // synchronise on internal section to avoid circular locking with a continuing edit if the chunk was
// submitted to keep loaded internal chunks to queue target size. // submitted to keep loaded internal chunks to queue target size.

View File

@ -468,7 +468,11 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
bitMask |= 1 << getSectionIndex; bitMask |= 1 << getSectionIndex;
char[] setArr = set.load(layerNo); // setArr is modified by PaperweightPlatformAdapter#newChunkSection. This is in order to write changes to
// this chunk GET when #updateGet is called. Future dords, please listen this time.
char[] tmp = set.load(layerNo);
char[] setArr = new char[tmp.length];
System.arraycopy(tmp, 0, setArr, 0, tmp.length);
// synchronise on internal section to avoid circular locking with a continuing edit if the chunk was // synchronise on internal section to avoid circular locking with a continuing edit if the chunk was
// submitted to keep loaded internal chunks to queue target size. // submitted to keep loaded internal chunks to queue target size.

View File

@ -30,8 +30,7 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl {
ordinal = BlockTypesCache.ReservedIDs.AIR; ordinal = BlockTypesCache.ReservedIDs.AIR;
nonAir--; nonAir--;
} }
case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR, BlockTypesCache.ReservedIDs.VOID_AIR -> case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR, BlockTypesCache.ReservedIDs.VOID_AIR -> nonAir--;
nonAir--;
} }
int palette = blockToPalette[ordinal]; int palette = blockToPalette[ordinal];
if (palette == Integer.MAX_VALUE) { if (palette == Integer.MAX_VALUE) {
@ -74,8 +73,6 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl {
CachedBukkitAdapter adapter, CachedBukkitAdapter adapter,
short[] nonEmptyBlockCount short[] nonEmptyBlockCount
) { ) {
// Write to new array to avoid editing SET array
char[] copy = new char[set.length];
short nonAir = 4096; short nonAir = 4096;
int num_palette = 0; int num_palette = 0;
char[] getArr = null; char[] getArr = null;
@ -86,19 +83,23 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl {
if (getArr == null) { if (getArr == null) {
getArr = get.apply(layer); getArr = get.apply(layer);
} }
switch (ordinal = getArr[i]) { // write to set array as this should be a copied array, and will be important when the changes are written
// to the GET chunk cached by FAWE. Future dords, actually read this comment please.
set[i] = switch (ordinal = getArr[i]) {
case BlockTypesCache.ReservedIDs.__RESERVED__ -> { case BlockTypesCache.ReservedIDs.__RESERVED__ -> {
nonAir--; nonAir--;
ordinal = BlockTypesCache.ReservedIDs.AIR; yield (ordinal = BlockTypesCache.ReservedIDs.AIR);
} }
case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR, BlockTypesCache.ReservedIDs.VOID_AIR -> case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR,
nonAir--; BlockTypesCache.ReservedIDs.VOID_AIR -> {
} nonAir--;
yield ordinal;
}
default -> ordinal;
};
} }
case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR, BlockTypesCache.ReservedIDs.VOID_AIR -> case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR, BlockTypesCache.ReservedIDs.VOID_AIR -> nonAir--;
nonAir--;
} }
copy[i] = ordinal;
int palette = blockToPalette[ordinal]; int palette = blockToPalette[ordinal];
if (palette == Integer.MAX_VALUE) { if (palette == Integer.MAX_VALUE) {
blockToPalette[ordinal] = num_palette; blockToPalette[ordinal] = num_palette;
@ -116,7 +117,7 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl {
System.arraycopy(adapter.getOrdinalToIbdID(), 0, blockToPalette, 0, adapter.getOrdinalToIbdID().length); System.arraycopy(adapter.getOrdinalToIbdID(), 0, blockToPalette, 0, adapter.getOrdinalToIbdID().length);
} }
for (int i = 0; i < 4096; i++) { for (int i = 0; i < 4096; i++) {
char ordinal = copy[i]; char ordinal = set[i];
if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) { if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) {
LOGGER.error("Empty (__RESERVED__) ordinal given where not expected, default to air."); LOGGER.error("Empty (__RESERVED__) ordinal given where not expected, default to air.");
ordinal = BlockTypesCache.ReservedIDs.AIR; ordinal = BlockTypesCache.ReservedIDs.AIR;