From fda7d00747abe97d7891b80ed8bb88d97e1c70d1 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Wed, 29 Apr 2020 18:17:21 +0100 Subject: [PATCH] A more verbose fix to #329 and similar issues. - Re-read chunksections the first time they're "loaded" for an operation - Reset the chunksection if there are block changes when setting blocks via reflection - These are maybe gonna affect performance a bit? Idk. Seems to be alright for me - These are maybe gonna make more issues? Yeah maybe, but I couldn't find any --- .../mc1_15_2/BukkitGetBlocks_1_15_2.java | 23 ++++++++----------- .../implementation/chunk/ChunkHolder.java | 4 ++++ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitGetBlocks_1_15_2.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitGetBlocks_1_15_2.java index 965c73d54..3578a5549 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitGetBlocks_1_15_2.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitGetBlocks_1_15_2.java @@ -221,10 +221,9 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks { if (this.sections == null) { this.sections = sections.clone(); } - //TODO: Understand why this causes #329, what the purpose of this is, and what may or may not break after commenting this out. -// if (this.sections[layer] != section) { -// this.sections[layer] = section; -// } + if (this.sections[layer] != section) { + this.sections[layer] = new ChunkSection[]{section}.clone()[0]; + } this.blocks[layer] = arr; } } @@ -299,19 +298,17 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks { synchronized (this) { synchronized (lock) { lock.untilFree(); - ChunkSection getSection; if (this.nmsChunk != nmsChunk) { this.nmsChunk = nmsChunk; this.sections = null; this.reset(); - } else { - getSection = this.getSections()[layer]; - if (getSection != existingSection) { - this.sections[layer] = existingSection; - this.reset(); - } else if (lock.isModified()) { - this.reset(layer); - } + } else if (existingSection != getSections()[layer]) { + this.sections[layer] = existingSection; + this.reset(); + } else if (!Arrays.equals(update(layer, new char[4096]), load(layer))) { + this.reset(layer); + } else if (lock.isModified()) { + this.reset(layer); } newSection = BukkitAdapter_1_15_2.newChunkSection(layer, this::load, setArr); if (!BukkitAdapter_1_15_2.setSectionAtomic(sections, existingSection, newSection, layer)) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/ChunkHolder.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/ChunkHolder.java index 443c310ff..50fa4e8ca 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/ChunkHolder.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/ChunkHolder.java @@ -243,6 +243,7 @@ public class ChunkHolder> implements IQueueChunk { public IChunkGet get(ChunkHolder chunk) { chunk.getOrCreateGet(); chunk.delegate = BOTH; + chunk.chunkExisting.trim(false); return chunk.chunkExisting; } @@ -271,6 +272,7 @@ public class ChunkHolder> implements IQueueChunk { public BiomeType getBiome(ChunkHolder chunk, int x, int y, int z) { chunk.getOrCreateGet(); chunk.delegate = GET; + chunk.chunkExisting.trim(false); return chunk.getBiomeType(x, y, z); } @@ -278,6 +280,7 @@ public class ChunkHolder> implements IQueueChunk { public BlockState getBlock(ChunkHolder chunk, int x, int y, int z) { chunk.getOrCreateGet(); chunk.delegate = GET; + chunk.chunkExisting.trim(false); return chunk.getBlock(x, y, z); } @@ -286,6 +289,7 @@ public class ChunkHolder> implements IQueueChunk { int z) { chunk.getOrCreateGet(); chunk.delegate = GET; + chunk.chunkExisting.trim(false); return chunk.getFullBlock(x, y, z); } };