Return earlier if check count exceeds max tries

This commit is contained in:
Phoenix616 2019-07-27 15:39:50 +01:00
parent aa9d995e4d
commit 988f2ee736

View File

@ -314,6 +314,11 @@ public class RandomSearcher {
} }
do { do {
checks++;
if (checks >= maxTries) {
future.completeExceptionally(new NotFoundException("location"));
return;
}
if (loadedOnly) { if (loadedOnly) {
Chunk chunk = loadedChunks[random.nextInt(loadedChunks.length)]; Chunk chunk = loadedChunks[random.nextInt(loadedChunks.length)];
randChunkX = chunk.getX(); randChunkX = chunk.getX();
@ -322,11 +327,6 @@ public class RandomSearcher {
randChunkX = (random.nextBoolean() ? 1 : -1) * random.nextInt(maxChunk + 1); randChunkX = (random.nextBoolean() ? 1 : -1) * random.nextInt(maxChunk + 1);
randChunkZ = (random.nextBoolean() ? 1 : -1) * random.nextInt(maxChunk + 1); randChunkZ = (random.nextBoolean() ? 1 : -1) * random.nextInt(maxChunk + 1);
} }
checks++;
if (checks >= maxTries) {
future.completeExceptionally(new NotFoundException("location"));
return;
}
} while (!checked.put(randChunkX, randChunkZ) || !inRadius(randChunkX, randChunkZ, minChunk, maxChunk)); } while (!checked.put(randChunkX, randChunkZ) || !inRadius(randChunkX, randChunkZ, minChunk, maxChunk));
randomLoc.setX(((center.getBlockX() >> 4) + randChunkX) * 16); randomLoc.setX(((center.getBlockX() >> 4) + randChunkX) * 16);