From 9ac3bccbdee00a7ed64a4516ba845b059d810e09 Mon Sep 17 00:00:00 2001
From: Phillipp Glanz
Date: Mon, 3 Apr 2023 15:10:57 +0200
Subject: [PATCH] Improve scheduling for chunk data of regen
---
.../fawe/v1_19_R3/PaperweightGetBlocks.java | 39 ++++++++-----------
1 file changed, 16 insertions(+), 23 deletions(-)
diff --git a/worldedit-bukkit/folia-adapters/adapter-1_19_4/src/main/java/com/sk89q/worldedit/folia/adapter/impl/fawe/v1_19_R3/PaperweightGetBlocks.java b/worldedit-bukkit/folia-adapters/adapter-1_19_4/src/main/java/com/sk89q/worldedit/folia/adapter/impl/fawe/v1_19_R3/PaperweightGetBlocks.java
index c898dfdae..300fa1093 100644
--- a/worldedit-bukkit/folia-adapters/adapter-1_19_4/src/main/java/com/sk89q/worldedit/folia/adapter/impl/fawe/v1_19_R3/PaperweightGetBlocks.java
+++ b/worldedit-bukkit/folia-adapters/adapter-1_19_4/src/main/java/com/sk89q/worldedit/folia/adapter/impl/fawe/v1_19_R3/PaperweightGetBlocks.java
@@ -61,6 +61,7 @@ import net.minecraft.world.level.chunk.PalettedContainerRO;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.lighting.LevelLightEngine;
import org.apache.logging.log4j.Logger;
+import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_19_R3.block.CraftBlock;
@@ -771,28 +772,18 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
final int y = blockHash.getY();
final int z = blockHash.getZ() + bz;
final BlockPos pos = new BlockPos(x, y, z);
-
- synchronized (nmsWorld) {
-
- BlockEntity tileEntity = TaskManager.taskManager().syncAt(
- () -> nmsWorld.getBlockEntity(pos),
- new Location(new BukkitWorld(getChunk().bukkitChunk.getWorld()), Vector3.at(x, y, z))
- );
- if (tileEntity == null || tileEntity.isRemoved()) {
- nmsWorld.removeBlockEntity(pos);
- tileEntity = TaskManager.taskManager().syncAt(
- () -> nmsWorld.getBlockEntity(pos),
- new Location(new BukkitWorld(getChunk().bukkitChunk.getWorld()), Vector3.at(x, y, z))
- );
- }
- if (tileEntity != null) {
- final net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNative(
- nativeTag);
- tag.put("x", IntTag.valueOf(x));
- tag.put("y", IntTag.valueOf(y));
- tag.put("z", IntTag.valueOf(z));
- tileEntity.load(tag);
- }
+ BlockEntity tileEntity = nmsWorld.getBlockEntity(pos);
+ if (tileEntity == null || tileEntity.isRemoved()) {
+ nmsWorld.removeBlockEntity(pos);
+ tileEntity = nmsWorld.getBlockEntity(pos);
+ }
+ if (tileEntity != null) {
+ final net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNative(
+ nativeTag);
+ tag.put("x", IntTag.valueOf(x));
+ tag.put("y", IntTag.valueOf(y));
+ tag.put("z", IntTag.valueOf(z));
+ tileEntity.load(tag);
}
}
};
@@ -828,7 +819,9 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
// Run the sync tasks
for (Runnable task : finalSyncTasks) {
if (task != null) {
- task.run();
+ Bukkit.getRegionScheduler().execute(WorldEditPlugin.getInstance(), nmsWorld.getWorld(), bx,
+ bz, task::run
+ );
}
}
if (callback == null) {