Skip to content

Commit

Permalink
fix: allow cancellation on unloading stage 3
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Jan 18, 2025
1 parent 3272b4b commit ce05a9d
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,6 @@ public CompletionStage<Void> downgradeFromThis(ChunkLoadingContext context, Canc
worldChunk.setLoadedToWorld(false);
}

if (loadedToWorld.get() && ModStatuses.fabric_lifecycle_events_v1 && chunk instanceof WorldChunk worldChunk) {
LifecycleEventInvoker.invokeChunkUnload(((IThreadedAnvilChunkStorage) context.tacs()).getWorld(), worldChunk);
}

if ((context.holder().getFlags() & ItemHolder.FLAG_BROKEN) != 0 && chunk instanceof ProtoChunk) { // do not save broken ProtoChunks
LOGGER.warn("Not saving partially generated broken chunk {}", context.holder().getKey());
return CompletableFuture.completedStage((Void) null);
Expand All @@ -166,7 +162,19 @@ public CompletionStage<Void> downgradeFromThis(ChunkLoadingContext context, Canc
.thenAcceptAsync(unused -> {
Chunk chunk = context.holder().getItem().get().chunk();
if (chunk instanceof WrapperProtoChunk protoChunk) chunk = protoChunk.getWrappedChunk();

if (context.holder().getTargetStatus().ordinal() >= this.ordinal()) { // saving cancelled late
if (chunk instanceof WorldChunk worldChunk) {
worldChunk.setLoadedToWorld(loadedToWorld.get());
}
cancellable.cancel();
throw new CancellationException();
}

if (loadedToWorld.get() && chunk instanceof WorldChunk worldChunk) {
if (ModStatuses.fabric_lifecycle_events_v1) {
LifecycleEventInvoker.invokeChunkUnload(((IThreadedAnvilChunkStorage) context.tacs()).getWorld(), worldChunk);
}
((IThreadedAnvilChunkStorage) context.tacs()).getWorld().unloadEntities(worldChunk);
}

Expand Down

0 comments on commit ce05a9d

Please sign in to comment.