From 884ec322b818ac3423c3b5043c141e5a9c08a98f Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Thu, 17 Dec 2020 22:04:49 +0000 Subject: [PATCH] Ensure chunk sections are reloaded for every edit/chunk read Add an option for force-reloading the cached chunk sections when a layer is updated --- .../adapter/mc1_15_2/BukkitGetBlocks_1_15_2.java | 13 ++++++++----- .../adapter/mc1_16_1/BukkitGetBlocks_1_16_1.java | 13 ++++++++----- .../adapter/mc1_16_2/BukkitGetBlocks_1_16_2.java | 13 ++++++++----- .../adapter/mc1_16_4/BukkitGetBlocks_1_16_4.java | 16 +++++++++++----- 4 files changed, 35 insertions(+), 20 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 40d082be9..549526f9f 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 @@ -397,7 +397,7 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks { this.nmsChunk = nmsChunk; this.sections = null; this.reset(); - } else if (existingSection != getSections()[layer]) { + } else if (existingSection != getSections(false)[layer]) { this.sections[layer] = existingSection; this.reset(); } else if (!Arrays.equals(update(layer, new char[4096]), load(layer))) { @@ -642,7 +642,7 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks { @Override public synchronized char[] update(int layer, char[] data) { - ChunkSection section = getSections()[layer]; + ChunkSection section = getSections(true)[layer]; // Section is null, return empty array if (section == null) { data = new char[4096]; @@ -757,7 +757,10 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks { } } - public ChunkSection[] getSections() { + public ChunkSection[] getSections(boolean force) { + if (force) { + return sections = getChunk().getSections().clone(); + } ChunkSection[] tmp = sections; if (tmp == null) { synchronized (this) { @@ -809,7 +812,7 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks { @Override public boolean hasSection(int layer) { - return getSections()[layer] != null; + return getSections(false)[layer] != null; } @Override @@ -825,7 +828,7 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks { if (!hasSection(i) || super.sections[i] == CharBlocks.EMPTY) { continue; } - ChunkSection existing = getSections()[i]; + ChunkSection existing = getSections(false)[i]; try { final DataPaletteBlock blocksExisting = existing.getBlocks(); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_1/BukkitGetBlocks_1_16_1.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_1/BukkitGetBlocks_1_16_1.java index 9ab5ff383..458ae27a5 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_1/BukkitGetBlocks_1_16_1.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_1/BukkitGetBlocks_1_16_1.java @@ -397,7 +397,7 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks { this.nmsChunk = nmsChunk; this.sections = null; this.reset(); - } else if (existingSection != getSections()[layer]) { + } else if (existingSection != getSections(false)[layer]) { this.sections[layer] = existingSection; this.reset(); } else if (!Arrays.equals(update(layer, new char[4096]), load(layer))) { @@ -644,7 +644,7 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks { @Override public synchronized char[] update(int layer, char[] data) { - ChunkSection section = getSections()[layer]; + ChunkSection section = getSections(true)[layer]; // Section is null, return empty array if (section == null) { data = new char[4096]; @@ -759,7 +759,10 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks { } } - public ChunkSection[] getSections() { + public ChunkSection[] getSections(boolean force) { + if (force) { + return sections = getChunk().getSections().clone(); + } ChunkSection[] tmp = sections; if (tmp == null) { synchronized (this) { @@ -811,7 +814,7 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks { @Override public boolean hasSection(int layer) { - return getSections()[layer] != null; + return getSections(false)[layer] != null; } @Override @@ -827,7 +830,7 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks { if (!hasSection(i) || super.sections[i] == CharBlocks.EMPTY) { continue; } - ChunkSection existing = getSections()[i]; + ChunkSection existing = getSections(false)[i]; try { final DataPaletteBlock blocksExisting = existing.getBlocks(); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitGetBlocks_1_16_2.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitGetBlocks_1_16_2.java index e63973c68..44c885305 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitGetBlocks_1_16_2.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitGetBlocks_1_16_2.java @@ -400,7 +400,7 @@ public class BukkitGetBlocks_1_16_2 extends CharGetBlocks { this.nmsChunk = nmsChunk; this.sections = null; this.reset(); - } else if (existingSection != getSections()[layer]) { + } else if (existingSection != getSections(false)[layer]) { this.sections[layer] = existingSection; this.reset(); } else if (!Arrays.equals(update(layer, new char[4096]), load(layer))) { @@ -647,7 +647,7 @@ public class BukkitGetBlocks_1_16_2 extends CharGetBlocks { @Override public synchronized char[] update(int layer, char[] data) { - ChunkSection section = getSections()[layer]; + ChunkSection section = getSections(true)[layer]; // Section is null, return empty array if (section == null) { data = new char[4096]; @@ -762,7 +762,10 @@ public class BukkitGetBlocks_1_16_2 extends CharGetBlocks { } } - public ChunkSection[] getSections() { + public ChunkSection[] getSections(boolean force) { + if (force) { + return sections = getChunk().getSections().clone(); + } ChunkSection[] tmp = sections; if (tmp == null) { synchronized (this) { @@ -814,7 +817,7 @@ public class BukkitGetBlocks_1_16_2 extends CharGetBlocks { @Override public boolean hasSection(int layer) { - return getSections()[layer] != null; + return getSections(false)[layer] != null; } @Override @@ -830,7 +833,7 @@ public class BukkitGetBlocks_1_16_2 extends CharGetBlocks { if (!hasSection(i) || super.sections[i] == CharBlocks.EMPTY) { continue; } - ChunkSection existing = getSections()[i]; + ChunkSection existing = getSections(false)[i]; try { final DataPaletteBlock blocksExisting = existing.getBlocks(); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_4/BukkitGetBlocks_1_16_4.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_4/BukkitGetBlocks_1_16_4.java index 061ba338e..e43987767 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_4/BukkitGetBlocks_1_16_4.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_4/BukkitGetBlocks_1_16_4.java @@ -1,6 +1,7 @@ package com.boydti.fawe.bukkit.adapter.mc1_16_4; import com.boydti.fawe.Fawe; +import com.boydti.fawe.FaweAPI; import com.boydti.fawe.FaweCache; import com.boydti.fawe.beta.IChunkGet; import com.boydti.fawe.beta.IChunkSet; @@ -27,8 +28,10 @@ import com.sk89q.worldedit.internal.Constants; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockTypes; +import com.sk89q.worldedit.world.block.BlockTypesCache; import net.minecraft.server.v1_16_R3.BiomeBase; import net.minecraft.server.v1_16_R3.BiomeStorage; +import net.minecraft.server.v1_16_R3.Block; import net.minecraft.server.v1_16_R3.BlockPosition; import net.minecraft.server.v1_16_R3.Chunk; import net.minecraft.server.v1_16_R3.ChunkSection; @@ -400,7 +403,7 @@ public class BukkitGetBlocks_1_16_4 extends CharGetBlocks { this.nmsChunk = nmsChunk; this.sections = null; this.reset(); - } else if (existingSection != getSections()[layer]) { + } else if (existingSection != getSections(false)[layer]) { this.sections[layer] = existingSection; this.reset(); } else if (!Arrays.equals(update(layer, new char[4096]), load(layer))) { @@ -647,7 +650,7 @@ public class BukkitGetBlocks_1_16_4 extends CharGetBlocks { @Override public synchronized char[] update(int layer, char[] data) { - ChunkSection section = getSections()[layer]; + ChunkSection section = getSections(true)[layer]; // Section is null, return empty array if (section == null) { data = new char[4096]; @@ -762,7 +765,10 @@ public class BukkitGetBlocks_1_16_4 extends CharGetBlocks { } } - public ChunkSection[] getSections() { + public ChunkSection[] getSections(boolean force) { + if (force) { + return sections = getChunk().getSections().clone(); + } ChunkSection[] tmp = sections; if (tmp == null) { synchronized (this) { @@ -814,7 +820,7 @@ public class BukkitGetBlocks_1_16_4 extends CharGetBlocks { @Override public boolean hasSection(int layer) { - return getSections()[layer] != null; + return getSections(false)[layer] != null; } @Override @@ -830,7 +836,7 @@ public class BukkitGetBlocks_1_16_4 extends CharGetBlocks { if (!hasSection(i) || super.sections[i] == CharBlocks.EMPTY) { continue; } - ChunkSection existing = getSections()[i]; + ChunkSection existing = getSections(false)[i]; try { final DataPaletteBlock blocksExisting = existing.getBlocks();