13
0
geforkt von Mirrors/Paper
Paper/nms-patches/ChunkProviderServer.patch

142 Zeilen
5.1 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/ChunkProviderServer.java
+++ b/net/minecraft/server/ChunkProviderServer.java
2018-07-15 02:00:00 +02:00
@@ -20,6 +20,11 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
+import org.bukkit.craftbukkit.chunkio.ChunkIOExecutor;
+import org.bukkit.event.world.ChunkUnloadEvent;
+// CraftBukkit end
+
public class ChunkProviderServer implements IChunkProvider {
2016-02-29 22:32:46 +01:00
private static final Logger a = LogManager.getLogger();
2018-07-15 02:00:00 +02:00
@@ -35,7 +40,7 @@
this.world = worldserver;
this.chunkLoader = ichunkloader;
this.chunkGenerator = chunkgenerator;
- this.f = new ChunkTaskScheduler(2, worldserver, chunkgenerator, ichunkloader, iasynctaskhandler);
+ this.f = new ChunkTaskScheduler(0, worldserver, chunkgenerator, ichunkloader, iasynctaskhandler); // CraftBukkit - very buggy, broken in lots of __subtle__ ways. Same goes for async chunk loading. Also Bukkit API / plugins can't handle async events at all anyway.
this.g = new SchedulerBatch(this.f);
}
@@ -77,9 +82,10 @@
@Nullable
private Chunk loadChunkAt(int i, int j) {
try {
- Chunk chunk = this.chunkLoader.a(this.world, i, j, (chunk) -> {
- chunk.setLastSaved(this.world.getTime());
- this.chunks.put(ChunkCoordIntPair.a(i, j), chunk);
+ // CraftBukkit - decompile error
+ Chunk chunk = this.chunkLoader.a(this.world, i, j, (chunk1) -> {
+ chunk1.setLastSaved(this.world.getTime());
+ this.chunks.put(ChunkCoordIntPair.a(i, j), chunk1);
});
2016-02-29 22:32:46 +01:00
if (chunk != null) {
2018-07-15 02:00:00 +02:00
@@ -104,6 +110,12 @@
}
2016-02-29 22:32:46 +01:00
}
+ // CraftBukkit start
+ public Chunk getChunkIfLoaded(int x, int z) {
+ return chunks.get(ChunkCoordIntPair.a(x, z));
+ }
+ // CraftBukkit end
+
2016-02-29 22:32:46 +01:00
public Chunk getChunkAt(int i, int j) {
2018-07-15 02:00:00 +02:00
Chunk chunk = this.getOrLoadChunkAt(i, j);
2018-07-15 02:00:00 +02:00
@@ -125,7 +137,7 @@
synchronized (this.chunks) {
IChunkAccess ichunkaccess = (IChunkAccess) this.chunks.get(ChunkCoordIntPair.a(i, j));
2018-07-15 02:00:00 +02:00
- return ichunkaccess != null ? ichunkaccess : (IChunkAccess) this.f.c((Object) (new ChunkCoordIntPair(i, j)));
+ return ichunkaccess != null ? ichunkaccess : (IChunkAccess) this.f.c((new ChunkCoordIntPair(i, j))); // CraftBukkit - decompile error
}
2018-07-15 02:00:00 +02:00
}
2018-07-25 11:32:06 +02:00
@@ -147,10 +159,21 @@
return this.g.c();
}
+ // CraftBukkit start
2018-07-15 02:00:00 +02:00
public CompletableFuture<Chunk> generateChunk(int i, int j) {
2018-07-25 11:32:06 +02:00
+ return this.generateChunk(i, j, false);
+ }
+
+ public CompletableFuture<Chunk> generateChunk(int i, int j, boolean force) {
2018-07-15 02:00:00 +02:00
this.g.b();
2018-07-25 11:32:06 +02:00
- this.g.a(new ChunkCoordIntPair(i, j));
2018-07-15 02:00:00 +02:00
- CompletableFuture completablefuture = this.g.c();
2018-07-25 11:32:06 +02:00
+
+ ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(i, j);
+ if (force) {
+ this.f.forcePolluteCache(chunkcoordintpair);
+ }
+ this.g.a(chunkcoordintpair);
+ // CraftBukkit end
2018-07-15 02:00:00 +02:00
+ CompletableFuture<ProtoChunk> completablefuture = this.g.c(); // CraftBukkit - decompile error
2018-07-15 02:00:00 +02:00
return completablefuture.thenApply(this::a);
}
2018-07-25 11:32:06 +02:00
@@ -268,10 +291,12 @@
Chunk chunk = (Chunk) this.chunks.get(olong);
if (chunk != null && chunk.d) {
- chunk.removeEntities();
- this.saveChunk(chunk);
- this.saveChunkNOP(chunk);
- this.chunks.remove(olong);
+ // CraftBukkit start - move unload logic to own method
+ if (!unloadChunk(chunk, true)) {
+ continue;
+ }
+ // CraftBukkit end
+
++i;
}
}
2018-07-25 11:32:06 +02:00
@@ -284,6 +309,40 @@
return false;
}
+ // CraftBukkit start
+ public boolean unloadChunk(Chunk chunk, boolean save) {
+ ChunkUnloadEvent event = new ChunkUnloadEvent(chunk.bukkitChunk, save);
+ this.world.getServer().getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return false;
+ }
+ save = event.isSaveChunk();
+
+ // Update neighbor counts
+ for (int x = -2; x < 3; x++) {
+ for (int z = -2; z < 3; z++) {
+ if (x == 0 && z == 0) {
+ continue;
+ }
+
+ Chunk neighbor = this.getChunkIfLoaded(chunk.locX + x, chunk.locZ + z);
+ if (neighbor != null) {
+ neighbor.setNeighborUnloaded(-x, -z);
+ chunk.setNeighborUnloaded(x, z);
+ }
+ }
+ }
+ // Moved from unloadChunks above
+ chunk.removeEntities();
+ if (save) {
+ this.saveChunk(chunk);
+ this.saveChunkNOP(chunk);
+ }
+ this.chunks.remove(chunk.chunkKey);
+ return true;
+ }
+ // CraftBukkit end
+
public boolean e() {
return !this.world.savingDisabled;
}