1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
|
--- a/net/minecraft/server/level/ServerChunkCache.java
+++ b/net/minecraft/server/level/ServerChunkCache.java
@@ -28,9 +28,9 @@
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.ai.village.poi.PoiManager;
import net.minecraft.world.level.ChunkPos;
+import net.minecraft.world.level.EnumSkyBlock;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.Level;
-import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.LocalMobCapCalculator;
import net.minecraft.world.level.NaturalSpawner;
import net.minecraft.world.level.chunk.ChunkAccess;
@@ -58,8 +58,8 @@
public final ChunkMap chunkMap;
private final DimensionDataStorage dataStorage;
private long lastInhabitedUpdate;
- private boolean spawnEnemies = true;
- private boolean spawnFriendlies = true;
+ public boolean spawnEnemies = true;
+ public boolean spawnFriendlies = true;
private static final int CACHE_SIZE = 4;
private final long[] lastChunkPos = new long[4];
private final ChunkStatus[] lastChunkStatus = new ChunkStatus[4];
@@ -68,127 +68,134 @@
@VisibleForDebug
private NaturalSpawner.SpawnState lastSpawnState;
- public ServerChunkCache(ServerLevel serverlevel, LevelStorageSource.LevelStorageAccess levelstoragesource_levelstorageaccess, DataFixer datafixer, StructureTemplateManager structuretemplatemanager, Executor executor, ChunkGenerator chunkgenerator, int i, int j, boolean flag, ChunkProgressListener chunkprogresslistener, ChunkStatusUpdateListener chunkstatusupdatelistener, Supplier<DimensionDataStorage> supplier) {
- this.level = serverlevel;
- this.mainThreadProcessor = new ServerChunkCache.MainThreadExecutor(serverlevel);
+ public ServerChunkCache(ServerLevel level, LevelStorageSource.LevelStorageAccess levelStorageAccess, DataFixer fixerUpper, StructureTemplateManager structureManager, Executor dispatcher, ChunkGenerator generator, int viewDistance, int simulationDistance, boolean sync, ChunkProgressListener progressListener, ChunkStatusUpdateListener chunkStatusListener, Supplier<DimensionDataStorage> overworldDataStorage) {
+ this.level = level;
+ this.mainThreadProcessor = new ServerChunkCache.MainThreadExecutor(level);
this.mainThread = Thread.currentThread();
- File file = levelstoragesource_levelstorageaccess.getDimensionPath(serverlevel.dimension()).resolve("data").toFile();
+ File file = levelStorageAccess.getDimensionPath(level.dimension()).resolve("data").toFile();
file.mkdirs();
- this.dataStorage = new DimensionDataStorage(file, datafixer);
- this.chunkMap = new ChunkMap(serverlevel, levelstoragesource_levelstorageaccess, datafixer, structuretemplatemanager, executor, this.mainThreadProcessor, this, chunkgenerator, chunkprogresslistener, chunkstatusupdatelistener, supplier, i, flag);
+ this.dataStorage = new DimensionDataStorage(file, fixerUpper);
+ this.chunkMap = new ChunkMap(level, levelStorageAccess, fixerUpper, structureManager, dispatcher, this.mainThreadProcessor, this, generator, progressListener, chunkStatusListener, overworldDataStorage, viewDistance, sync);
this.lightEngine = this.chunkMap.getLightEngine();
this.distanceManager = this.chunkMap.getDistanceManager();
- this.distanceManager.updateSimulationDistance(j);
+ this.distanceManager.updateSimulationDistance(simulationDistance);
this.clearCache();
}
+ // CraftBukkit start - properly implement isChunkLoaded
+ public boolean isChunkLoaded(int chunkX, int chunkZ) {
+ ChunkHolder chunk = this.chunkMap.getUpdatingChunkIfPresent(ChunkPos.asLong(chunkX, chunkZ));
+ if (chunk == null) {
+ return false;
+ }
+ return chunk.getFullChunkNow() != null;
+ }
+ // CraftBukkit end
+
@Override
- @Override
public ThreadedLevelLightEngine getLightEngine() {
return this.lightEngine;
}
@Nullable
- private ChunkHolder getVisibleChunkIfPresent(long i) {
- return this.chunkMap.getVisibleChunkIfPresent(i);
+ private ChunkHolder getVisibleChunkIfPresent(long chunkPos) {
+ return this.chunkMap.getVisibleChunkIfPresent(chunkPos);
}
public int getTickingGenerated() {
return this.chunkMap.getTickingGenerated();
}
- private void storeInCache(long i, ChunkAccess chunkaccess, ChunkStatus chunkstatus) {
+ private void storeInCache(long chunkPos, ChunkAccess ichunkaccess, ChunkStatus chunk) {
for (int j = 3; j > 0; --j) {
this.lastChunkPos[j] = this.lastChunkPos[j - 1];
this.lastChunkStatus[j] = this.lastChunkStatus[j - 1];
this.lastChunk[j] = this.lastChunk[j - 1];
}
- this.lastChunkPos[0] = i;
- this.lastChunkStatus[0] = chunkstatus;
- this.lastChunk[0] = chunkaccess;
+ this.lastChunkPos[0] = chunkPos;
+ this.lastChunkStatus[0] = chunk;
+ this.lastChunk[0] = ichunkaccess;
}
@Nullable
@Override
- @Override
- public ChunkAccess getChunk(int i, int j, ChunkStatus chunkstatus, boolean flag) {
+ public ChunkAccess getChunk(int chunkX, int chunkZ, ChunkStatus requiredStatus, boolean load) {
if (Thread.currentThread() != this.mainThread) {
return (ChunkAccess) CompletableFuture.supplyAsync(() -> {
- return this.getChunk(i, j, chunkstatus, flag);
+ return this.getChunk(chunkX, chunkZ, requiredStatus, load);
}, this.mainThreadProcessor).join();
} else {
- ProfilerFiller profilerfiller = this.level.getProfiler();
+ ProfilerFiller gameprofilerfiller = this.level.getProfiler();
- profilerfiller.incrementCounter("getChunk");
- long k = ChunkPos.asLong(i, j);
+ gameprofilerfiller.incrementCounter("getChunk");
+ long k = ChunkPos.asLong(chunkX, chunkZ);
- ChunkAccess chunkaccess;
+ ChunkAccess ichunkaccess;
for (int l = 0; l < 4; ++l) {
- if (k == this.lastChunkPos[l] && chunkstatus == this.lastChunkStatus[l]) {
- chunkaccess = this.lastChunk[l];
- if (chunkaccess != null || !flag) {
- return chunkaccess;
+ if (k == this.lastChunkPos[l] && requiredStatus == this.lastChunkStatus[l]) {
+ ichunkaccess = this.lastChunk[l];
+ 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;
}
}
}
- profilerfiller.incrementCounter("getChunkCacheMiss");
- CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> completablefuture = this.getChunkFutureMainThread(i, j, chunkstatus, flag);
- ServerChunkCache.MainThreadExecutor serverchunkcache_mainthreadexecutor = this.mainThreadProcessor;
+ gameprofilerfiller.incrementCounter("getChunkCacheMiss");
+ CompletableFuture<Either<ChunkAccess, ChunkHolder.Failure>> completablefuture = this.getChunkFutureMainThread(chunkX, chunkZ, requiredStatus, load);
+ ServerChunkCache.MainThreadExecutor chunkproviderserver_b = this.mainThreadProcessor;
Objects.requireNonNull(completablefuture);
- serverchunkcache_mainthreadexecutor.managedBlock(completablefuture::isDone);
- chunkaccess = (ChunkAccess) ((Either) completablefuture.join()).map((chunkaccess1) -> {
- return chunkaccess1;
- }, (chunkholder_chunkloadingfailure) -> {
- if (flag) {
- throw (IllegalStateException) Util.pauseInIde(new IllegalStateException("Chunk not there when requested: " + chunkholder_chunkloadingfailure));
+ chunkproviderserver_b.managedBlock(completablefuture::isDone);
+ ichunkaccess = (ChunkAccess) ((Either) completablefuture.join()).map((ichunkaccess1) -> {
+ return ichunkaccess1;
+ }, (playerchunk_failure) -> {
+ if (load) {
+ throw (IllegalStateException) Util.pauseInIde(new IllegalStateException("Chunk not there when requested: " + playerchunk_failure));
} else {
return null;
}
});
- this.storeInCache(k, chunkaccess, chunkstatus);
- return chunkaccess;
+ this.storeInCache(k, ichunkaccess, requiredStatus);
+ return ichunkaccess;
}
}
@Nullable
@Override
- @Override
- public LevelChunk getChunkNow(int i, int j) {
+ public LevelChunk getChunkNow(int chunkX, int chunkZ) {
if (Thread.currentThread() != this.mainThread) {
return null;
} else {
this.level.getProfiler().incrementCounter("getChunkNow");
- long k = ChunkPos.asLong(i, j);
+ long k = ChunkPos.asLong(chunkX, chunkZ);
for (int l = 0; l < 4; ++l) {
if (k == this.lastChunkPos[l] && this.lastChunkStatus[l] == ChunkStatus.FULL) {
- ChunkAccess chunkaccess = this.lastChunk[l];
+ ChunkAccess ichunkaccess = this.lastChunk[l];
- return chunkaccess instanceof LevelChunk ? (LevelChunk) chunkaccess : null;
+ return ichunkaccess instanceof LevelChunk ? (LevelChunk) ichunkaccess : null;
}
}
- ChunkHolder chunkholder = this.getVisibleChunkIfPresent(k);
+ ChunkHolder playerchunk = this.getVisibleChunkIfPresent(k);
- if (chunkholder == null) {
+ if (playerchunk == null) {
return null;
} else {
- Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure> either = (Either) chunkholder.getFutureIfPresent(ChunkStatus.FULL).getNow((Object) null);
+ Either<ChunkAccess, ChunkHolder.Failure> either = (Either) playerchunk.getFutureIfPresent(ChunkStatus.FULL).getNow(null); // CraftBukkit - decompile error
if (either == null) {
return null;
} else {
- ChunkAccess chunkaccess1 = (ChunkAccess) either.left().orElse((Object) null);
+ ChunkAccess ichunkaccess1 = (ChunkAccess) either.left().orElse(null); // CraftBukkit - decompile error
- if (chunkaccess1 != null) {
- this.storeInCache(k, chunkaccess1, ChunkStatus.FULL);
- if (chunkaccess1 instanceof LevelChunk) {
- return (LevelChunk) chunkaccess1;
+ if (ichunkaccess1 != null) {
+ this.storeInCache(k, ichunkaccess1, ChunkStatus.FULL);
+ if (ichunkaccess1 instanceof LevelChunk) {
+ return (LevelChunk) ichunkaccess1;
}
}
@@ -204,19 +211,19 @@
Arrays.fill(this.lastChunk, (Object) null);
}
- public CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> getChunkFuture(int i, int j, ChunkStatus chunkstatus, boolean flag) {
+ public CompletableFuture<Either<ChunkAccess, ChunkHolder.Failure>> getChunkFuture(int x, int y, ChunkStatus chunkStatus, boolean load) {
boolean flag1 = Thread.currentThread() == this.mainThread;
CompletableFuture completablefuture;
if (flag1) {
- completablefuture = this.getChunkFutureMainThread(i, j, chunkstatus, flag);
- ServerChunkCache.MainThreadExecutor serverchunkcache_mainthreadexecutor = this.mainThreadProcessor;
+ completablefuture = this.getChunkFutureMainThread(x, y, chunkStatus, load);
+ ServerChunkCache.MainThreadExecutor chunkproviderserver_b = this.mainThreadProcessor;
Objects.requireNonNull(completablefuture);
- serverchunkcache_mainthreadexecutor.managedBlock(completablefuture::isDone);
+ chunkproviderserver_b.managedBlock(completablefuture::isDone);
} else {
completablefuture = CompletableFuture.supplyAsync(() -> {
- return this.getChunkFutureMainThread(i, j, chunkstatus, flag);
+ return this.getChunkFutureMainThread(x, y, chunkStatus, load);
}, this.mainThreadProcessor).thenCompose((completablefuture1) -> {
return completablefuture1;
});
@@ -225,58 +232,64 @@
return completablefuture;
}
- private CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> getChunkFutureMainThread(int i, int j, ChunkStatus chunkstatus, boolean flag) {
- ChunkPos chunkpos = new ChunkPos(i, j);
- long k = chunkpos.toLong();
- int l = ChunkLevel.byStatus(chunkstatus);
- ChunkHolder chunkholder = this.getVisibleChunkIfPresent(k);
+ private CompletableFuture<Either<ChunkAccess, ChunkHolder.Failure>> getChunkFutureMainThread(int x, int y, ChunkStatus chunkStatus, boolean load) {
+ ChunkPos chunkcoordintpair = new ChunkPos(x, y);
+ long k = chunkcoordintpair.toLong();
+ int l = ChunkLevel.byStatus(chunkStatus);
+ ChunkHolder playerchunk = this.getVisibleChunkIfPresent(k);
- if (flag) {
- this.distanceManager.addTicket(TicketType.UNKNOWN, chunkpos, l, chunkpos);
- if (this.chunkAbsent(chunkholder, l)) {
- ProfilerFiller profilerfiller = this.level.getProfiler();
+ // 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 (load && !currentlyUnloading) {
+ // CraftBukkit end
+ this.distanceManager.addTicket(TicketType.UNKNOWN, chunkcoordintpair, l, chunkcoordintpair);
+ if (this.chunkAbsent(playerchunk, l)) {
+ ProfilerFiller gameprofilerfiller = this.level.getProfiler();
- profilerfiller.push("chunkLoad");
+ gameprofilerfiller.push("chunkLoad");
this.runDistanceManagerUpdates();
- chunkholder = this.getVisibleChunkIfPresent(k);
- profilerfiller.pop();
- if (this.chunkAbsent(chunkholder, l)) {
+ playerchunk = this.getVisibleChunkIfPresent(k);
+ gameprofilerfiller.pop();
+ if (this.chunkAbsent(playerchunk, l)) {
throw (IllegalStateException) Util.pauseInIde(new IllegalStateException("No chunk holder after ticket has been added"));
}
}
}
- return this.chunkAbsent(chunkholder, l) ? ChunkHolder.UNLOADED_CHUNK_FUTURE : chunkholder.getOrScheduleFuture(chunkstatus, this.chunkMap);
+ return this.chunkAbsent(playerchunk, l) ? ChunkHolder.UNLOADED_CHUNK_FUTURE : playerchunk.getOrScheduleFuture(chunkStatus, this.chunkMap);
}
- private boolean chunkAbsent(@Nullable ChunkHolder chunkholder, int i) {
- return chunkholder == null || chunkholder.getTicketLevel() > i;
+ private boolean chunkAbsent(@Nullable ChunkHolder chunkHolder, int status) {
+ return chunkHolder == null || chunkHolder.oldTicketLevel > status; // CraftBukkit using oldTicketLevel for isLoaded checks
}
@Override
- @Override
- public boolean hasChunk(int i, int j) {
- ChunkHolder chunkholder = this.getVisibleChunkIfPresent((new ChunkPos(i, j)).toLong());
+ public boolean hasChunk(int x, int z) {
+ ChunkHolder playerchunk = this.getVisibleChunkIfPresent((new ChunkPos(x, z)).toLong());
int k = ChunkLevel.byStatus(ChunkStatus.FULL);
- return !this.chunkAbsent(chunkholder, k);
+ return !this.chunkAbsent(playerchunk, k);
}
@Nullable
@Override
- @Override
- public LightChunk getChunkForLighting(int i, int j) {
- long k = ChunkPos.asLong(i, j);
- ChunkHolder chunkholder = this.getVisibleChunkIfPresent(k);
+ public LightChunk getChunkForLighting(int chunkX, int chunkZ) {
+ long k = ChunkPos.asLong(chunkX, chunkZ);
+ ChunkHolder playerchunk = this.getVisibleChunkIfPresent(k);
- if (chunkholder == null) {
+ if (playerchunk == null) {
return null;
} else {
int l = ServerChunkCache.CHUNK_STATUSES.size() - 1;
while (true) {
ChunkStatus chunkstatus = (ChunkStatus) ServerChunkCache.CHUNK_STATUSES.get(l);
- Optional<ChunkAccess> optional = ((Either) chunkholder.getFutureIfPresentUnchecked(chunkstatus).getNow(ChunkHolder.UNLOADED_CHUNK)).left();
+ Optional<ChunkAccess> optional = ((Either) playerchunk.getFutureIfPresentUnchecked(chunkstatus).getNow(ChunkHolder.UNLOADED_CHUNK)).left();
if (optional.isPresent()) {
return (LightChunk) optional.get();
@@ -292,7 +305,6 @@
}
@Override
- @Override
public Level getLevel() {
return this.level;
}
@@ -313,47 +325,65 @@
}
}
- public boolean isPositionTicking(long i) {
- ChunkHolder chunkholder = this.getVisibleChunkIfPresent(i);
+ public boolean isPositionTicking(long chunkPos) {
+ ChunkHolder playerchunk = this.getVisibleChunkIfPresent(chunkPos);
- if (chunkholder == null) {
+ if (playerchunk == null) {
return false;
- } else if (!this.level.shouldTickBlocksAt(i)) {
+ } else if (!this.level.shouldTickBlocksAt(chunkPos)) {
return false;
} else {
- Either<LevelChunk, ChunkHolder.ChunkLoadingFailure> either = (Either) chunkholder.getTickingChunkFuture().getNow((Object) null);
+ Either<LevelChunk, ChunkHolder.Failure> either = (Either) playerchunk.getTickingChunkFuture().getNow(null); // CraftBukkit - decompile error
return either != null && either.left().isPresent();
}
}
- public void save(boolean flag) {
+ public void save(boolean flush) {
this.runDistanceManagerUpdates();
- this.chunkMap.saveAllChunks(flag);
+ this.chunkMap.saveAllChunks(flush);
}
@Override
- @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
- @Override
- public void tick(BooleanSupplier booleansupplier, boolean flag) {
+ public void tick(BooleanSupplier hasTimeLeft, boolean tickChunks) {
this.level.getProfiler().push("purge");
this.distanceManager.purgeStaleTickets();
this.runDistanceManagerUpdates();
this.level.getProfiler().popPush("chunks");
- if (flag) {
+ if (tickChunks) {
this.tickChunks();
this.chunkMap.tick();
}
this.level.getProfiler().popPush("unload");
- this.chunkMap.tick(booleansupplier);
+ this.chunkMap.tick(hasTimeLeft);
this.level.getProfiler().pop();
this.clearCache();
}
@@ -364,79 +394,78 @@
this.lastInhabitedUpdate = i;
if (!this.level.isDebug()) {
- ProfilerFiller profilerfiller = this.level.getProfiler();
+ ProfilerFiller gameprofilerfiller = this.level.getProfiler();
- profilerfiller.push("pollingChunks");
- profilerfiller.push("filteringLoadedChunks");
- List<ServerChunkCache.ChunkAndHolder> list = Lists.newArrayListWithCapacity(this.chunkMap.size());
+ gameprofilerfiller.push("pollingChunks");
+ gameprofilerfiller.push("filteringLoadedChunks");
+ List<ServerChunkCache.a> list = Lists.newArrayListWithCapacity(this.chunkMap.size());
Iterator iterator = this.chunkMap.getChunks().iterator();
while (iterator.hasNext()) {
- ChunkHolder chunkholder = (ChunkHolder) iterator.next();
- LevelChunk levelchunk = chunkholder.getTickingChunk();
+ ChunkHolder playerchunk = (ChunkHolder) iterator.next();
+ LevelChunk chunk = playerchunk.getTickingChunk();
- if (levelchunk != null) {
- list.add(new ServerChunkCache.ChunkAndHolder(levelchunk, chunkholder));
+ if (chunk != null) {
+ list.add(new ServerChunkCache.a(chunk, playerchunk));
}
}
if (this.level.getServer().tickRateManager().runsNormally()) {
- profilerfiller.popPush("naturalSpawnCount");
+ gameprofilerfiller.popPush("naturalSpawnCount");
int k = this.distanceManager.getNaturalSpawnChunkCount();
- NaturalSpawner.SpawnState naturalspawner_spawnstate = NaturalSpawner.createState(k, this.level.getAllEntities(), this::getFullChunk, new LocalMobCapCalculator(this.chunkMap));
+ NaturalSpawner.SpawnState spawnercreature_d = NaturalSpawner.createState(k, this.level.getAllEntities(), this::getFullChunk, new LocalMobCapCalculator(this.chunkMap));
- this.lastSpawnState = naturalspawner_spawnstate;
- profilerfiller.popPush("spawnAndTick");
- boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING);
+ this.lastSpawnState = spawnercreature_d;
+ gameprofilerfiller.popPush("spawnAndTick");
+ boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !this.level.players().isEmpty(); // CraftBukkit
Util.shuffle(list, this.level.random);
int l = this.level.getGameRules().getInt(GameRules.RULE_RANDOMTICKING);
- 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
Iterator iterator1 = list.iterator();
while (iterator1.hasNext()) {
- ServerChunkCache.ChunkAndHolder serverchunkcache_chunkandholder = (ServerChunkCache.ChunkAndHolder) iterator1.next();
- LevelChunk levelchunk1 = serverchunkcache_chunkandholder.chunk;
- ChunkPos chunkpos = levelchunk1.getPos();
+ ServerChunkCache.a chunkproviderserver_a = (ServerChunkCache.a) iterator1.next();
+ LevelChunk chunk1 = chunkproviderserver_a.chunk;
+ ChunkPos chunkcoordintpair = chunk1.getPos();
- if (this.level.isNaturalSpawningAllowed(chunkpos) && this.chunkMap.anyPlayerCloseEnoughForSpawning(chunkpos)) {
- levelchunk1.incrementInhabitedTime(j);
- if (flag && (this.spawnEnemies || this.spawnFriendlies) && this.level.getWorldBorder().isWithinBounds(chunkpos)) {
- NaturalSpawner.spawnForChunk(this.level, levelchunk1, naturalspawner_spawnstate, this.spawnFriendlies, this.spawnEnemies, flag1);
+ if (this.level.isNaturalSpawningAllowed(chunkcoordintpair) && this.chunkMap.anyPlayerCloseEnoughForSpawning(chunkcoordintpair)) {
+ chunk1.incrementInhabitedTime(j);
+ if (flag && (this.spawnEnemies || this.spawnFriendlies) && this.level.getWorldBorder().isWithinBounds(chunkcoordintpair)) {
+ NaturalSpawner.spawnForChunk(this.level, chunk1, spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag1);
}
- if (this.level.shouldTickBlocksAt(chunkpos.toLong())) {
- this.level.tickChunk(levelchunk1, l);
+ if (this.level.shouldTickBlocksAt(chunkcoordintpair.toLong())) {
+ this.level.tickChunk(chunk1, l);
}
}
}
- profilerfiller.popPush("customSpawners");
+ gameprofilerfiller.popPush("customSpawners");
if (flag) {
this.level.tickCustomSpawners(this.spawnEnemies, this.spawnFriendlies);
}
}
- profilerfiller.popPush("broadcast");
- list.forEach((serverchunkcache_chunkandholder1) -> {
- serverchunkcache_chunkandholder1.holder.broadcastChanges(serverchunkcache_chunkandholder1.chunk);
+ gameprofilerfiller.popPush("broadcast");
+ list.forEach((chunkproviderserver_a1) -> {
+ chunkproviderserver_a1.holder.broadcastChanges(chunkproviderserver_a1.chunk);
});
- profilerfiller.pop();
- profilerfiller.pop();
+ gameprofilerfiller.pop();
+ gameprofilerfiller.pop();
}
}
- private void getFullChunk(long i, Consumer<LevelChunk> consumer) {
- ChunkHolder chunkholder = this.getVisibleChunkIfPresent(i);
+ private void getFullChunk(long chunkPos, Consumer<LevelChunk> consumer) {
+ ChunkHolder playerchunk = this.getVisibleChunkIfPresent(chunkPos);
- if (chunkholder != null) {
- ((Either) chunkholder.getFullChunkFuture().getNow(ChunkHolder.UNLOADED_LEVEL_CHUNK)).left().ifPresent(consumer);
+ if (playerchunk != null) {
+ ((Either) playerchunk.getFullChunkFuture().getNow(ChunkHolder.UNLOADED_LEVEL_CHUNK)).left().ifPresent(consumer);
}
}
@Override
- @Override
public String gatherStats() {
return Integer.toString(this.getLoadedChunksCount());
}
@@ -459,52 +488,49 @@
}
@Override
- @Override
public int getLoadedChunksCount() {
return this.chunkMap.size();
}
- public void blockChanged(BlockPos blockpos) {
- int i = SectionPos.blockToSectionCoord(blockpos.getX());
- int j = SectionPos.blockToSectionCoord(blockpos.getZ());
- ChunkHolder chunkholder = this.getVisibleChunkIfPresent(ChunkPos.asLong(i, j));
+ public void blockChanged(BlockPos pos) {
+ int i = SectionPos.blockToSectionCoord(pos.getX());
+ int j = SectionPos.blockToSectionCoord(pos.getZ());
+ ChunkHolder playerchunk = this.getVisibleChunkIfPresent(ChunkPos.asLong(i, j));
- if (chunkholder != null) {
- chunkholder.blockChanged(blockpos);
+ if (playerchunk != null) {
+ playerchunk.blockChanged(pos);
}
}
@Override
- @Override
- public void onLightUpdate(LightLayer lightlayer, SectionPos sectionpos) {
+ public void onLightUpdate(EnumSkyBlock type, SectionPos pos) {
this.mainThreadProcessor.execute(() -> {
- ChunkHolder chunkholder = this.getVisibleChunkIfPresent(sectionpos.chunk().toLong());
+ ChunkHolder playerchunk = this.getVisibleChunkIfPresent(pos.chunk().toLong());
- if (chunkholder != null) {
- chunkholder.sectionLightChanged(lightlayer, sectionpos.y());
+ if (playerchunk != null) {
+ playerchunk.sectionLightChanged(type, pos.y());
}
});
}
- public <T> void addRegionTicket(TicketType<T> tickettype, ChunkPos chunkpos, int i, T t0) {
- this.distanceManager.addRegionTicket(tickettype, chunkpos, i, t0);
+ public <T> void addRegionTicket(TicketType<T> type, ChunkPos pos, int distance, T value) {
+ this.distanceManager.addRegionTicket(type, pos, distance, value);
}
- public <T> void removeRegionTicket(TicketType<T> tickettype, ChunkPos chunkpos, int i, T t0) {
- this.distanceManager.removeRegionTicket(tickettype, chunkpos, i, t0);
+ public <T> void removeRegionTicket(TicketType<T> type, ChunkPos pos, int distance, T value) {
+ this.distanceManager.removeRegionTicket(type, pos, distance, value);
}
@Override
- @Override
- public void updateChunkForced(ChunkPos chunkpos, boolean flag) {
- this.distanceManager.updateChunkForced(chunkpos, flag);
+ public void updateChunkForced(ChunkPos pos, boolean add) {
+ this.distanceManager.updateChunkForced(pos, add);
}
- public void move(ServerPlayer serverplayer) {
- if (!serverplayer.isRemoved()) {
- this.chunkMap.move(serverplayer);
+ public void move(ServerPlayer player) {
+ if (!player.isRemoved()) {
+ this.chunkMap.move(player);
}
}
@@ -525,23 +551,22 @@
this.chunkMap.broadcast(entity, packet);
}
- public void setViewDistance(int i) {
- this.chunkMap.setServerViewDistance(i);
+ public void setViewDistance(int viewDistance) {
+ this.chunkMap.setServerViewDistance(viewDistance);
}
- public void setSimulationDistance(int i) {
- this.distanceManager.updateSimulationDistance(i);
+ public void setSimulationDistance(int simulationDistance) {
+ this.distanceManager.updateSimulationDistance(simulationDistance);
}
@Override
- @Override
- public void setSpawnSettings(boolean flag, boolean flag1) {
- this.spawnEnemies = flag;
- this.spawnFriendlies = flag1;
+ public void setSpawnSettings(boolean hostile, boolean peaceful) {
+ this.spawnEnemies = hostile;
+ this.spawnFriendlies = peaceful;
}
- public String getChunkDebugData(ChunkPos chunkpos) {
- return this.chunkMap.getChunkDebugData(chunkpos);
+ public String getChunkDebugData(ChunkPos chunkPos) {
+ return this.chunkMap.getChunkDebugData(chunkPos);
}
public DimensionDataStorage getDataStorage() {
@@ -568,53 +593,54 @@
private final class MainThreadExecutor extends BlockableEventLoop<Runnable> {
- MainThreadExecutor(Level level) {
- super("Chunk source main thread executor for " + level.dimension().location());
+ MainThreadExecutor(Level world) {
+ super("Chunk source main thread executor for " + world.dimension().location());
}
@Override
- @Override
protected Runnable wrapRunnable(Runnable runnable) {
return runnable;
}
@Override
- @Override
protected boolean shouldRun(Runnable runnable) {
return true;
}
@Override
- @Override
protected boolean scheduleExecutables() {
return true;
}
@Override
- @Override
protected Thread getRunningThread() {
return ServerChunkCache.this.mainThread;
}
@Override
- @Override
- protected void doRunTask(Runnable runnable) {
+ protected void doRunTask(Runnable task) {
ServerChunkCache.this.level.getProfiler().incrementCounter("runTask");
- super.doRunTask(runnable);
+ super.doRunTask(task);
}
@Override
- protected boolean pollTask() {
+ // CraftBukkit start - process pending Chunk loadCallback() and unloadCallback() after each run task
+ public boolean pollTask() {
+ try {
if (ServerChunkCache.this.runDistanceManagerUpdates()) {
return true;
} else {
ServerChunkCache.this.lightEngine.tryScheduleUpdate();
return super.pollTask();
}
+ } finally {
+ chunkMap.callbackExecutor.run();
}
+ // CraftBukkit end
+ }
}
- private static record ChunkAndHolder(LevelChunk chunk, ChunkHolder holder) {
+ private static record a(LevelChunk chunk, ChunkHolder holder) {
}
}
|