2021-03-15 23:00:00 +01:00
--- a/net/minecraft/server/level/ChunkProviderServer.java
+++ b/net/minecraft/server/level/ChunkProviderServer.java
2024-10-22 17:15:00 +02:00
@@ -96,6 +96,16 @@
2020-06-06 11:23:46 +02:00
this.clearCache();
}
+ // CraftBukkit start - properly implement isChunkLoaded
+ public boolean isChunkLoaded(int chunkX, int chunkZ) {
2021-11-21 23:00:00 +01:00
+ PlayerChunk chunk = this.chunkMap.getUpdatingChunkIfPresent(ChunkCoordIntPair.asLong(chunkX, chunkZ));
2020-06-06 11:23:46 +02:00
+ if (chunk == null) {
+ return false;
+ }
2022-03-27 07:24:06 +02:00
+ return chunk.getFullChunkNow() != null;
2020-06-06 11:23:46 +02:00
+ }
+ // CraftBukkit end
+
@Override
public LightEngineThreaded getLightEngine() {
return this.lightEngine;
2024-10-22 17:15:00 +02:00
@@ -139,7 +149,7 @@
2021-06-11 07:00:00 +02:00
if (k == this.lastChunkPos[l] && chunkstatus == this.lastChunkStatus[l]) {
2024-04-23 17:15:00 +02:00
IChunkAccess 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;
}
}
2024-10-22 17:15:00 +02:00
@@ -152,7 +162,7 @@
2024-04-23 17:15:00 +02:00
Objects.requireNonNull(completablefuture);
chunkproviderserver_b.managedBlock(completablefuture::isDone);
ChunkResult<IChunkAccess> chunkresult = (ChunkResult) completablefuture.join();
- IChunkAccess ichunkaccess1 = (IChunkAccess) chunkresult.orElse((Object) null);
+ IChunkAccess ichunkaccess1 = (IChunkAccess) chunkresult.orElse(null); // CraftBukkit - decompile error
if (ichunkaccess1 == null && flag) {
throw (IllegalStateException) SystemUtils.pauseInIde(new IllegalStateException("Chunk not there when requested: " + chunkresult.getError()));
2024-10-22 17:15:00 +02:00
@@ -232,7 +242,15 @@
2023-06-07 17:30:00 +02:00
int l = ChunkLevel.byStatus(chunkstatus);
2021-11-21 23:00:00 +01:00
PlayerChunk playerchunk = this.getVisibleChunkIfPresent(k);
2019-05-16 01:11:20 +02:00
- if (flag) {
+ // CraftBukkit start - don't add new ticket for currently unloading chunk
+ boolean currentlyUnloading = false;
+ if (playerchunk != null) {
2023-06-07 17:30:00 +02:00
+ FullChunkStatus oldChunkState = ChunkLevel.fullStatus(playerchunk.oldTicketLevel);
+ FullChunkStatus currentChunkState = ChunkLevel.fullStatus(playerchunk.getTicketLevel());
+ currentlyUnloading = (oldChunkState.isOrAfter(FullChunkStatus.FULL) && !currentChunkState.isOrAfter(FullChunkStatus.FULL));
2019-05-16 01:11:20 +02:00
+ }
+ if (flag && !currentlyUnloading) {
+ // CraftBukkit end
2021-11-21 23:00:00 +01:00
this.distanceManager.addTicket(TicketType.UNKNOWN, chunkcoordintpair, l, chunkcoordintpair);
if (this.chunkAbsent(playerchunk, l)) {
2024-10-22 17:15:00 +02:00
GameProfilerFiller gameprofilerfiller = Profiler.get();
@@ -251,7 +269,7 @@
2024-06-15 08:47:43 +02:00
}
private boolean chunkAbsent(@Nullable PlayerChunk playerchunk, int i) {
- return playerchunk == null || playerchunk.getTicketLevel() > i;
+ return playerchunk == null || playerchunk.oldTicketLevel > i; // CraftBukkit using oldTicketLevel for isLoaded checks
}
@Override
2024-10-22 17:15:00 +02:00
@@ -310,12 +328,34 @@
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
2024-10-22 17:15:00 +02:00
this.dataStorage.close();
2019-07-29 08:36:51 +02:00
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() {
2024-10-22 17:15:00 +02:00
+ GameProfilerFiller gameprofilerfiller = Profiler.get();
+
+ gameprofilerfiller.push("purge");
2021-11-21 23:00:00 +01:00
+ this.distanceManager.purgeStaleTickets();
+ this.runDistanceManagerUpdates();
2024-10-22 17:15:00 +02:00
+ gameprofilerfiller.popPush("unload");
2021-11-21 23:00:00 +01:00
+ this.chunkMap.tick(() -> true);
2024-10-22 17:15:00 +02:00
+ gameprofilerfiller.pop();
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
2022-02-28 16:00:00 +01:00
public void tick(BooleanSupplier booleansupplier, boolean flag) {
2024-10-22 17:15:00 +02:00
GameProfilerFiller gameprofilerfiller = Profiler.get();
@@ -402,14 +442,14 @@
this.lastSpawnState = spawnercreature_d;
gameprofilerfiller.popPush("spawnAndTick");
- boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING);
+ boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !this.level.players().isEmpty(); // CraftBukkit
int k = this.level.getGameRules().getInt(GameRules.RULE_RANDOMTICKING);
List list1;
2021-11-21 23:00:00 +01:00
2024-10-22 17:15:00 +02:00
if (flag && (this.spawnEnemies || this.spawnFriendlies)) {
- boolean flag1 = this.level.getLevelData().getGameTime() % 400L == 0L;
+ boolean flag1 = this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) != 0L && this.level.getLevelData().getGameTime() % this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) == 0L; // CraftBukkit
2019-05-14 02:00:00 +02:00
2024-10-22 17:15:00 +02:00
- list1 = SpawnerCreature.getFilteredSpawningCategories(spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag1);
+ list1 = SpawnerCreature.getFilteredSpawningCategories(spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag1, this.level); // CraftBukkit
} else {
list1 = List.of();
}
@@ -542,8 +582,14 @@
@Override
public void setSpawnSettings(boolean flag) {
+ // CraftBukkit start
+ this.setSpawnSettings(flag, this.spawnFriendlies);
+ }
+
+ public void setSpawnSettings(boolean flag, boolean spawnFriendlies) {
this.spawnEnemies = flag;
- this.spawnFriendlies = this.spawnFriendlies;
+ this.spawnFriendlies = spawnFriendlies;
+ // CraftBukkit end
}
2021-07-06 16:00:00 +02:00
2024-10-22 17:15:00 +02:00
public String getChunkDebugData(ChunkCoordIntPair chunkcoordintpair) {
@@ -619,13 +665,19 @@
2021-06-11 07:00:00 +02:00
}
2019-07-13 20:19:44 +02:00
@Override
2021-11-21 23:00:00 +01:00
- protected boolean pollTask() {
2019-07-13 20:19:44 +02:00
+ // CraftBukkit start - process pending Chunk loadCallback() and unloadCallback() after each run task
2021-11-21 23:00:00 +01:00
+ public boolean pollTask() {
2019-07-13 20:19:44 +02:00
+ try {
2021-11-21 23:00:00 +01:00
if (ChunkProviderServer.this.runDistanceManagerUpdates()) {
2019-07-13 20:19:44 +02:00
return true;
} else {
2021-11-21 23:00:00 +01:00
ChunkProviderServer.this.lightEngine.tryScheduleUpdate();
return super.pollTask();
2019-07-13 20:19:44 +02:00
}
+ } finally {
2021-06-11 07:00:00 +02:00
+ chunkMap.callbackExecutor.run();
2019-07-13 20:19:44 +02:00
+ }
+ // CraftBukkit end
}
}
2021-11-21 23:00:00 +01:00