9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-26 18:39:20 +00:00

优化世界读取

This commit is contained in:
XiaoMoMi
2025-09-07 03:41:45 +08:00
parent c68c87eff9
commit f8618d18cb
4 changed files with 37 additions and 17 deletions

View File

@@ -39,6 +39,8 @@ public class BukkitWorldManager implements WorldManager, Listener {
private CEWorld[] worldArray;
private StorageAdaptor storageAdaptor;
private boolean initialized = false;
private UUID lastWorldUUID = null;
private CEWorld lastWorld = null;
public BukkitWorldManager(BukkitCraftEngine plugin) {
instance = this;
@@ -65,7 +67,15 @@ public class BukkitWorldManager implements WorldManager, Listener {
@Override
public CEWorld getWorld(UUID uuid) {
return this.worlds.get(uuid);
if (uuid == this.lastWorldUUID || uuid.equals(this.lastWorldUUID)) {
return this.lastWorld;
}
CEWorld world = this.worlds.get(uuid);
if (world != null) {
this.lastWorldUUID = uuid;
this.lastWorld = world;
}
return world;
}
@Override
@@ -114,6 +124,8 @@ public class BukkitWorldManager implements WorldManager, Listener {
}
}
this.worlds.clear();
this.lastWorld = null;
this.lastWorldUUID = null;
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
@@ -123,9 +135,10 @@ public class BukkitWorldManager implements WorldManager, Listener {
@Override
public void loadWorld(net.momirealms.craftengine.core.world.World world) {
if (this.worlds.containsKey(world.uuid())) return;
UUID uuid = world.uuid();
if (this.worlds.containsKey(uuid)) return;
CEWorld ceWorld = new BukkitCEWorld(world, this.storageAdaptor);
this.worlds.put(world.uuid(), ceWorld);
this.worlds.put(uuid, ceWorld);
this.resetWorldArray();
for (Chunk chunk : ((World) world.platformWorld()).getLoadedChunks()) {
handleChunkLoad(ceWorld, chunk);
@@ -135,8 +148,9 @@ public class BukkitWorldManager implements WorldManager, Listener {
@Override
public void loadWorld(CEWorld world) {
if (this.worlds.containsKey(world.world().uuid())) return;
this.worlds.put(world.world().uuid(), world);
UUID uuid = world.world().uuid();
if (this.worlds.containsKey(uuid)) return;
this.worlds.put(uuid, world);
this.resetWorldArray();
for (Chunk chunk : ((World) world.world().platformWorld()).getLoadedChunks()) {
handleChunkLoad(world, chunk);
@@ -163,8 +177,8 @@ public class BukkitWorldManager implements WorldManager, Listener {
@Override
public void unloadWorld(net.momirealms.craftengine.core.world.World world) {
CEWorld ceWorld;
ceWorld = this.worlds.remove(world.uuid());
UUID uuid = world.uuid();
CEWorld ceWorld = this.worlds.remove(uuid);
if (ceWorld == null) {
return;
}
@@ -173,6 +187,10 @@ public class BukkitWorldManager implements WorldManager, Listener {
for (Chunk chunk : ((World) world.platformWorld()).getLoadedChunks()) {
handleChunkUnload(ceWorld, chunk);
}
if (uuid.equals(this.lastWorldUUID)) {
this.lastWorld = null;
this.lastWorldUUID = null;
}
try {
ceWorld.worldDataStorage().close();
} catch (IOException e) {

View File

@@ -66,9 +66,9 @@ resource-pack:
remove-tinted-leaves-particle: true
merge-external-folders:
- ModelEngine/resource pack
- BetterModel/build
merge-external-zip-files:
- CustomNameplates/resourcepack.zip
- "BetterModel/build.zip"
exclude-file-extensions: ["md", "psd", "bbmodel", "db", "ini"]
# Exclude the shaders when generating the resource pack
exclude-core-shaders: false

View File

@@ -78,7 +78,7 @@ public abstract class CEWorld {
for (ConcurrentLong2ReferenceChainedHashTable.TableEntry<CEChunk> entry : this.loadedChunkMap.entrySet()) {
CEChunk chunk = entry.getValue();
if (chunk.dirty()) {
worldDataStorage.writeChunkAt(new ChunkPos(entry.getKey()), chunk);
this.worldDataStorage.writeChunkAt(new ChunkPos(entry.getKey()), chunk);
chunk.setDirty(false);
}
}
@@ -205,15 +205,17 @@ public abstract class CEWorld {
this.tickingBlockEntities.addAll(this.pendingTickingBlockEntities);
this.pendingTickingBlockEntities.clear();
}
ReferenceOpenHashSet<TickingBlockEntity> toRemove = new ReferenceOpenHashSet<>();
for (TickingBlockEntity blockEntity : this.tickingBlockEntities) {
if (blockEntity.isValid()) {
blockEntity.tick();
} else {
toRemove.add(blockEntity);
if (!this.tickingBlockEntities.isEmpty()) {
ReferenceOpenHashSet<TickingBlockEntity> toRemove = new ReferenceOpenHashSet<>();
for (TickingBlockEntity blockEntity : this.tickingBlockEntities) {
if (blockEntity.isValid()) {
blockEntity.tick();
} else {
toRemove.add(blockEntity);
}
}
this.tickingBlockEntities.removeAll(toRemove);
}
this.tickingBlockEntities.removeAll(toRemove);
this.isTickingBlockEntities = false;
}

View File

@@ -32,7 +32,7 @@ public final class DefaultChunkSerializer {
}
ListTag blockEntityRenders = DefaultBlockEntityRendererSerializer.serialize(chunk.blockEntityRenderers());
if (!blockEntityRenders.isEmpty()) {
chunkNbt.put("block_entity_renders", blockEntityRenders);
chunkNbt.put("block_entity_renderers", blockEntityRenders);
}
return chunkNbt;
}