mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-09 19:49:35 +01:00
314b83ffae
By: Doc <nachito94@msn.com>
174 lines
7.1 KiB
Diff
174 lines
7.1 KiB
Diff
--- a/net/minecraft/server/level/ChunkProviderServer.java
|
|
+++ b/net/minecraft/server/level/ChunkProviderServer.java
|
|
@@ -86,6 +86,24 @@
|
|
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.getFullChunk() != null;
|
|
+ }
|
|
+
|
|
+ public Chunk getChunkUnchecked(int chunkX, int chunkZ) {
|
|
+ PlayerChunk chunk = this.chunkMap.getUpdatingChunkIfPresent(ChunkCoordIntPair.asLong(chunkX, chunkZ));
|
|
+ if (chunk == null) {
|
|
+ return null;
|
|
+ }
|
|
+ return chunk.getFullChunkUnchecked();
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
@Override
|
|
public LightEngineThreaded getLightEngine() {
|
|
return this.lightEngine;
|
|
@@ -130,7 +148,7 @@
|
|
for (int l = 0; l < 4; ++l) {
|
|
if (k == this.lastChunkPos[l] && chunkstatus == this.lastChunkStatus[l]) {
|
|
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;
|
|
}
|
|
}
|
|
@@ -178,12 +196,12 @@
|
|
if (playerchunk == null) {
|
|
return null;
|
|
} else {
|
|
- Either<IChunkAccess, PlayerChunk.Failure> either = (Either) playerchunk.getFutureIfPresent(ChunkStatus.FULL).getNow((Object) null);
|
|
+ Either<IChunkAccess, PlayerChunk.Failure> either = (Either) playerchunk.getFutureIfPresent(ChunkStatus.FULL).getNow(null); // CraftBukkit - decompile error
|
|
|
|
if (either == null) {
|
|
return null;
|
|
} else {
|
|
- IChunkAccess ichunkaccess1 = (IChunkAccess) either.left().orElse((Object) null);
|
|
+ IChunkAccess ichunkaccess1 = (IChunkAccess) either.left().orElse(null); // CraftBukkit - decompile error
|
|
|
|
if (ichunkaccess1 != null) {
|
|
this.storeInCache(k, ichunkaccess1, ChunkStatus.FULL);
|
|
@@ -231,7 +249,15 @@
|
|
int l = 33 + ChunkStatus.getDistance(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) {
|
|
+ PlayerChunk.State oldChunkState = PlayerChunk.getFullChunkStatus(playerchunk.oldTicketLevel);
|
|
+ PlayerChunk.State currentChunkState = PlayerChunk.getFullChunkStatus(playerchunk.getTicketLevel());
|
|
+ currentlyUnloading = (oldChunkState.isOrAfter(PlayerChunk.State.BORDER) && !currentChunkState.isOrAfter(PlayerChunk.State.BORDER));
|
|
+ }
|
|
+ if (flag && !currentlyUnloading) {
|
|
+ // CraftBukkit end
|
|
this.distanceManager.addTicket(TicketType.UNKNOWN, chunkcoordintpair, l, chunkcoordintpair);
|
|
if (this.chunkAbsent(playerchunk, l)) {
|
|
GameProfilerFiller gameprofilerfiller = this.level.getProfiler();
|
|
@@ -250,7 +276,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
|
|
@@ -317,7 +343,7 @@
|
|
} else if (!this.level.shouldTickBlocksAt(i)) {
|
|
return false;
|
|
} else {
|
|
- Either<Chunk, PlayerChunk.Failure> either = (Either) playerchunk.getTickingChunkFuture().getNow((Object) null);
|
|
+ Either<Chunk, PlayerChunk.Failure> either = (Either) playerchunk.getTickingChunkFuture().getNow(null); // CraftBukkit - decompile error
|
|
|
|
return either != null && either.left().isPresent();
|
|
}
|
|
@@ -330,11 +356,31 @@
|
|
|
|
@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();
|
|
this.chunkMap.close();
|
|
}
|
|
|
|
+ // CraftBukkit start - modelled on below
|
|
+ public void purgeUnload() {
|
|
+ this.level.getProfiler().push("purge");
|
|
+ this.distanceManager.purgeStaleTickets();
|
|
+ this.runDistanceManagerUpdates();
|
|
+ this.level.getProfiler().popPush("unload");
|
|
+ this.chunkMap.tick(() -> true);
|
|
+ this.level.getProfiler().pop();
|
|
+ this.clearCache();
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
@Override
|
|
public void tick(BooleanSupplier booleansupplier) {
|
|
this.level.getProfiler().push("purge");
|
|
@@ -363,7 +409,7 @@
|
|
|
|
gameprofilerfiller.push("pollingChunks");
|
|
int k = this.level.getGameRules().getInt(GameRules.RULE_RANDOMTICKING);
|
|
- boolean flag1 = worlddata.getGameTime() % 400L == 0L;
|
|
+ boolean flag1 = level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) != 0L && worlddata.getGameTime() % level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) == 0L; // CraftBukkit
|
|
|
|
gameprofilerfiller.push("naturalSpawnCount");
|
|
int l = this.distanceManager.getNaturalSpawnChunkCount();
|
|
@@ -384,7 +430,7 @@
|
|
}
|
|
|
|
gameprofilerfiller.popPush("spawnAndTick");
|
|
- boolean flag2 = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING);
|
|
+ boolean flag2 = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !level.players().isEmpty(); // CraftBukkit
|
|
|
|
Collections.shuffle(list);
|
|
Iterator iterator1 = list.iterator();
|
|
@@ -579,18 +625,26 @@
|
|
}
|
|
|
|
@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
|
|
}
|
|
}
|
|
|
|
- private static record a(Chunk a, PlayerChunk b) {
|
|
+ // CraftBukkit start - decompile error
|
|
+ private static record a(Chunk chunk, PlayerChunk holder) {
|
|
|
|
+ /*
|
|
final Chunk chunk;
|
|
final PlayerChunk holder;
|
|
|
|
@@ -606,5 +660,7 @@
|
|
public PlayerChunk holder() {
|
|
return this.holder;
|
|
}
|
|
+ */
|
|
+ // CraftBukkit end
|
|
}
|
|
}
|