155 lines
6.4 KiB
Diff
155 lines
6.4 KiB
Diff
--- a/net/minecraft/server/level/ChunkProviderServer.java
|
|
+++ b/net/minecraft/server/level/ChunkProviderServer.java
|
|
@@ -100,6 +100,16 @@
|
|
this.clearCache();
|
|
}
|
|
|
|
+ // CraftBukkit start - properly implement isChunkLoaded
|
|
+ public boolean isChunkLoaded(int chunkX, int chunkZ) {
|
|
+ PlayerChunk chunk = this.chunkMap.getUpdatingChunkIfPresent(ChunkCoordIntPair.asLong(chunkX, chunkZ));
|
|
+ if (chunk == null) {
|
|
+ return false;
|
|
+ }
|
|
+ return chunk.getFullChunkNow() != null;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
@Override
|
|
public LightEngineThreaded getLightEngine() {
|
|
return this.lightEngine;
|
|
@@ -143,7 +153,7 @@
|
|
if (k == this.lastChunkPos[l] && chunkstatus == this.lastChunkStatus[l]) {
|
|
IChunkAccess ichunkaccess = this.lastChunk[l];
|
|
|
|
- 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;
|
|
}
|
|
}
|
|
@@ -156,7 +166,7 @@
|
|
Objects.requireNonNull(completablefuture);
|
|
chunkproviderserver_a.managedBlock(completablefuture::isDone);
|
|
ChunkResult<IChunkAccess> chunkresult = (ChunkResult) completablefuture.join();
|
|
- IChunkAccess ichunkaccess1 = chunkresult.orElse((Object) null);
|
|
+ IChunkAccess ichunkaccess1 = chunkresult.orElse(null); // CraftBukkit - decompile error
|
|
|
|
if (ichunkaccess1 == null && flag) {
|
|
throw (IllegalStateException) SystemUtils.pauseInIde(new IllegalStateException("Chunk not there when requested: " + chunkresult.getError()));
|
|
@@ -236,7 +246,15 @@
|
|
int l = ChunkLevel.byStatus(chunkstatus);
|
|
PlayerChunk playerchunk = this.getVisibleChunkIfPresent(k);
|
|
|
|
- if (flag) {
|
|
+ // CraftBukkit start - don't add new ticket for currently unloading chunk
|
|
+ boolean currentlyUnloading = false;
|
|
+ if (playerchunk != null) {
|
|
+ FullChunkStatus oldChunkState = ChunkLevel.fullStatus(playerchunk.oldTicketLevel);
|
|
+ FullChunkStatus currentChunkState = ChunkLevel.fullStatus(playerchunk.getTicketLevel());
|
|
+ currentlyUnloading = (oldChunkState.isOrAfter(FullChunkStatus.FULL) && !currentChunkState.isOrAfter(FullChunkStatus.FULL));
|
|
+ }
|
|
+ if (flag && !currentlyUnloading) {
|
|
+ // CraftBukkit end
|
|
this.addTicket(new Ticket(TicketType.UNKNOWN, l), chunkcoordintpair);
|
|
if (this.chunkAbsent(playerchunk, l)) {
|
|
GameProfilerFiller gameprofilerfiller = Profiler.get();
|
|
@@ -255,7 +273,7 @@
|
|
}
|
|
|
|
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
|
|
@@ -314,12 +332,34 @@
|
|
|
|
@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.dataStorage.close();
|
|
this.lightEngine.close();
|
|
this.chunkMap.close();
|
|
}
|
|
|
|
+ // CraftBukkit start - modelled on below
|
|
+ public void purgeUnload() {
|
|
+ GameProfilerFiller gameprofilerfiller = Profiler.get();
|
|
+
|
|
+ gameprofilerfiller.push("purge");
|
|
+ this.ticketStorage.purgeStaleTickets();
|
|
+ this.runDistanceManagerUpdates();
|
|
+ gameprofilerfiller.popPush("unload");
|
|
+ this.chunkMap.tick(() -> true);
|
|
+ gameprofilerfiller.pop();
|
|
+ this.clearCache();
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
@Override
|
|
public void tick(BooleanSupplier booleansupplier, boolean flag) {
|
|
GameProfilerFiller gameprofilerfiller = Profiler.get();
|
|
@@ -384,14 +424,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<EnumCreatureType> list;
|
|
|
|
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
|
|
|
|
- list = SpawnerCreature.getFilteredSpawningCategories(spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag1);
|
|
+ list = SpawnerCreature.getFilteredSpawningCategories(spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag1, this.level); // CraftBukkit
|
|
} else {
|
|
list = List.of();
|
|
}
|
|
@@ -554,8 +594,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
|
|
}
|
|
|
|
public String getChunkDebugData(ChunkCoordIntPair chunkcoordintpair) {
|
|
@@ -631,13 +677,19 @@
|
|
}
|
|
|
|
@Override
|
|
- protected boolean pollTask() {
|
|
+ // CraftBukkit start - process pending Chunk loadCallback() and unloadCallback() after each run task
|
|
+ public boolean pollTask() {
|
|
+ try {
|
|
if (ChunkProviderServer.this.runDistanceManagerUpdates()) {
|
|
return true;
|
|
} else {
|
|
ChunkProviderServer.this.lightEngine.tryScheduleUpdate();
|
|
return super.pollTask();
|
|
}
|
|
+ } finally {
|
|
+ chunkMap.callbackExecutor.run();
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|
|
}
|
|
}
|