9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-24 17:39:30 +00:00

使用线程安全的方法

This commit is contained in:
XiaoMoMi
2025-05-07 02:02:26 +08:00
parent daf2ac3e8a
commit 7c0d056637
2 changed files with 14 additions and 13 deletions

View File

@@ -76,18 +76,17 @@ public class FastAsyncWorldEditDelegate extends AbstractDelegateExtent {
});
}
private static void injectLevelChunk(CEChunk ceChunk) {
private static void injectLevelChunk(Object chunkSource, CEChunk ceChunk) {
ChunkPos pos = ceChunk.chunkPos();
CESection[] ceSections = ceChunk.sections();
Object worldServer = ceChunk.world().world().serverWorld();
Object chunkSource = FastNMS.INSTANCE.method$ServerLevel$getChunkSource(worldServer);
// TODO THREAD SAFETY?
Object levelChunk = FastNMS.INSTANCE.method$ServerChunkCache$getChunkAtIfLoadedMainThread(chunkSource, pos.x, pos.z);
Object[] sections = FastNMS.INSTANCE.method$ChunkAccess$getSections(levelChunk);
for (int i = 0; i < ceSections.length; i++) {
CESection ceSection = ceSections[i];
Object section = sections[i];
BukkitInjector.injectLevelChunkSection(section, ceSection, ceChunk, new SectionPos(pos.x, ceChunk.sectionY(i), pos.z));
Object levelChunk = FastNMS.INSTANCE.method$ServerChunkCache$getChunk(chunkSource, pos.x, pos.z, false);
if (levelChunk != null) {
Object[] sections = FastNMS.INSTANCE.method$ChunkAccess$getSections(levelChunk);
CESection[] ceSections = ceChunk.sections();
for (int i = 0; i < ceSections.length; i++) {
CESection ceSection = ceSections[i];
Object section = sections[i];
BukkitInjector.injectLevelChunkSection(section, ceSection, ceChunk, new SectionPos(pos.x, ceChunk.sectionY(i), pos.z));
}
}
}
@@ -146,11 +145,13 @@ public class FastAsyncWorldEditDelegate extends AbstractDelegateExtent {
saveAllChunks();
List<ChunkPos> chunks = new ArrayList<>(BROKEN_CHUNKS);
BROKEN_CHUNKS.clear();
Object worldServer = this.ceWorld.world().serverWorld();
Object chunkSource = FastNMS.INSTANCE.method$ServerLevel$getChunkSource(worldServer);
for (ChunkPos chunk : chunks) {
CEChunk loaded = this.ceWorld.getChunkAtIfLoaded(chunk.longKey());
// only inject loaded chunks
if (loaded == null) continue;
injectLevelChunk(loaded);
injectLevelChunk(chunkSource, loaded);
}
return super.commitBefore();
}

View File

@@ -50,7 +50,7 @@ byte_buddy_version=1.17.5
ahocorasick_version=0.6.3
snake_yaml_version=2.4
anti_grief_version=0.15
nms_helper_version=0.64.5
nms_helper_version=0.64.6
evalex_version=3.5.0
reactive_streams_version=1.0.4
amazon_awssdk_version=2.31.23