Skip to content

Commit 06d31eb

Browse files
committed
change: more cleanup
1 parent a723938 commit 06d31eb

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/main/java/ca/spottedleaf/starlight/mixin/common/lightengine/ThreadedLevelLightEngineMixin.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import java.util.concurrent.CompletableFuture;
3434
import java.util.concurrent.atomic.AtomicLong;
35+
import java.util.function.Consumer;
3536
import java.util.function.Supplier;
3637

3738
@Mixin(ThreadedLevelLightEngine.class)
@@ -67,7 +68,7 @@ private void queueTaskForSection(final int chunkX, final int chunkY, final int c
6768
return;
6869
}
6970

70-
if (ChunkSystemHooks.isNonFullTicket() && center.getPersistedStatus() != ChunkStatus.FULL) { // TODO check if getHighestGeneratedStatus() is a better idea
71+
if (!ChunkSystemHooks.isNonFullTicket() && center.getPersistedStatus() != ChunkStatus.FULL) { // TODO check if getHighestGeneratedStatus() is a better idea
7172
// do not keep chunk loaded, we are probably in a gen thread
7273
// if we proceed to add a ticket the chunk will be loaded, which is not what we want (avoid cascading gen)
7374
runnable.get();
@@ -106,7 +107,7 @@ private void queueTaskForSection(final int chunkX, final int chunkY, final int c
106107
ChunkSystemHooks.addLightTicket(world, pos);
107108
}
108109

109-
updateFuture.onComplete.thenAcceptAsync((final Void ignore) -> {
110+
Consumer<Void> cleanup = (final Void ignore) -> {
110111
synchronized (this.chunksBeingWorkedOn) {
111112
final int newReferences = this.chunksBeingWorkedOn.addTo(key, -1);
112113
if (newReferences == 1) {
@@ -117,7 +118,14 @@ private void queueTaskForSection(final int chunkX, final int chunkY, final int c
117118
ChunkSystemHooks.removeLightTicket(world, pos);
118119
}
119120
}
120-
}, world.getChunkSource().chunkMap.mainThreadExecutor).whenComplete((final Void ignore, final Throwable thr) -> {
121+
};
122+
CompletableFuture<Void> future;
123+
if (ChunkSystemHooks.isTicketThreadSafe()) {
124+
future = updateFuture.onComplete.thenAccept(cleanup);
125+
} else {
126+
future = updateFuture.onComplete.thenAcceptAsync(cleanup, world.getChunkSource().chunkMap.mainThreadExecutor);
127+
}
128+
future.whenComplete((final Void ignore, final Throwable thr) -> {
121129
if (thr != null) {
122130
LOGGER.error("Failed to remove ticket level for post chunk task " + new ChunkPos(chunkX, chunkZ), thr);
123131
}

0 commit comments

Comments
 (0)