2021-03-15 23:00:00 +01:00
--- a/net/minecraft/server/level/ChunkProviderServer.java
+++ b/net/minecraft/server/level/ChunkProviderServer.java
2021-06-11 07:00:00 +02:00
@@ -83,6 +83,24 @@
2020-06-06 11:23:46 +02:00
this.clearCache();
}
+ // CraftBukkit start - properly implement isChunkLoaded
+ public boolean isChunkLoaded(int chunkX, int chunkZ) {
2021-06-11 07:00:00 +02:00
+ PlayerChunk chunk = this.chunkMap.getUpdatingChunk(ChunkCoordIntPair.pair(chunkX, chunkZ));
2020-06-06 11:23:46 +02:00
+ if (chunk == null) {
+ return false;
+ }
+ return chunk.getFullChunk() != null;
+ }
2021-02-13 23:24:23 +01:00
+
+ public Chunk getChunkUnchecked(int chunkX, int chunkZ) {
2021-06-11 07:00:00 +02:00
+ PlayerChunk chunk = this.chunkMap.getUpdatingChunk(ChunkCoordIntPair.pair(chunkX, chunkZ));
2021-02-13 23:24:23 +01:00
+ if (chunk == null) {
+ return null;
+ }
+ return chunk.getFullChunkUnchecked();
+ }
2020-06-06 11:23:46 +02:00
+ // CraftBukkit end
+
@Override
public LightEngineThreaded getLightEngine() {
return this.lightEngine;
2021-06-11 07:00:00 +02:00
@@ -127,7 +145,7 @@
2019-05-16 01:11:20 +02:00
for (int l = 0; l < 4; ++l) {
2021-06-11 07:00:00 +02:00
if (k == this.lastChunkPos[l] && chunkstatus == this.lastChunkStatus[l]) {
ichunkaccess = this.lastChunk[l];
2019-05-16 01:11:20 +02:00
- if (ichunkaccess != null || !flag) {
+ if (ichunkaccess != null) { // CraftBukkit - the chunk can become accessible in the meantime TODO for non-null chunks it might also make sense to check that the chunk's state hasn't changed in the meantime
return ichunkaccess;
}
}
2021-06-11 07:00:00 +02:00
@@ -175,12 +193,12 @@
2019-07-20 01:00:00 +02:00
if (playerchunk == null) {
return null;
} else {
- Either<IChunkAccess, PlayerChunk.Failure> either = (Either) playerchunk.b(ChunkStatus.FULL).getNow((Object) null);
2020-02-02 01:18:17 +01:00
+ Either<IChunkAccess, PlayerChunk.Failure> either = (Either) playerchunk.b(ChunkStatus.FULL).getNow(null); // CraftBukkit - decompile error
2019-07-20 01:00:00 +02:00
if (either == null) {
return null;
} else {
- IChunkAccess ichunkaccess1 = (IChunkAccess) either.left().orElse((Object) null);
2020-02-02 01:18:17 +01:00
+ IChunkAccess ichunkaccess1 = (IChunkAccess) either.left().orElse(null); // CraftBukkit - decompile error
2019-07-20 01:00:00 +02:00
if (ichunkaccess1 != null) {
this.a(k, ichunkaccess1, ChunkStatus.FULL);
2021-06-11 07:00:00 +02:00
@@ -228,7 +246,15 @@
2019-05-16 01:11:20 +02:00
int l = 33 + ChunkStatus.a(chunkstatus);
PlayerChunk playerchunk = this.getChunk(k);
- if (flag) {
+ // CraftBukkit start - don't add new ticket for currently unloading chunk
+ boolean currentlyUnloading = false;
+ if (playerchunk != null) {
2019-05-27 22:30:00 +02:00
+ PlayerChunk.State oldChunkState = PlayerChunk.getChunkState(playerchunk.oldTicketLevel);
+ PlayerChunk.State currentChunkState = PlayerChunk.getChunkState(playerchunk.getTicketLevel());
+ currentlyUnloading = (oldChunkState.isAtLeast(PlayerChunk.State.BORDER) && !currentChunkState.isAtLeast(PlayerChunk.State.BORDER));
2019-05-16 01:11:20 +02:00
+ }
+ if (flag && !currentlyUnloading) {
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
this.distanceManager.a(TicketType.UNKNOWN, chunkcoordintpair, l, chunkcoordintpair);
2019-05-16 01:11:20 +02:00
if (this.a(playerchunk, l)) {
2021-06-11 07:00:00 +02:00
GameProfilerFiller gameprofilerfiller = this.level.getMethodProfiler();
@@ -247,7 +273,7 @@
2019-05-16 01:11:20 +02:00
}
private boolean a(@Nullable PlayerChunk playerchunk, int i) {
- return playerchunk == null || playerchunk.getTicketLevel() > i;
+ return playerchunk == null || playerchunk.oldTicketLevel > i; // CraftBukkit using oldTicketLevel for isLoaded checks
}
2020-06-25 02:00:00 +02:00
@Override
2021-06-11 07:00:00 +02:00
@@ -307,7 +333,7 @@
2020-06-25 02:00:00 +02:00
}
2021-06-11 07:00:00 +02:00
public boolean a(long i) {
2020-06-25 02:00:00 +02:00
- return this.a(i, PlayerChunk::a);
+ return this.a(i, (Function<PlayerChunk, CompletableFuture<Either<Chunk, PlayerChunk.Failure>>>) PlayerChunk::a); // CraftBukkit - decompile error
}
private boolean a(long i, Function<PlayerChunk, CompletableFuture<Either<Chunk, PlayerChunk.Failure>>> function) {
2021-06-11 07:00:00 +02:00
@@ -329,11 +355,31 @@
2019-07-29 08:36:51 +02:00
@Override
public void close() throws IOException {
- this.save(true);
+ // CraftBukkit start
+ close(true);
+ }
+
+ public void close(boolean save) throws IOException {
+ if (save) {
+ this.save(true);
+ }
+ // CraftBukkit end
this.lightEngine.close();
2021-06-11 07:00:00 +02:00
this.chunkMap.close();
2018-07-15 02:00:00 +02:00
}
2014-11-25 22:32:16 +01:00
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start - modelled on below
+ public void purgeUnload() {
2021-06-11 07:00:00 +02:00
+ this.level.getMethodProfiler().enter("purge");
+ this.distanceManager.purgeTickets();
2019-04-23 04:00:00 +02:00
+ this.tickDistanceManager();
2021-06-11 07:00:00 +02:00
+ this.level.getMethodProfiler().exitEnter("unload");
+ this.chunkMap.unloadChunks(() -> true);
+ this.level.getMethodProfiler().exit();
2019-05-27 22:30:00 +02:00
+ this.clearCache();
2018-08-26 04:00:00 +02:00
+ }
+ // CraftBukkit end
+
2021-06-11 07:00:00 +02:00
@Override
2019-04-23 04:00:00 +02:00
public void tick(BooleanSupplier booleansupplier) {
2021-06-11 07:00:00 +02:00
this.level.getMethodProfiler().enter("purge");
@@ -354,12 +400,12 @@
this.lastInhabitedUpdate = i;
WorldData worlddata = this.level.getWorldData();
boolean flag = this.level.isDebugWorld();
- boolean flag1 = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING);
+ boolean flag1 = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !level.getPlayers().isEmpty(); // CraftBukkit
2014-11-25 22:32:16 +01:00
2019-04-23 04:00:00 +02:00
if (!flag) {
2021-06-11 07:00:00 +02:00
this.level.getMethodProfiler().enter("pollingChunks");
int k = this.level.getGameRules().getInt(GameRules.RULE_RANDOMTICKING);
2019-04-23 04:00:00 +02:00
- boolean flag2 = worlddata.getTime() % 400L == 0L;
2021-06-11 07:00:00 +02:00
+ boolean flag2 = level.ticksPerAnimalSpawns != 0L && worlddata.getTime() % level.ticksPerAnimalSpawns == 0L; // CraftBukkit
2019-05-14 02:00:00 +02:00
2021-06-11 07:00:00 +02:00
this.level.getMethodProfiler().enter("naturalSpawnCount");
int l = this.distanceManager.b();
@@ -548,13 +594,19 @@
}
2019-07-13 20:19:44 +02:00
@Override
2021-06-11 07:00:00 +02:00
- protected boolean executeNext() {
2019-07-13 20:19:44 +02:00
+ // CraftBukkit start - process pending Chunk loadCallback() and unloadCallback() after each run task
2021-06-11 07:00:00 +02:00
+ public boolean executeNext() {
2019-07-13 20:19:44 +02:00
+ try {
if (ChunkProviderServer.this.tickDistanceManager()) {
return true;
} else {
ChunkProviderServer.this.lightEngine.queueUpdate();
return super.executeNext();
}
+ } finally {
2021-06-11 07:00:00 +02:00
+ chunkMap.callbackExecutor.run();
2019-07-13 20:19:44 +02:00
+ }
+ // CraftBukkit end
}
}
}