3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-20 21:40:06 +01:00
Paper/nms-patches/ChunkProviderServer.patch

113 Zeilen
6.2 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/ChunkProviderServer.java
+++ b/net/minecraft/server/ChunkProviderServer.java
@@ -81,7 +81,7 @@
for (int l = 0; l < 4; ++l) {
if (k == this.n[l] && chunkstatus == this.o[l]) {
ichunkaccess = this.p[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;
}
}
@@ -125,7 +125,15 @@
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) {
+ PlayerChunk.State oldChunkState = PlayerChunk.c(playerchunk.oldTicketLevel); // PAIL getChunkState
+ PlayerChunk.State currentChunkState = PlayerChunk.c(playerchunk.getTicketLevel()); // PAIL getChunkState
+ currentlyUnloading = (oldChunkState.a(PlayerChunk.State.BORDER) && !currentChunkState.a(PlayerChunk.State.BORDER)); // PAIL isAtLeast
+ }
+ if (flag && !currentlyUnloading) {
+ // CraftBukkit end
this.chunkMapDistance.a(TicketType.UNKNOWN, chunkcoordintpair, l, chunkcoordintpair);
if (this.a(playerchunk, l)) {
GameProfilerFiller gameprofilerfiller = this.world.getMethodProfiler();
@@ -144,14 +152,14 @@
}
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) {
PlayerChunk playerchunk = this.getChunk((new ChunkCoordIntPair(i, j)).pair());
int k = 33 + ChunkStatus.a(ChunkStatus.FULL);
- return playerchunk != null && playerchunk.getTicketLevel() <= k ? ((Either) playerchunk.getStatusFuture(ChunkStatus.FULL).getNow(PlayerChunk.UNLOADED_CHUNK_ACCESS)).left().isPresent() : false;
+ return playerchunk != null && playerchunk.oldTicketLevel <= k ? ((Either) playerchunk.getStatusFuture(ChunkStatus.FULL).getNow(PlayerChunk.UNLOADED_CHUNK_ACCESS)).left().isPresent() : false; // CraftBukkit using oldTicketLevel for isLoaded checks
}
@Override
@@ -241,6 +249,18 @@
2019-04-23 04:00:00 +02:00
this.playerChunkMap.close();
2018-07-15 02:00:00 +02: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();
+ this.l(); // PAIL 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();
@@ -260,13 +280,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;
- boolean flag1 = this.world.getGameRules().getBoolean("doMobSpawning");
+ boolean flag1 = this.world.getGameRules().getBoolean("doMobSpawning") && !world.getPlayers().isEmpty(); // CraftBukkit
2019-04-23 04:00:00 +02:00
if (!flag) {
this.world.getMethodProfiler().enter("pollingChunks");
2019-05-14 02:00:00 +02:00
int k = this.world.getGameRules().c("randomTickSpeed");
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();
@@ -299,8 +319,30 @@
2019-04-23 04:00:00 +02:00
for (int j1 = 0; j1 < i1; ++j1) {
EnumCreatureType enumcreaturetype = aenumcreaturetype1[j1];
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;
+ }
+
2019-04-23 04:00:00 +02:00
+ if (limit == 0) {
+ continue;
+ }
+ // CraftBukkit end
+
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) {
SpawnerCreature.a(enumcreaturetype, (World) this.world, chunk, blockposition);