diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/world/BukkitWorldManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/world/BukkitWorldManager.java index 18050cd49..2a90f6333 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/world/BukkitWorldManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/world/BukkitWorldManager.java @@ -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) { diff --git a/common-files/src/main/resources/config.yml b/common-files/src/main/resources/config.yml index 5c39b74bf..5ef03acb9 100644 --- a/common-files/src/main/resources/config.yml +++ b/common-files/src/main/resources/config.yml @@ -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 diff --git a/core/src/main/java/net/momirealms/craftengine/core/world/CEWorld.java b/core/src/main/java/net/momirealms/craftengine/core/world/CEWorld.java index 32abf2075..fafbb6da3 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/world/CEWorld.java +++ b/core/src/main/java/net/momirealms/craftengine/core/world/CEWorld.java @@ -78,7 +78,7 @@ public abstract class CEWorld { for (ConcurrentLong2ReferenceChainedHashTable.TableEntry 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 toRemove = new ReferenceOpenHashSet<>(); - for (TickingBlockEntity blockEntity : this.tickingBlockEntities) { - if (blockEntity.isValid()) { - blockEntity.tick(); - } else { - toRemove.add(blockEntity); + if (!this.tickingBlockEntities.isEmpty()) { + ReferenceOpenHashSet 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; } diff --git a/core/src/main/java/net/momirealms/craftengine/core/world/chunk/serialization/DefaultChunkSerializer.java b/core/src/main/java/net/momirealms/craftengine/core/world/chunk/serialization/DefaultChunkSerializer.java index 4ef8a7955..ff195c4d3 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/world/chunk/serialization/DefaultChunkSerializer.java +++ b/core/src/main/java/net/momirealms/craftengine/core/world/chunk/serialization/DefaultChunkSerializer.java @@ -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; }