Skip to content

Commit

Permalink
Fix level loading screen showing 0% until in-game (#7)
Browse files Browse the repository at this point in the history
* Fix level loading screen showing 0% until in-game

* Schedule loading screen updates

* null check progress listener

* move out of loop
  • Loading branch information
jpenilla authored Aug 24, 2024
1 parent b8f281a commit 2e0f0ab
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.server.level.FullChunkStatus;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.progress.ChunkProgressListener;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.LevelChunk;
Expand Down Expand Up @@ -80,7 +81,13 @@ public static void onChunkHolderCreate(final ServerLevel level, final ChunkHolde
}

public static void onChunkHolderDelete(final ServerLevel level, final ChunkHolder holder) {

// Update progress listener for LevelLoadingScreen
final ChunkProgressListener progressListener = level.getChunkSource().chunkMap.progressListener;
if (progressListener != null) {
ChunkSystem.scheduleChunkTask(level, holder.getPos().x, holder.getPos().z, () -> {
progressListener.onStatusChange(holder.getPos(), null);
});
}
}

public static void onChunkPreBorder(final LevelChunk chunk, final ChunkHolder holder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import net.minecraft.server.level.ChunkLevel;
import net.minecraft.server.level.FullChunkStatus;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.progress.ChunkProgressListener;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.ChunkAccess;
Expand Down Expand Up @@ -1353,6 +1354,17 @@ void addStatusConsumer(final ChunkStatus status, final Consumer<ChunkAccess> con
}

private void completeStatusConsumers(ChunkStatus status, final ChunkAccess chunk) {
// Update progress listener for LevelLoadingScreen
if (chunk != null) {
final ChunkProgressListener progressListener = this.world.getChunkSource().chunkMap.progressListener;
if (progressListener != null) {
final ChunkStatus finalStatus = status;
this.scheduler.scheduleChunkTask(this.chunkX, this.chunkZ, () -> {
progressListener.onStatusChange(this.vanillaChunkHolder.getPos(), finalStatus);
});
}
}

// need to tell future statuses to complete if cancelled
do {
this.completeStatusConsumers0(status, chunk);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/moonrise.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ accessible method net/minecraft/server/level/ChunkMap setServerViewDistance (I)V
accessible method net/minecraft/server/level/ChunkMap upgradeChunkTag (Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/nbt/CompoundTag;
accessible field net/minecraft/server/level/ChunkMap worldGenContext Lnet/minecraft/world/level/chunk/status/WorldGenContext;
accessible field net/minecraft/server/level/ChunkMap tickingGenerated Ljava/util/concurrent/atomic/AtomicInteger;
accessible field net/minecraft/server/level/ChunkMap progressListener Lnet/minecraft/server/level/progress/ChunkProgressListener;

# ChunkLevel
accessible field net/minecraft/server/level/ChunkLevel FULL_CHUNK_LEVEL I
Expand Down

0 comments on commit 2e0f0ab

Please sign in to comment.