From 2c85ff1673cb7ab5893f5fb0635d606bd1c6042b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Tue, 21 Apr 2020 15:23:23 +0200 Subject: [PATCH 1/3] Properly remove tile entities in BukkitGetBlocks_1_15_2 --- .../mc1_15_2/BukkitGetBlocks_1_15_2.java | 46 +++++++++++++++---- 1 file changed, 38 insertions(+), 8 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 6c748660b..13f2bc1d4 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 @@ -11,8 +11,11 @@ import com.boydti.fawe.object.collection.AdaptedMap; import com.boydti.fawe.object.collection.BitArray4096; import com.google.common.base.Suppliers; import com.google.common.collect.Iterables; +import com.sk89q.jnbt.CompoundTag; +import com.sk89q.jnbt.ListTag; +import com.sk89q.jnbt.LongTag; +import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; -import com.sk89q.jnbt.*; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; @@ -21,21 +24,47 @@ 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 net.minecraft.server.v1_15_R1.*; +import net.minecraft.server.v1_15_R1.BiomeBase; +import net.minecraft.server.v1_15_R1.BiomeStorage; +import net.minecraft.server.v1_15_R1.BlockPosition; +import net.minecraft.server.v1_15_R1.Chunk; +import net.minecraft.server.v1_15_R1.ChunkSection; +import net.minecraft.server.v1_15_R1.DataBits; +import net.minecraft.server.v1_15_R1.DataPalette; +import net.minecraft.server.v1_15_R1.DataPaletteBlock; +import net.minecraft.server.v1_15_R1.DataPaletteHash; +import net.minecraft.server.v1_15_R1.DataPaletteLinear; +import net.minecraft.server.v1_15_R1.Entity; +import net.minecraft.server.v1_15_R1.EntityTypes; +import net.minecraft.server.v1_15_R1.IBlockData; +import net.minecraft.server.v1_15_R1.LightEngineThreaded; +import net.minecraft.server.v1_15_R1.NBTTagCompound; +import net.minecraft.server.v1_15_R1.NBTTagInt; +import net.minecraft.server.v1_15_R1.TileEntity; +import net.minecraft.server.v1_15_R1.WorldServer; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.craftbukkit.v1_15_R1.block.CraftBlock; import org.bukkit.event.entity.CreatureSpawnEvent; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.annotation.Nullable; -import java.util.*; +import java.util.AbstractSet; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.Callable; import java.util.concurrent.Future; import java.util.function.Function; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import static org.slf4j.LoggerFactory.getLogger; @@ -217,7 +246,8 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks { // Remove existing tiles { - Map tiles = nmsChunk.getTileEntities(); + // Create a copy so that we can remove blocks + Map tiles = new HashMap<>(nmsChunk.getTileEntities()); if (!tiles.isEmpty()) { for (Map.Entry entry : tiles.entrySet()) { final BlockPosition pos = entry.getKey(); @@ -232,8 +262,8 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks { int ordinal = set.getBlock(lx, ly, lz).getOrdinal(); if (ordinal != 0) { TileEntity tile = entry.getValue(); - tile.hasWorld(); - tile.invalidateBlockCache(); + nmsChunk.removeTileEntity(tile.getPosition()); + nmsChunk.markDirty(); } } } From 8a19c4c38c04f22e5e59dbac119704c60e160142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Tue, 21 Apr 2020 15:40:53 +0200 Subject: [PATCH 2/3] Don't mark the chunk as dirty. --- .../fawe/bukkit/adapter/mc1_15_2/BukkitGetBlocks_1_15_2.java | 1 - 1 file changed, 1 deletion(-) 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 13f2bc1d4..965c73d54 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 @@ -263,7 +263,6 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks { if (ordinal != 0) { TileEntity tile = entry.getValue(); nmsChunk.removeTileEntity(tile.getPosition()); - nmsChunk.markDirty(); } } } From c478dbd249ba7bd91e9029e2c957e3514f5d731e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Tue, 21 Apr 2020 23:58:14 +0200 Subject: [PATCH 3/3] Backport changes --- .../fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java | 6 +++--- .../fawe/bukkit/adapter/mc1_15/BukkitGetBlocks_1_15.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java index 3fd910454..4e585f2ae 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java @@ -33,6 +33,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.HashMap; import java.util.Set; import java.util.UUID; import java.util.concurrent.Callable; @@ -230,7 +231,7 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks { // Remove existing tiles { - Map tiles = nmsChunk.getTileEntities(); + Map tiles = new HashMap<>(nmsChunk.getTileEntities()); if (!tiles.isEmpty()) { for (Map.Entry entry : tiles.entrySet()) { final BlockPosition pos = entry.getKey(); @@ -243,8 +244,7 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks { } if (set.getBlock(lx, ly, lz).getOrdinal() != 0) { TileEntity tile = entry.getValue(); - tile.n(); - tile.invalidateBlockCache(); + nmsChunk.removeTileEntity(tile.getPosition()); } } } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitGetBlocks_1_15.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitGetBlocks_1_15.java index f3ef44996..4a399655d 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitGetBlocks_1_15.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitGetBlocks_1_15.java @@ -33,6 +33,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.HashMap; import java.util.Set; import java.util.UUID; import java.util.concurrent.Callable; @@ -238,7 +239,7 @@ public class BukkitGetBlocks_1_15 extends CharGetBlocks { // Remove existing tiles { - Map tiles = nmsChunk.getTileEntities(); + Map tiles = new HashMap<>(nmsChunk.getTileEntities()); if (!tiles.isEmpty()) { for (Map.Entry entry : tiles.entrySet()) { final BlockPosition pos = entry.getKey(); @@ -251,8 +252,7 @@ public class BukkitGetBlocks_1_15 extends CharGetBlocks { } if (set.getBlock(lx, ly, lz).getOrdinal() != 0) { TileEntity tile = entry.getValue(); - tile.hasWorld(); - tile.invalidateBlockCache(); + nmsChunk.removeTileEntity(tile.getPosition()); } } }