mirror of
https://github.com/Phoenix616/RandomTeleport.git
synced 2024-11-10 20:59:35 +01:00
Fix issues with very small ranges and fix only corners getting found
This also makes the max-range inclusive instead of exclusive as that makes more sense. Previously a searcher with max range of 1 would not find a new coordinate, it should find one at least one block next to it.
This commit is contained in:
parent
8a17bfc000
commit
ce3ad0e0fa
@ -279,11 +279,9 @@ public class RandomSearcher {
|
||||
Location randomLoc = center.clone();
|
||||
randomLoc.setY(0);
|
||||
do {
|
||||
randomLoc.setX(center.getBlockX() + (random.nextBoolean() ? 1 : -1) * random.nextInt(maxRadius));
|
||||
} while (!inRange(randomLoc.getBlockX(), center.getBlockX()));
|
||||
do {
|
||||
randomLoc.setZ(center.getBlockZ() + (random.nextBoolean() ? 1 : -1) * random.nextInt(maxRadius));
|
||||
} while (!inRange(randomLoc.getBlockZ(), center.getBlockZ()));
|
||||
randomLoc.setX(center.getBlockX() + (random.nextBoolean() ? 1 : -1) * (random.nextInt(maxRadius + 1)));
|
||||
randomLoc.setZ(center.getBlockZ() + (random.nextBoolean() ? 1 : -1) * (random.nextInt(maxRadius + 1)));
|
||||
} while (!inRadius(randomLoc));
|
||||
randomLoc.setX((randomLoc.getBlockX() >> 4) * 16);
|
||||
randomLoc.setZ((randomLoc.getBlockZ() >> 4) * 16);
|
||||
PaperLib.getChunkAtAsync(randomLoc, generatedOnly).thenApply(c -> {
|
||||
@ -322,13 +320,10 @@ public class RandomSearcher {
|
||||
}
|
||||
|
||||
private boolean inRadius(Location location) {
|
||||
return inRange(location.getBlockX(), center.getBlockX())
|
||||
|| inRange(location.getBlockZ(), center.getBlockZ()) ;
|
||||
}
|
||||
|
||||
private boolean inRange(int coord, int check) {
|
||||
int diff = Math.abs(check - coord);
|
||||
return diff >= minRadius && diff < maxRadius;
|
||||
int diffX = Math.abs(location.getBlockX() - center.getBlockX());
|
||||
int diffZ = Math.abs(location.getBlockZ() - center.getBlockZ());
|
||||
return diffX >= minRadius && diffX <= maxRadius && diffZ <= maxRadius
|
||||
|| diffZ >= minRadius && diffZ <= maxRadius && diffX <= maxRadius;
|
||||
}
|
||||
|
||||
public RandomTeleport getPlugin() {
|
||||
|
Loading…
Reference in New Issue
Block a user