Skip to content

Commit

Permalink
Run to end of iterator as much as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
TelepathicGrunt committed Dec 12, 2023
1 parent 4d256bb commit 53298ff
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class GenerationTask {
private volatile Listener listener;
private volatile boolean stopped;

public static final TicketType<ChunkPos> NEOFORGE_FORCED = TicketType.create("neoforge_forced", Comparator.comparingLong(ChunkPos::toLong));
public static final TicketType<ChunkPos> NEOFORGE_GENERATE_FORCED = TicketType.create("neoforge_generate_forced", Comparator.comparingLong(ChunkPos::toLong));

public GenerationTask(ServerLevel serverLevel, int x, int z, int radius) {
this.server = serverLevel.getServer();
Expand Down Expand Up @@ -171,10 +171,11 @@ private LongList collectChunks(int count) {
LongList chunks = new LongArrayList(count);

Iterator<ChunkPos> iterator = this.iterator;
for (int i = 0; i < count && iterator.hasNext(); i++) {
for (int i = 0; i < count && iterator.hasNext();) {
ChunkPos chunk = iterator.next();
if (Math.abs(chunk.x) <= this.radius && Math.abs(chunk.z) <= this.radius) {
chunks.add(ChunkPos.asLong(chunk.x + this.x, chunk.z + this.z));
i++;
}
}

Expand All @@ -183,12 +184,12 @@ private LongList collectChunks(int count) {

private void acquireChunk(long chunk) {
ChunkPos pos = new ChunkPos(chunk);
this.chunkSource.addRegionTicket(NEOFORGE_FORCED, pos, 0, pos);
this.chunkSource.addRegionTicket(NEOFORGE_GENERATE_FORCED, pos, 0, pos);
}

private void releaseChunk(long chunk) {
ChunkPos pos = new ChunkPos(chunk);
this.chunkSource.addRegionTicket(NEOFORGE_FORCED, pos, 0, pos);
this.chunkSource.addRegionTicket(NEOFORGE_GENERATE_FORCED, pos, 0, pos);
}

public interface Listener {
Expand Down

0 comments on commit 53298ff

Please sign in to comment.