From 89cc2f9d9f1fed47b73fdd4cdfe07757ff61cdbe Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Tue, 5 Jan 2021 15:03:47 +0000 Subject: [PATCH] Large memory use reduction when PostProcessing history --- .../mc1_15_2/BukkitGetBlocks_1_15_2.java | 10 +-- .../mc1_15_2/BukkitGetBlocks_1_15_2_Copy.java | 77 ++++++++++++++---- .../mc1_16_1/BukkitGetBlocks_1_16_1.java | 10 +-- .../mc1_16_1/BukkitGetBlocks_1_16_1_Copy.java | 78 +++++++++++++++---- .../mc1_16_2/BukkitGetBlocks_1_16_2.java | 10 +-- .../mc1_16_2/BukkitGetBlocks_1_16_2_Copy.java | 77 ++++++++++++++---- .../mc1_16_4/BukkitGetBlocks_1_16_4.java | 10 +-- .../mc1_16_4/BukkitGetBlocks_1_16_4_Copy.java | 77 ++++++++++++++---- .../com/boydti/fawe/beta/IChunkGetCopy.java | 6 -- .../object/changeset/AbstractChangeSet.java | 11 +-- 10 files changed, 269 insertions(+), 97 deletions(-) delete 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 b6b2380a2..c4a9dfc9c 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 @@ -4,7 +4,6 @@ import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; import com.boydti.fawe.beta.IChunkGet; import com.boydti.fawe.beta.IChunkSet; -import com.boydti.fawe.beta.implementation.blocks.CharBlocks; import com.boydti.fawe.beta.implementation.blocks.CharGetBlocks; import com.boydti.fawe.beta.implementation.lighting.HeightMapType; import com.boydti.fawe.beta.implementation.queue.QueueHandler; @@ -318,7 +317,7 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks { @Override public > T call(IChunkSet set, Runnable finalizer) { forceLoadSections = false; - copy = createCopy ? new BukkitGetBlocks_1_15_2_Copy(world, getChunkX(), getChunkZ()) : null; + copy = createCopy ? new BukkitGetBlocks_1_15_2_Copy(world) : null; try { WorldServer nmsWorld = world; Chunk nmsChunk = ensureLoaded(nmsWorld, chunkX, chunkZ); @@ -362,12 +361,9 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks { 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. + char[] setArr = set.load(layer).clone(); if (createCopy) { - copy.storeSection(layer); - copy.storeSetBlocks(layer, setArr); + copy.storeSection(layer, load(layer).clone()); } ChunkSection newSection; 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 837676daa..8fddf5db1 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,7 +2,10 @@ package com.boydti.fawe.bukkit.adapter.mc1_15_2; import com.boydti.fawe.FaweCache; -import com.boydti.fawe.beta.IChunkGetCopy; +import com.boydti.fawe.beta.IBlocks; +import com.boydti.fawe.beta.IChunkGet; +import com.boydti.fawe.beta.IChunkSet; +import com.boydti.fawe.beta.implementation.lighting.HeightMapType; 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; @@ -22,23 +25,25 @@ import net.minecraft.server.v1_15_R1.TileEntity; import net.minecraft.server.v1_15_R1.WorldServer; import org.bukkit.craftbukkit.v1_15_R1.block.CraftBlock; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Range; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.concurrent.Future; -public class BukkitGetBlocks_1_15_2_Copy extends BukkitGetBlocks_1_15_2 implements IChunkGetCopy { +public class BukkitGetBlocks_1_15_2_Copy implements IChunkGet { 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][]; + private final char[][] blocks = new char[16][]; + private final WorldServer world; - protected BukkitGetBlocks_1_15_2_Copy(WorldServer world, int X, int Z) { - super(world, X, Z); + protected BukkitGetBlocks_1_15_2_Copy(WorldServer world) { + this.world = world; } protected void storeTile(TileEntity tile) { @@ -89,6 +94,16 @@ public class BukkitGetBlocks_1_15_2_Copy extends BukkitGetBlocks_1_15_2 implemen return null; } + @Override + public void setCreateCopy(boolean createCopy) { + + } + + @Override + public boolean isCreateCopy() { + return false; + } + protected void storeBiomes(BiomeStorage biomeStorage) { this.biomeStorage = new BiomeStorage(BukkitAdapter_1_15_2.getBiomeArray(biomeStorage).clone()); } @@ -107,8 +122,18 @@ public class BukkitGetBlocks_1_15_2_Copy extends BukkitGetBlocks_1_15_2 implemen return base != null ? BukkitAdapter.adapt(CraftBlock.biomeBaseToBiome(base)) : null; } - protected void storeSection(int layer) { - blocks[layer] = load(layer).clone(); + @Override + public boolean trim(boolean aggressive, int layer) { + return false; + } + + @Override + public IBlocks reset() { + return null; + } + + protected void storeSection(int layer, char[] data) { + blocks[layer] = data; } @Override @@ -117,24 +142,50 @@ public class BukkitGetBlocks_1_15_2_Copy extends BukkitGetBlocks_1_15_2 implemen return state.toBaseBlock(this, x, y, z); } + @Override + public boolean hasSection(@Range(from = 0, to = 15) int layer) { + return blocks[layer] != null; + } + + @Override + public char[] load(int layer) { + return blocks[layer]; + } + @Override public BlockState getBlock(int x, int y, int z) { return BlockTypesCache.states[get(x, y, z)]; } @Override + public int getSkyLight(int x, int y, int z) { + return 0; + } + + @Override + public int getEmmittedLight(int x, int y, int z) { + return 0; + } + + @Override + public int[] getHeightMap(HeightMapType type) { + return new int[0]; + } + + @Override + public > T call(IChunkSet set, Runnable finalize) { + return null; + } + public char get(int x, int y, int z) { final int layer = y >> 4; final int index = (y & 15) << 8 | z << 4 | x; return blocks[layer][index]; } - protected void storeSetBlocks(int layer, char[] blocks) { - newSetBlocks[layer] = blocks.clone(); - } @Override - public char[] getNewSetArr(int layer) { - return newSetBlocks[layer]; + public boolean trim(boolean aggressive) { + return false; } } 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 3a5a68338..bf2ca9670 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 @@ -4,7 +4,6 @@ import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; import com.boydti.fawe.beta.IChunkGet; import com.boydti.fawe.beta.IChunkSet; -import com.boydti.fawe.beta.implementation.blocks.CharBlocks; import com.boydti.fawe.beta.implementation.blocks.CharGetBlocks; import com.boydti.fawe.beta.implementation.lighting.HeightMapType; import com.boydti.fawe.beta.implementation.queue.QueueHandler; @@ -318,7 +317,7 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks { @Override public > T call(IChunkSet set, Runnable finalizer) { forceLoadSections = false; - copy = createCopy ? new BukkitGetBlocks_1_16_1_Copy(world, getChunkX(), getChunkZ()) : null; + copy = createCopy ? new BukkitGetBlocks_1_16_1_Copy(world) : null; try { WorldServer nmsWorld = world; Chunk nmsChunk = ensureLoaded(nmsWorld, chunkX, chunkZ); @@ -362,12 +361,9 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks { 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. + char[] setArr = set.load(layer).clone(); if (createCopy) { - copy.storeSection(layer); - copy.storeSetBlocks(layer, setArr); + copy.storeSection(layer, load(layer).clone()); } ChunkSection newSection; 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 2cd174af9..634d2c5ff 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,7 +2,10 @@ package com.boydti.fawe.bukkit.adapter.mc1_16_1; import com.boydti.fawe.FaweCache; -import com.boydti.fawe.beta.IChunkGetCopy; +import com.boydti.fawe.beta.IBlocks; +import com.boydti.fawe.beta.IChunkGet; +import com.boydti.fawe.beta.IChunkSet; +import com.boydti.fawe.beta.implementation.lighting.HeightMapType; 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; @@ -17,29 +20,30 @@ import com.sk89q.worldedit.world.block.BlockTypesCache; import net.minecraft.server.v1_16_R1.BiomeBase; import net.minecraft.server.v1_16_R1.BiomeStorage; import net.minecraft.server.v1_16_R1.Entity; -import net.minecraft.server.v1_16_R1.IRegistry; import net.minecraft.server.v1_16_R1.NBTTagCompound; import net.minecraft.server.v1_16_R1.TileEntity; import net.minecraft.server.v1_16_R1.WorldServer; import org.bukkit.craftbukkit.v1_16_R1.block.CraftBlock; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Range; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.concurrent.Future; -public class BukkitGetBlocks_1_16_1_Copy extends BukkitGetBlocks_1_16_1 implements IChunkGetCopy { +public class BukkitGetBlocks_1_16_1_Copy implements IChunkGet { 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][]; + private final char[][] blocks = new char[16][]; + private final WorldServer world; - protected BukkitGetBlocks_1_16_1_Copy(WorldServer world, int X, int Z) { - super(world, X, Z); + protected BukkitGetBlocks_1_16_1_Copy(WorldServer world) { + this.world = world; } protected void storeTile(TileEntity tile) { @@ -90,6 +94,16 @@ public class BukkitGetBlocks_1_16_1_Copy extends BukkitGetBlocks_1_16_1 implemen return null; } + @Override + public void setCreateCopy(boolean createCopy) { + + } + + @Override + public boolean isCreateCopy() { + return false; + } + protected void storeBiomes(BiomeStorage biomeStorage) { this.biomeStorage = new BiomeStorage(BukkitAdapter_1_16_1.getBiomeArray(biomeStorage).clone()); } @@ -108,8 +122,18 @@ public class BukkitGetBlocks_1_16_1_Copy extends BukkitGetBlocks_1_16_1 implemen return base != null ? BukkitAdapter.adapt(CraftBlock.biomeBaseToBiome(base)) : null; } - protected void storeSection(int layer) { - blocks[layer] = load(layer).clone(); + @Override + public boolean trim(boolean aggressive, int layer) { + return false; + } + + @Override + public IBlocks reset() { + return null; + } + + protected void storeSection(int layer, char[] data) { + blocks[layer] = data; } @Override @@ -118,24 +142,50 @@ public class BukkitGetBlocks_1_16_1_Copy extends BukkitGetBlocks_1_16_1 implemen return state.toBaseBlock(this, x, y, z); } + @Override + public boolean hasSection(@Range(from = 0, to = 15) int layer) { + return blocks[layer] != null; + } + + @Override + public char[] load(int layer) { + return blocks[layer]; + } + @Override public BlockState getBlock(int x, int y, int z) { return BlockTypesCache.states[get(x, y, z)]; } @Override + public int getSkyLight(int x, int y, int z) { + return 0; + } + + @Override + public int getEmmittedLight(int x, int y, int z) { + return 0; + } + + @Override + public int[] getHeightMap(HeightMapType type) { + return new int[0]; + } + + @Override + public > T call(IChunkSet set, Runnable finalize) { + return null; + } + public char get(int x, int y, int z) { final int layer = y >> 4; final int index = (y & 15) << 8 | z << 4 | x; return blocks[layer][index]; } - protected void storeSetBlocks(int layer, char[] blocks) { - newSetBlocks[layer] = blocks.clone(); - } @Override - public char[] getNewSetArr(int layer) { - return newSetBlocks[layer]; + public boolean trim(boolean aggressive) { + return false; } } 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 5a8873114..e5c0dc447 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 @@ -4,7 +4,6 @@ import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; import com.boydti.fawe.beta.IChunkGet; import com.boydti.fawe.beta.IChunkSet; -import com.boydti.fawe.beta.implementation.blocks.CharBlocks; import com.boydti.fawe.beta.implementation.blocks.CharGetBlocks; import com.boydti.fawe.beta.implementation.lighting.HeightMapType; import com.boydti.fawe.beta.implementation.queue.QueueHandler; @@ -321,7 +320,7 @@ public class BukkitGetBlocks_1_16_2 extends CharGetBlocks { @Override public > T call(IChunkSet set, Runnable finalizer) { forceLoadSections = false; - copy = createCopy ? new BukkitGetBlocks_1_16_2_Copy(world, getChunkX(), getChunkZ()) : null; + copy = createCopy ? new BukkitGetBlocks_1_16_2_Copy(world) : null; try { WorldServer nmsWorld = world; Chunk nmsChunk = ensureLoaded(nmsWorld, chunkX, chunkZ); @@ -365,12 +364,9 @@ public class BukkitGetBlocks_1_16_2 extends CharGetBlocks { 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. + char[] setArr = set.load(layer).clone(); if (createCopy) { - copy.storeSection(layer); - copy.storeSetBlocks(layer, setArr); + copy.storeSection(layer, load(layer).clone()); } ChunkSection newSection; 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 c0086e180..bb772de71 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,7 +2,10 @@ package com.boydti.fawe.bukkit.adapter.mc1_16_2; import com.boydti.fawe.FaweCache; -import com.boydti.fawe.beta.IChunkGetCopy; +import com.boydti.fawe.beta.IBlocks; +import com.boydti.fawe.beta.IChunkGet; +import com.boydti.fawe.beta.IChunkSet; +import com.boydti.fawe.beta.implementation.lighting.HeightMapType; 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; @@ -23,23 +26,25 @@ import net.minecraft.server.v1_16_R2.TileEntity; import net.minecraft.server.v1_16_R2.WorldServer; import org.bukkit.craftbukkit.v1_16_R2.block.CraftBlock; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Range; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.concurrent.Future; -public class BukkitGetBlocks_1_16_2_Copy extends BukkitGetBlocks_1_16_2 implements IChunkGetCopy { +public class BukkitGetBlocks_1_16_2_Copy implements IChunkGet { 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][]; + private final char[][] blocks = new char[16][]; + private final WorldServer world; - protected BukkitGetBlocks_1_16_2_Copy(WorldServer world, int X, int Z) { - super(world, X, Z); + protected BukkitGetBlocks_1_16_2_Copy(WorldServer world) { + this.world = world; } protected void storeTile(TileEntity tile) { @@ -90,6 +95,16 @@ public class BukkitGetBlocks_1_16_2_Copy extends BukkitGetBlocks_1_16_2 implemen return null; } + @Override + public void setCreateCopy(boolean createCopy) { + + } + + @Override + public boolean isCreateCopy() { + return false; + } + protected void storeBiomes(BiomeStorage biomeStorage) { this.biomeStorage = new BiomeStorage(biomeStorage.g, BukkitAdapter_1_16_2.getBiomeArray(biomeStorage).clone()); } @@ -108,8 +123,18 @@ public class BukkitGetBlocks_1_16_2_Copy extends BukkitGetBlocks_1_16_2 implemen return base != null ? BukkitAdapter.adapt(CraftBlock.biomeBaseToBiome(world.r().b(IRegistry.ay), base)) : null; } - protected void storeSection(int layer) { - blocks[layer] = load(layer).clone(); + @Override + public boolean trim(boolean aggressive, int layer) { + return false; + } + + @Override + public IBlocks reset() { + return null; + } + + protected void storeSection(int layer, char[] data) { + blocks[layer] = data; } @Override @@ -118,24 +143,50 @@ public class BukkitGetBlocks_1_16_2_Copy extends BukkitGetBlocks_1_16_2 implemen return state.toBaseBlock(this, x, y, z); } + @Override + public boolean hasSection(@Range(from = 0, to = 15) int layer) { + return blocks[layer] != null; + } + + @Override + public char[] load(int layer) { + return blocks[layer]; + } + @Override public BlockState getBlock(int x, int y, int z) { return BlockTypesCache.states[get(x, y, z)]; } @Override + public int getSkyLight(int x, int y, int z) { + return 0; + } + + @Override + public int getEmmittedLight(int x, int y, int z) { + return 0; + } + + @Override + public int[] getHeightMap(HeightMapType type) { + return new int[0]; + } + + @Override + public > T call(IChunkSet set, Runnable finalize) { + return null; + } + public char get(int x, int y, int z) { final int layer = y >> 4; final int index = (y & 15) << 8 | z << 4 | x; return blocks[layer][index]; } - protected void storeSetBlocks(int layer, char[] blocks) { - newSetBlocks[layer] = blocks.clone(); - } @Override - public char[] getNewSetArr(int layer) { - return newSetBlocks[layer]; + public boolean trim(boolean aggressive) { + return false; } } 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 8fb195641..d07e4b8f2 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 @@ -4,7 +4,6 @@ import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; import com.boydti.fawe.beta.IChunkGet; import com.boydti.fawe.beta.IChunkSet; -import com.boydti.fawe.beta.implementation.blocks.CharBlocks; import com.boydti.fawe.beta.implementation.blocks.CharGetBlocks; import com.boydti.fawe.beta.implementation.lighting.HeightMapType; import com.boydti.fawe.beta.implementation.queue.QueueHandler; @@ -321,7 +320,7 @@ public class BukkitGetBlocks_1_16_4 extends CharGetBlocks { @Override public > T call(IChunkSet set, Runnable finalizer) { forceLoadSections = false; - copy = createCopy ? new BukkitGetBlocks_1_16_4_Copy(world, getChunkX(), getChunkZ()) : null; + copy = createCopy ? new BukkitGetBlocks_1_16_4_Copy(world) : null; try { WorldServer nmsWorld = world; Chunk nmsChunk = ensureLoaded(nmsWorld, chunkX, chunkZ); @@ -365,12 +364,9 @@ public class BukkitGetBlocks_1_16_4 extends CharGetBlocks { 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. + char[] setArr = set.load(layer).clone(); if (createCopy) { - copy.storeSection(layer); - copy.storeSetBlocks(layer, setArr); + copy.storeSection(layer, load(layer).clone()); } ChunkSection newSection; 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 da2980d1e..3f1db2730 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,7 +2,10 @@ package com.boydti.fawe.bukkit.adapter.mc1_16_4; import com.boydti.fawe.FaweCache; -import com.boydti.fawe.beta.IChunkGetCopy; +import com.boydti.fawe.beta.IBlocks; +import com.boydti.fawe.beta.IChunkGet; +import com.boydti.fawe.beta.IChunkSet; +import com.boydti.fawe.beta.implementation.lighting.HeightMapType; 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; @@ -23,23 +26,25 @@ import net.minecraft.server.v1_16_R3.TileEntity; import net.minecraft.server.v1_16_R3.WorldServer; import org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Range; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.concurrent.Future; -public class BukkitGetBlocks_1_16_4_Copy extends BukkitGetBlocks_1_16_4 implements IChunkGetCopy { +public class BukkitGetBlocks_1_16_4_Copy implements IChunkGet { 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][]; + private final char[][] blocks = new char[16][]; + private final WorldServer world; - protected BukkitGetBlocks_1_16_4_Copy(WorldServer world, int X, int Z) { - super(world, X, Z); + protected BukkitGetBlocks_1_16_4_Copy(WorldServer world) { + this.world = world; } protected void storeTile(TileEntity tile) { @@ -90,6 +95,16 @@ public class BukkitGetBlocks_1_16_4_Copy extends BukkitGetBlocks_1_16_4 implemen return null; } + @Override + public void setCreateCopy(boolean createCopy) { + + } + + @Override + public boolean isCreateCopy() { + return false; + } + protected void storeBiomes(BiomeStorage biomeStorage) { this.biomeStorage = new BiomeStorage(biomeStorage.g, BukkitAdapter_1_16_4.getBiomeArray(biomeStorage).clone()); } @@ -108,8 +123,18 @@ public class BukkitGetBlocks_1_16_4_Copy extends BukkitGetBlocks_1_16_4 implemen return base != null ? BukkitAdapter.adapt(CraftBlock.biomeBaseToBiome(world.r().b(IRegistry.ay), base)) : null; } - protected void storeSection(int layer) { - blocks[layer] = load(layer).clone(); + @Override + public boolean trim(boolean aggressive, int layer) { + return false; + } + + @Override + public IBlocks reset() { + return null; + } + + protected void storeSection(int layer, char[] data) { + blocks[layer] = data; } @Override @@ -118,24 +143,50 @@ public class BukkitGetBlocks_1_16_4_Copy extends BukkitGetBlocks_1_16_4 implemen return state.toBaseBlock(this, x, y, z); } + @Override + public boolean hasSection(@Range(from = 0, to = 15) int layer) { + return blocks[layer] != null; + } + + @Override + public char[] load(int layer) { + return blocks[layer]; + } + @Override public BlockState getBlock(int x, int y, int z) { return BlockTypesCache.states[get(x, y, z)]; } @Override + public int getSkyLight(int x, int y, int z) { + return 0; + } + + @Override + public int getEmmittedLight(int x, int y, int z) { + return 0; + } + + @Override + public int[] getHeightMap(HeightMapType type) { + return new int[0]; + } + + @Override + public > T call(IChunkSet set, Runnable finalize) { + return null; + } + public char get(int x, int y, int z) { final int layer = y >> 4; final int index = (y & 15) << 8 | z << 4 | x; return blocks[layer][index]; } - protected void storeSetBlocks(int layer, char[] blocks) { - newSetBlocks[layer] = blocks.clone(); - } @Override - public char[] getNewSetArr(int layer) { - return newSetBlocks[layer]; + public boolean trim(boolean aggressive) { + return false; } } 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 deleted file mode 100644 index 87b3b4396..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkGetCopy.java +++ /dev/null @@ -1,6 +0,0 @@ -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 5ba55d849..bf90ebc6a 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,7 +5,6 @@ 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; @@ -157,7 +156,6 @@ 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,11 +166,7 @@ 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; @@ -189,9 +183,6 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor { if (combinedTo != 0) { add(xx, yy, zz, combinedFrom, combinedTo); } - if (updateSet) { - blocksSet[index] = newBlocksSet[index]; - } } } }