3
0
KCauldronX/patches/net/minecraftforge/common/chunkio/ChunkIOProvider.java.patch
Sergey Shatunov 5aaf6c5cbf ChunkManager implementation
ChunkManager optimize chunks handling in small and big worlds

Small worlds gets benefits with using int-object map instead long-object (in area -32768...32767 by x and z)

Large worlds gets benefits by using efficient map by Colt project, which a little (3-6%) slower in writing, but greatly faster
(400-500% from Java's HashMap and 150-180% from Trove's maps) on reading.
2016-02-10 19:17:47 +07:00

51 lines
2.5 KiB
Diff

--- ../src-base/minecraft/net/minecraftforge/common/chunkio/ChunkIOProvider.java
+++ ../src-work/minecraft/net/minecraftforge/common/chunkio/ChunkIOProvider.java
@@ -9,6 +9,9 @@
import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;
+import org.bukkit.Server;
+import org.bukkit.craftbukkit.util.LongHash;
+
class ChunkIOProvider implements AsynchronousExecutor.CallBackProvider<QueuedChunk, net.minecraft.world.chunk.Chunk, Runnable, RuntimeException> {
private final AtomicInteger threadNumber = new AtomicInteger(1);
@@ -41,14 +44,36 @@
queuedChunk.loader.loadEntities(queuedChunk.world, queuedChunk.compound.getCompoundTag("Level"), chunk);
MinecraftForge.EVENT_BUS.post(new ChunkDataEvent.Load(chunk, queuedChunk.compound)); // Don't call ChunkDataEvent.Load async
chunk.lastSaveTime = queuedChunk.provider.worldObj.getTotalWorldTime();
- queuedChunk.provider.loadedChunkHashMap.add(ChunkCoordIntPair.chunkXZ2Int(queuedChunk.x, queuedChunk.z), chunk);
+ queuedChunk.provider.chunkManager.putChunk(chunk, queuedChunk.x, queuedChunk.z); // KCauldron
queuedChunk.provider.loadedChunks.add(chunk);
chunk.onChunkLoad();
if (queuedChunk.provider.currentChunkProvider != null) {
+ queuedChunk.provider.worldObj.timings.syncChunkLoadStructuresTimer.startTiming(); // Spigot
queuedChunk.provider.currentChunkProvider.recreateStructures(queuedChunk.x, queuedChunk.z);
+ queuedChunk.provider.worldObj.timings.syncChunkLoadStructuresTimer.stopTiming(); // Spigot
}
+
+ Server server = queuedChunk.provider.worldObj.getServer();
+ if (server != null) {
+ server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkLoadEvent(chunk.bukkitChunk, false));
+ }
+ // Update neighbor counts
+ for (int x = -2; x < 3; x++) {
+ for (int z = -2; z < 3; z++) {
+ if (x == 0 && z == 0) {
+ continue;
+ }
+
+ net.minecraft.world.chunk.Chunk neighbor = queuedChunk.provider.getChunkIfLoaded(chunk.xPosition + x, chunk.zPosition + z);
+ if (neighbor != null) {
+ neighbor.setNeighborLoaded(-x, -z);
+ chunk.setNeighborLoaded(x, z);
+ }
+ }
+ }
+
chunk.populateChunk(queuedChunk.provider, queuedChunk.provider, queuedChunk.x, queuedChunk.z);
}