From b57c472b86f1cac4d5e9aba92503251390e3521e Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Thu, 17 Dec 2020 14:09:54 +0000 Subject: [PATCH] Save the get blocks to the set chunk after history is written when post-processing --- .../mc1_15_2/BukkitGetBlocks_1_15_2.java | 11 +++++++--- .../mc1_15_2/BukkitGetBlocks_1_15_2_Copy.java | 13 +++++++++++- .../mc1_16_1/BukkitGetBlocks_1_16_1.java | 11 +++++++--- .../mc1_16_1/BukkitGetBlocks_1_16_1_Copy.java | 13 +++++++++++- .../mc1_16_2/BukkitGetBlocks_1_16_2.java | 11 +++++++--- .../mc1_16_2/BukkitGetBlocks_1_16_2_Copy.java | 13 +++++++++++- .../mc1_16_4/BukkitGetBlocks_1_16_4.java | 11 +++++++--- .../mc1_16_4/BukkitGetBlocks_1_16_4_Copy.java | 13 +++++++++++- .../com/boydti/fawe/beta/IChunkGetCopy.java | 6 ++++++ .../object/changeset/AbstractChangeSet.java | 20 ++++++++++++++----- 10 files changed, 101 insertions(+), 21 deletions(-) create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkGetCopy.java 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 0cb058215..40d082be9 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 @@ -357,13 +357,18 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks { if (!set.hasSection(layer)) { continue; } - if (createCopy) { - copy.storeSection(layer); - } bitMask |= 1 << layer; char[] setArr = set.load(layer); + // If we're creating a copy, it's because we're delaying history so we do not want to write to + // the chunkSet yet. + if (createCopy) { + setArr = setArr.clone(); + copy.storeSection(layer); + copy.storeSetBlocks(layer, setArr); + } + ChunkSection newSection; ChunkSection existingSection = sections[layer]; if (existingSection == null) { diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitGetBlocks_1_15_2_Copy.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitGetBlocks_1_15_2_Copy.java index a9aef70f4..19fb70d5d 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitGetBlocks_1_15_2_Copy.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitGetBlocks_1_15_2_Copy.java @@ -2,6 +2,7 @@ package com.boydti.fawe.bukkit.adapter.mc1_15_2; import com.boydti.fawe.FaweCache; +import com.boydti.fawe.beta.IChunkGetCopy; import com.boydti.fawe.bukkit.adapter.mc1_15_2.nbt.LazyCompoundTag_1_15_2; import com.google.common.base.Suppliers; import com.sk89q.jnbt.CompoundTag; @@ -28,12 +29,13 @@ import java.util.Map; import java.util.Set; import java.util.UUID; -public class BukkitGetBlocks_1_15_2_Copy extends BukkitGetBlocks_1_15_2 { +public class BukkitGetBlocks_1_15_2_Copy extends BukkitGetBlocks_1_15_2 implements IChunkGetCopy { private final Map tiles = new HashMap<>(); private final Set entities = new HashSet<>(); private BiomeStorage biomeStorage; private final char[][] blocks = new char[16][4096]; + private final char[][] newSetBlocks = new char[16][]; protected BukkitGetBlocks_1_15_2_Copy(WorldServer world, int X, int Z) { super(world, X, Z); @@ -126,4 +128,13 @@ public class BukkitGetBlocks_1_15_2_Copy extends BukkitGetBlocks_1_15_2 { final int index = (y & 15) << 8 | z << 4 | x; return blocks[layer][index]; } + + protected void storeSetBlocks(int layer, char[] blocks) { + newSetBlocks[layer] = blocks; + } + + @Override + public char[] getNewSetArr(int layer) { + return newSetBlocks[layer]; + } } 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 a2538a143..9ab5ff383 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 @@ -357,13 +357,18 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks { if (!set.hasSection(layer)) { continue; } - if (createCopy) { - copy.storeSection(layer); - } bitMask |= 1 << layer; char[] setArr = set.load(layer); + // If we're creating a copy, it's because we're delaying history so we do not want to write to + // the chunkSet yet. + if (createCopy) { + setArr = setArr.clone(); + copy.storeSection(layer); + copy.storeSetBlocks(layer, setArr); + } + ChunkSection newSection; ChunkSection existingSection = sections[layer]; if (existingSection == null) { diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_1/BukkitGetBlocks_1_16_1_Copy.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_1/BukkitGetBlocks_1_16_1_Copy.java index 9b9dc3697..5deaaa901 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_1/BukkitGetBlocks_1_16_1_Copy.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_1/BukkitGetBlocks_1_16_1_Copy.java @@ -2,6 +2,7 @@ package com.boydti.fawe.bukkit.adapter.mc1_16_1; import com.boydti.fawe.FaweCache; +import com.boydti.fawe.beta.IChunkGetCopy; import com.boydti.fawe.bukkit.adapter.mc1_16_1.nbt.LazyCompoundTag_1_16_1; import com.google.common.base.Suppliers; import com.sk89q.jnbt.CompoundTag; @@ -29,12 +30,13 @@ import java.util.Map; import java.util.Set; import java.util.UUID; -public class BukkitGetBlocks_1_16_1_Copy extends BukkitGetBlocks_1_16_1 { +public class BukkitGetBlocks_1_16_1_Copy extends BukkitGetBlocks_1_16_1 implements IChunkGetCopy { private final Map tiles = new HashMap<>(); private final Set entities = new HashSet<>(); private BiomeStorage biomeStorage; private final char[][] blocks = new char[16][4096]; + private final char[][] newSetBlocks = new char[16][]; protected BukkitGetBlocks_1_16_1_Copy(WorldServer world, int X, int Z) { super(world, X, Z); @@ -127,4 +129,13 @@ public class BukkitGetBlocks_1_16_1_Copy extends BukkitGetBlocks_1_16_1 { final int index = (y & 15) << 8 | z << 4 | x; return blocks[layer][index]; } + + protected void storeSetBlocks(int layer, char[] blocks) { + newSetBlocks[layer] = blocks; + } + + @Override + public char[] getNewSetArr(int layer) { + return newSetBlocks[layer]; + } } 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 e19038d48..e63973c68 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 @@ -360,13 +360,18 @@ public class BukkitGetBlocks_1_16_2 extends CharGetBlocks { if (!set.hasSection(layer)) { continue; } - if (createCopy) { - copy.storeSection(layer); - } bitMask |= 1 << layer; char[] setArr = set.load(layer); + // If we're creating a copy, it's because we're delaying history so we do not want to write to + // the chunkSet yet. + if (createCopy) { + setArr = setArr.clone(); + copy.storeSection(layer); + copy.storeSetBlocks(layer, setArr); + } + ChunkSection newSection; ChunkSection existingSection = sections[layer]; if (existingSection == null) { diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitGetBlocks_1_16_2_Copy.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitGetBlocks_1_16_2_Copy.java index ac80fe3f1..dccf17358 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitGetBlocks_1_16_2_Copy.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitGetBlocks_1_16_2_Copy.java @@ -2,6 +2,7 @@ package com.boydti.fawe.bukkit.adapter.mc1_16_2; import com.boydti.fawe.FaweCache; +import com.boydti.fawe.beta.IChunkGetCopy; import com.boydti.fawe.bukkit.adapter.mc1_16_2.nbt.LazyCompoundTag_1_16_2; import com.google.common.base.Suppliers; import com.sk89q.jnbt.CompoundTag; @@ -29,12 +30,13 @@ import java.util.Map; import java.util.Set; import java.util.UUID; -public class BukkitGetBlocks_1_16_2_Copy extends BukkitGetBlocks_1_16_2 { +public class BukkitGetBlocks_1_16_2_Copy extends BukkitGetBlocks_1_16_2 implements IChunkGetCopy { private final Map tiles = new HashMap<>(); private final Set entities = new HashSet<>(); private BiomeStorage biomeStorage; private final char[][] blocks = new char[16][4096]; + private final char[][] newSetBlocks = new char[16][]; protected BukkitGetBlocks_1_16_2_Copy(WorldServer world, int X, int Z) { super(world, X, Z); @@ -127,4 +129,13 @@ public class BukkitGetBlocks_1_16_2_Copy extends BukkitGetBlocks_1_16_2 { final int index = (y & 15) << 8 | z << 4 | x; return blocks[layer][index]; } + + protected void storeSetBlocks(int layer, char[] blocks) { + newSetBlocks[layer] = blocks; + } + + @Override + public char[] getNewSetArr(int layer) { + return newSetBlocks[layer]; + } } 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 962fd3a7b..061ba338e 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 @@ -360,13 +360,18 @@ public class BukkitGetBlocks_1_16_4 extends CharGetBlocks { if (!set.hasSection(layer)) { continue; } - if (createCopy) { - copy.storeSection(layer); - } bitMask |= 1 << layer; char[] setArr = set.load(layer); + // If we're creating a copy, it's because we're delaying history so we do not want to write to + // the chunkSet yet. + if (createCopy) { + setArr = setArr.clone(); + copy.storeSection(layer); + copy.storeSetBlocks(layer, setArr); + } + ChunkSection newSection; ChunkSection existingSection = sections[layer]; if (existingSection == null) { diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_4/BukkitGetBlocks_1_16_4_Copy.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_4/BukkitGetBlocks_1_16_4_Copy.java index 2eec240cb..3a2ebe25f 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_4/BukkitGetBlocks_1_16_4_Copy.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_4/BukkitGetBlocks_1_16_4_Copy.java @@ -2,6 +2,7 @@ package com.boydti.fawe.bukkit.adapter.mc1_16_4; import com.boydti.fawe.FaweCache; +import com.boydti.fawe.beta.IChunkGetCopy; import com.boydti.fawe.bukkit.adapter.mc1_16_4.nbt.LazyCompoundTag_1_16_4; import com.google.common.base.Suppliers; import com.sk89q.jnbt.CompoundTag; @@ -29,12 +30,13 @@ import java.util.Map; import java.util.Set; import java.util.UUID; -public class BukkitGetBlocks_1_16_4_Copy extends BukkitGetBlocks_1_16_4 { +public class BukkitGetBlocks_1_16_4_Copy extends BukkitGetBlocks_1_16_4 implements IChunkGetCopy { private final Map tiles = new HashMap<>(); private final Set entities = new HashSet<>(); private BiomeStorage biomeStorage; private final char[][] blocks = new char[16][4096]; + private final char[][] newSetBlocks = new char[16][]; protected BukkitGetBlocks_1_16_4_Copy(WorldServer world, int X, int Z) { super(world, X, Z); @@ -127,4 +129,13 @@ public class BukkitGetBlocks_1_16_4_Copy extends BukkitGetBlocks_1_16_4 { final int index = (y & 15) << 8 | z << 4 | x; return blocks[layer][index]; } + + protected void storeSetBlocks(int layer, char[] blocks) { + newSetBlocks[layer] = blocks; + } + + @Override + public char[] getNewSetArr(int layer) { + return newSetBlocks[layer]; + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkGetCopy.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkGetCopy.java new file mode 100644 index 000000000..87b3b4396 --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkGetCopy.java @@ -0,0 +1,6 @@ +package com.boydti.fawe.beta; + +public interface IChunkGetCopy { + + char[] getNewSetArr(int layer); +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractChangeSet.java index dad021ee1..29dbef3e3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractChangeSet.java @@ -5,6 +5,7 @@ import com.boydti.fawe.FaweCache; import com.boydti.fawe.beta.IBatchProcessor; import com.boydti.fawe.beta.IChunk; import com.boydti.fawe.beta.IChunkGet; +import com.boydti.fawe.beta.IChunkGetCopy; import com.boydti.fawe.beta.IChunkSet; import com.boydti.fawe.object.HistoryExtent; import com.boydti.fawe.util.EditSessionBuilder; @@ -158,6 +159,7 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor { addEntityCreate(tag); } } + boolean updateSet = get instanceof IChunkGetCopy; for (int layer = 0; layer < 16; layer++) { if (!set.hasSection(layer)) { continue; @@ -168,7 +170,11 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor { blocksGet = FaweCache.IMP.EMPTY_CHAR_4096; } char[] blocksSet = set.load(layer); - + char[] newBlocksSet = null; + if (updateSet) { + newBlocksSet = ((IChunkGetCopy) get).getNewSetArr(layer); + } +; int by = layer << 4; for (int y = 0, index = 0; y < 16; y++) { int yy = y + by; @@ -176,14 +182,18 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor { int zz = z + bz; for (int x = 0; x < 16; x++, index++) { int xx = bx + x; - int combinedFrom = blocksGet[index]; - if (combinedFrom == 0) { - combinedFrom = BlockID.AIR; + int from = blocksGet[index]; + if (from == 0) { + from = BlockID.AIR; } - int combinedTo = blocksSet[index]; + final int combinedFrom = from; + final int combinedTo = blocksSet[index]; if (combinedTo != 0) { add(xx, yy, zz, combinedFrom, combinedTo); } + if (updateSet) { + blocksSet[index] = newBlocksSet[index]; + } } } }