From f969403b54f5442b57297897c7d51b9829f41832 Mon Sep 17 00:00:00 2001 From: Aurora Date: Wed, 26 Aug 2020 16:05:22 +0200 Subject: [PATCH] Fix NMS for Chunk Updates on 1.16.2 --- .../mc1_16_2/BukkitAdapter_1_16_2.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitAdapter_1_16_2.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitAdapter_1_16_2.java index 4f379ffd6..adac97fe1 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitAdapter_1_16_2.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitAdapter_1_16_2.java @@ -63,8 +63,8 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter { public static final Field fieldTickingBlockCount; public static final Field fieldNonEmptyBlockCount; - private static final Field fieldDirtyCount; - private static final Field fieldDirtyBits; + private static final Field fieldDirty; + private static final Field fieldDirtyBlocks; private static final MethodHandle methodGetVisibleChunk; @@ -94,10 +94,10 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter { fieldNonEmptyBlockCount = ChunkSection.class.getDeclaredField("nonEmptyBlockCount"); fieldNonEmptyBlockCount.setAccessible(true); - fieldDirtyCount = PlayerChunk.class.getDeclaredField("r"); - fieldDirtyCount.setAccessible(true); - fieldDirtyBits = PlayerChunk.class.getDeclaredField("dirtyBlocks"); - fieldDirtyBits.setAccessible(true); + fieldDirty = PlayerChunk.class.getDeclaredField("p"); + fieldDirty.setAccessible(true); + fieldDirtyBlocks = PlayerChunk.class.getDeclaredField("dirtyBlocks"); + fieldDirtyBlocks.setAccessible(true); Method declaredGetVisibleChunk = PlayerChunkMap.class.getDeclaredMethod("getVisibleChunk", long.class); declaredGetVisibleChunk.setAccessible(true); @@ -190,14 +190,20 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter { if (playerChunk.hasBeenLoaded()) { TaskManager.IMP.sync(() -> { try { - Set[] dirtyblocks = (Set[]) fieldDirtyBits.get(playerChunk); + Set[] dirtyblocks = (Set[]) 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++) { if (dirtyblocks[i] == null) dirtyblocks[i] = (Set) shortArraySetConstructor.newInstance(); - dirtyblocks[i].add((short) 0); - dirtyblocks[i].add((short) 1); + for (int x = 0; x < 16; x++) + 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) { ChunkCoordIntPair chunkCoordIntPair = new ChunkCoordIntPair(chunkX, chunkZ);