@@ -27,36 +27,39 @@ record PaperChunkSnapshotProvider(
27
27
public CompletableFuture <@ Nullable ChunkSnapshot > asyncSnapshot (final int x , final int z ) {
28
28
return CompletableFuture .supplyAsync (() -> {
29
29
final @ Nullable ChunkAccess existing = this .level .getChunkIfLoadedImmediately (x , z );
30
- if (existing != null && existing .getPersistedStatus ().isOrAfter (ChunkStatus .FULL )) {
31
- return CompletableFuture .completedFuture (existing );
32
- } else if (existing != null ) {
33
- return CompletableFuture .<@ Nullable ChunkAccess >completedFuture (null );
30
+ if (existing != null ) {
31
+ final @ Nullable ChunkSnapshot snapshot = this .maybeSnapshot (existing );
32
+ if (snapshot != null ) {
33
+ return CompletableFuture .completedFuture (snapshot );
34
+ }
34
35
}
35
- final CompletableFuture <@ Nullable ChunkAccess > load = new CompletableFuture <>();
36
+ final CompletableFuture <@ Nullable ChunkSnapshot > load = new CompletableFuture <>();
36
37
ChunkSystem .scheduleChunkLoad (
37
38
this .level ,
38
39
x ,
39
40
z ,
40
41
ChunkStatus .EMPTY ,
41
42
true ,
42
43
PrioritisedExecutor .Priority .NORMAL ,
43
- load :: complete
44
+ chunk -> load . complete ( this . maybeSnapshot ( chunk ))
44
45
);
45
46
return load ;
46
- }, this .executor (x , z )).thenCompose (chunkFuture -> chunkFuture .thenApplyAsync (chunk -> {
47
- if (chunk == null ) {
47
+ }, this .executor (x , z )).thenCompose (future -> future );
48
+ }
49
+
50
+ private @ Nullable ChunkSnapshot maybeSnapshot (@ Nullable ChunkAccess chunk ) {
51
+ if (chunk == null ) {
52
+ return null ;
53
+ }
54
+ if (chunk instanceof ImposterProtoChunk imposter ) {
55
+ chunk = imposter .getWrapped ();
56
+ }
57
+ if (!chunk .getPersistedStatus ().isOrAfter (ChunkStatus .FULL )) {
58
+ if (chunk .getBelowZeroRetrogen () == null || !chunk .getBelowZeroRetrogen ().targetStatus ().isOrAfter (ChunkStatus .SPAWN )) {
48
59
return null ;
49
60
}
50
- if (chunk instanceof ImposterProtoChunk imposter ) {
51
- chunk = imposter .getWrapped ();
52
- }
53
- if (!chunk .getPersistedStatus ().isOrAfter (ChunkStatus .FULL )) {
54
- if (chunk .getBelowZeroRetrogen () == null || !chunk .getBelowZeroRetrogen ().targetStatus ().isOrAfter (ChunkStatus .SPAWN )) {
55
- return null ;
56
- }
57
- }
58
- return ChunkSnapshot .snapshot (this .level , chunk , false );
59
- }, this .executor (x , z )));
61
+ }
62
+ return ChunkSnapshot .snapshot (this .level , chunk , false );
60
63
}
61
64
62
65
private Executor executor (final int x , final int z ) {
0 commit comments