Fix NMS for Chunk Updates on 1.16.2

This commit is contained in:
Aurora 2020-08-26 16:05:22 +02:00
parent 041029168f
commit f969403b54
No known key found for this signature in database
GPG Key ID: 89839F67B53656AD

View File

@ -63,8 +63,8 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter {
public static final Field fieldTickingBlockCount; public static final Field fieldTickingBlockCount;
public static final Field fieldNonEmptyBlockCount; public static final Field fieldNonEmptyBlockCount;
private static final Field fieldDirtyCount; private static final Field fieldDirty;
private static final Field fieldDirtyBits; private static final Field fieldDirtyBlocks;
private static final MethodHandle methodGetVisibleChunk; private static final MethodHandle methodGetVisibleChunk;
@ -94,10 +94,10 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter {
fieldNonEmptyBlockCount = ChunkSection.class.getDeclaredField("nonEmptyBlockCount"); fieldNonEmptyBlockCount = ChunkSection.class.getDeclaredField("nonEmptyBlockCount");
fieldNonEmptyBlockCount.setAccessible(true); fieldNonEmptyBlockCount.setAccessible(true);
fieldDirtyCount = PlayerChunk.class.getDeclaredField("r"); fieldDirty = PlayerChunk.class.getDeclaredField("p");
fieldDirtyCount.setAccessible(true); fieldDirty.setAccessible(true);
fieldDirtyBits = PlayerChunk.class.getDeclaredField("dirtyBlocks"); fieldDirtyBlocks = PlayerChunk.class.getDeclaredField("dirtyBlocks");
fieldDirtyBits.setAccessible(true); fieldDirtyBlocks.setAccessible(true);
Method declaredGetVisibleChunk = PlayerChunkMap.class.getDeclaredMethod("getVisibleChunk", long.class); Method declaredGetVisibleChunk = PlayerChunkMap.class.getDeclaredMethod("getVisibleChunk", long.class);
declaredGetVisibleChunk.setAccessible(true); declaredGetVisibleChunk.setAccessible(true);
@ -190,14 +190,20 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter {
if (playerChunk.hasBeenLoaded()) { if (playerChunk.hasBeenLoaded()) {
TaskManager.IMP.sync(() -> { TaskManager.IMP.sync(() -> {
try { try {
Set<Short>[] dirtyblocks = (Set<Short>[]) fieldDirtyBits.get(playerChunk); Set<Short>[] dirtyblocks = (Set<Short>[]) fieldDirtyBlocks.get(playerChunk);
if (Arrays.stream(dirtyblocks).allMatch(e -> e == null || e.isEmpty())) {
nmsWorld.getChunkProvider().playerChunkMap.a(playerChunk);
}
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
if (dirtyblocks[i] == null) dirtyblocks[i] = (Set<Short>) shortArraySetConstructor.newInstance(); if (dirtyblocks[i] == null) dirtyblocks[i] = (Set<Short>) shortArraySetConstructor.newInstance();
dirtyblocks[i].add((short) 0); for (int x = 0; x < 16; x++)
dirtyblocks[i].add((short) 1); for (int y = 0; y < 16; y++)
for (int z = 0; z < 16; z++)
dirtyblocks[i].add((short) ((x << 8) | (z << 4) | (y)));
} }
fieldDirtyBits.set(playerChunk, dirtyblocks);
nmsWorld.getChunkProvider().playerChunkMap.a(playerChunk); fieldDirtyBlocks.set(playerChunk, dirtyblocks);
fieldDirty.setBoolean(playerChunk, true);
if (lighting) { if (lighting) {
ChunkCoordIntPair chunkCoordIntPair = new ChunkCoordIntPair(chunkX, chunkZ); ChunkCoordIntPair chunkCoordIntPair = new ChunkCoordIntPair(chunkX, chunkZ);