3030
3131import java .nio .file .Path ;
3232import java .util .concurrent .CompletableFuture ;
33+ import java .util .concurrent .atomic .AtomicInteger ;
3334import java .util .function .Function ;
3435
3536@ Mixin (value = ServerChunkLoadingManager .class , priority = 1099 )
@@ -59,6 +60,8 @@ public MixinThreadedAnvilChunkStorage(StorageKey arg, Path path, DataFixer dataF
5960
6061 @ Shadow protected abstract @ Nullable ChunkHolder getCurrentChunkHolder (long pos );
6162
63+ @ Shadow @ Final private AtomicInteger chunksBeingSavedCount ;
64+
6265 /**
6366 * @author Kroppeb
6467 * @reason Reduces allocations
@@ -87,9 +90,10 @@ private boolean save(Chunk chunk) {
8790
8891 Profilers .get ().visit ("chunkSave" );
8992
93+ this .chunksBeingSavedCount .incrementAndGet ();
94+ SerializedChunk chunkSerializer = SerializedChunk .fromChunk (this .world , chunk );
9095 //region start replaced code
9196 // NbtCompound nbtCompound = ChunkSerializer.serialize(this.world, chunk);
92- SerializedChunk chunkSerializer = SerializedChunk .fromChunk (this .world , chunk );
9397 CompletableFuture <Void > saveFuture = CompletableFuture .supplyAsync (() -> {
9498 NbtWriter nbtWriter = new NbtWriter ();
9599 nbtWriter .start (NbtElement .COMPOUND_TYPE );
@@ -102,6 +106,15 @@ private boolean save(Chunk chunk) {
102106 return future ;
103107 }, ((IVanillaChunkManager ) this ).c2me$getSchedulingManager ().positionedExecutor (chunk .getPos ().toLong ())).thenCompose (Function .identity ());
104108
109+ saveFuture .handle ((void_ , exceptionx ) -> {
110+ if (exceptionx != null ) {
111+ this .world .getServer ().onChunkSaveFailure (exceptionx , this .getStorageKey (), chunkPos );
112+ }
113+
114+ this .chunksBeingSavedCount .decrementAndGet ();
115+ return null ;
116+ });
117+
105118 ChunkHolder holder = this .getCurrentChunkHolder (chunk .getPos ().toLong ());
106119 if (holder != null ) {
107120 ((IChunkHolder ) holder ).invokeCombineSavingFuture (saveFuture );
0 commit comments