2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/ChunkProviderServer.java
+++ b/net/minecraft/server/ChunkProviderServer.java
2020-01-21 22:00:00 +01:00
@@ -95,7 +95,7 @@
2019-05-16 01:11:20 +02:00
for (int l = 0; l < 4; ++l) {
2019-05-27 22:30:00 +02:00
if (k == this.cachePos[l] && chunkstatus == this.cacheStatus[l]) {
ichunkaccess = this.cacheChunk[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;
}
}
2020-01-21 22:00:00 +01:00
@@ -141,12 +141,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);
2020-01-21 22:00:00 +01:00
@@ -173,7 +173,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
this.chunkMapDistance.a(TicketType.UNKNOWN, chunkcoordintpair, l, chunkcoordintpair);
if (this.a(playerchunk, l)) {
GameProfilerFiller gameprofilerfiller = this.world.getMethodProfiler();
2020-01-21 22:00:00 +01:00
@@ -192,7 +200,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
}
public boolean isLoaded(int i, int j) {
2020-01-21 22:00:00 +01:00
@@ -294,11 +302,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();
2019-04-23 04:00:00 +02:00
this.playerChunkMap.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() {
+ this.world.getMethodProfiler().enter("purge");
+ this.chunkMapDistance.purgeTickets();
+ this.tickDistanceManager();
+ this.world.getMethodProfiler().exitEnter("unload");
+ this.playerChunkMap.unloadChunks(() -> true);
+ this.world.getMethodProfiler().exit();
2019-05-27 22:30:00 +02:00
+ this.clearCache();
2018-08-26 04:00:00 +02:00
+ }
+ // CraftBukkit end
+
2019-04-23 04:00:00 +02:00
public void tick(BooleanSupplier booleansupplier) {
this.world.getMethodProfiler().enter("purge");
this.chunkMapDistance.purgeTickets();
2020-01-21 22:00:00 +01:00
@@ -318,13 +346,13 @@
2019-04-23 04:00:00 +02:00
this.lastTickTime = i;
WorldData worlddata = this.world.getWorldData();
boolean flag = worlddata.getType() == WorldType.DEBUG_ALL_BLOCK_STATES;
2019-06-21 12:00:00 +02:00
- boolean flag1 = this.world.getGameRules().getBoolean(GameRules.DO_MOB_SPAWNING);
+ boolean flag1 = this.world.getGameRules().getBoolean(GameRules.DO_MOB_SPAWNING) && !world.getPlayers().isEmpty(); // CraftBukkit
2014-11-25 22:32:16 +01:00
2019-04-23 04:00:00 +02:00
if (!flag) {
this.world.getMethodProfiler().enter("pollingChunks");
2019-06-21 12:00:00 +02:00
int k = this.world.getGameRules().getInt(GameRules.RANDOM_TICK_SPEED);
2019-04-23 04:00:00 +02:00
BlockPosition blockposition = this.world.getSpawn();
- boolean flag2 = worlddata.getTime() % 400L == 0L;
+ boolean flag2 = world.ticksPerAnimalSpawns != 0L && worlddata.getTime() % world.ticksPerAnimalSpawns == 0L; // CraftBukkit // PAIL: TODO monster ticks
2019-05-14 02:00:00 +02:00
this.world.getMethodProfiler().enter("naturalSpawnCount");
int l = this.chunkMapDistance.b();
2020-01-21 22:00:00 +01:00
@@ -353,8 +381,30 @@
2019-04-23 04:00:00 +02:00
for (int j1 = 0; j1 < i1; ++j1) {
EnumCreatureType enumcreaturetype = aenumcreaturetype1[j1];
2016-05-11 07:34:16 +02:00
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start - Use per-world spawn limits
+ int limit = enumcreaturetype.b();
+ switch (enumcreaturetype) {
+ case MONSTER:
+ limit = world.getWorld().getMonsterSpawnLimit();
+ break;
+ case CREATURE:
+ limit = world.getWorld().getAnimalSpawnLimit();
+ break;
+ case WATER_CREATURE:
+ limit = world.getWorld().getWaterAnimalSpawnLimit();
+ break;
+ case AMBIENT:
+ limit = world.getWorld().getAmbientSpawnLimit();
+ break;
+ }
2014-11-25 22:32:16 +01:00
+
2019-04-23 04:00:00 +02:00
+ if (limit == 0) {
+ continue;
+ }
+ // CraftBukkit end
2016-06-22 01:08:09 +02:00
+
2019-04-23 04:00:00 +02:00
if (enumcreaturetype != EnumCreatureType.MISC && (!enumcreaturetype.c() || this.allowAnimals) && (enumcreaturetype.c() || this.allowMonsters) && (!enumcreaturetype.d() || flag2)) {
2019-05-14 02:00:00 +02:00
- int k1 = enumcreaturetype.b() * l / ChunkProviderServer.b;
+ int k1 = limit * l / ChunkProviderServer.b; // CraftBukkit - use per-world limits
2019-04-23 04:00:00 +02:00
if (object2intmap.getInt(enumcreaturetype) <= k1) {
2019-12-10 23:00:00 +01:00
SpawnerCreature.a(enumcreaturetype, this.world, chunk, blockposition);
2020-01-21 22:00:00 +01:00
@@ -507,12 +557,18 @@
2019-07-13 20:19:44 +02:00
@Override
protected boolean executeNext() {
+ // CraftBukkit start - process pending Chunk loadCallback() and unloadCallback() after each run task
+ try {
if (ChunkProviderServer.this.tickDistanceManager()) {
return true;
} else {
ChunkProviderServer.this.lightEngine.queueUpdate();
return super.executeNext();
}
+ } finally {
+ playerChunkMap.callbackExecutor.run();
+ }
+ // CraftBukkit end
}
}
}