Skip to content

Commit

Permalink
fix: fix a possible NPE in AllayWorldGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Nov 19, 2024
1 parent 6ab6d99 commit 8569ea6
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.allaymc.api.server.Server;
import org.allaymc.api.utils.HashUtils;
import org.allaymc.api.world.Dimension;
import org.allaymc.api.world.chunk.Chunk;
Expand All @@ -25,7 +24,10 @@
import org.allaymc.server.world.chunk.AllayChunk;
import org.allaymc.server.world.chunk.AllayUnsafeChunk;

import java.util.*;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -146,7 +148,9 @@ private boolean tryEnterPopulationStage(int x, int z) {
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) {
var chunkHash = HashUtils.hashXZ(x + i, z + j);
if (populationLocks.contains(chunkHash)) return false;
if (populationLocks.contains(chunkHash)) {
return false;
}
var noiseFuture = chunkNoiseFutures.get(chunkHash);
if (noiseFuture == null) {
// Chunk noise not generated
Expand Down Expand Up @@ -329,7 +333,7 @@ public final class PopulationStageChunkSource implements ChunkSource {
public Chunk getChunk(int x, int z) {
if (x == currentChunk.getX() && z == currentChunk.getZ()) return currentChunk;
if (!isInRange(x, z)) {
// log.warn("Attempted to access chunk out of range during chunk population stage! CurrentChunk: ({}. {}), RequestedChunk: ({}. {})", currentChunk.getX(), currentChunk.getZ(), x, z);
log.debug("Attempted to access chunk out of range during chunk population stage! CurrentChunk: ({}. {}), RequestedChunk: ({}. {})", currentChunk.getX(), currentChunk.getZ(), x, z);
return null;
}

Expand All @@ -340,9 +344,9 @@ public Chunk getChunk(int x, int z) {
return chunk;
}

var loadedChunk = dimension.getChunkService().getChunk(x, z);
Preconditions.checkNotNull(loadedChunk);
return loadedChunk;
// The return chunk can also be null, because
// it may have been unloaded at this point
return dimension.getChunkService().getChunk(x, z);
}

private boolean isInRange(int x, int z) {
Expand Down

0 comments on commit 8569ea6

Please sign in to comment.