mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 14:38:53 +00:00
Ensure users get put in centre of blocks, fix #263
This commit is contained in:
1 parent
a3ea62a85c
commit
107d654cd5
2 files changed
+13
-12
No files matched your search
@@ -39,15 +39,14 @@ public class NormalDistributionEngine extends RandomTeleportEngine {
|
||||
protected static Location generateLocation(@NotNull Location origin, float mean, float standardDeviation,
|
||||
float spawnRadius, float maxRadius) {
|
||||
// Generate random values
|
||||
final float radius = generateNormallyDistributedRadius(mean, standardDeviation, spawnRadius, maxRadius);
|
||||
final float angle = generateRandomAngle();
|
||||
final float radius = getDistributedRadius(mean, standardDeviation, spawnRadius, maxRadius);
|
||||
final float angle = getRandomAngle();
|
||||
|
||||
// Calculate corresponding x and z
|
||||
final float z = (float) (radius * Math.cos(angle));
|
||||
final float x = (float) (radius * Math.sin(angle));
|
||||
|
||||
return new Location(origin.x + x, 128, origin.z + z,
|
||||
origin.yaw, origin.pitch, origin.world);
|
||||
return new Location(Math.round(origin.x) + x, 128d, Math.round(origin.z) + z, origin.world);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,11 +66,11 @@ public class NormalDistributionEngine extends RandomTeleportEngine {
|
||||
*
|
||||
* @return the generated radius
|
||||
*/
|
||||
private static float generateNormallyDistributedRadius(float mean, float standardDeviation,
|
||||
float spawnRadius, float maxRadius) {
|
||||
private static float getDistributedRadius(float mean, float standardDeviation,
|
||||
float spawnRadius, float maxRadius) {
|
||||
double value = (new Random().nextGaussian() * mean + standardDeviation) * maxRadius;
|
||||
if (value < spawnRadius || value > maxRadius) {
|
||||
return generateNormallyDistributedRadius(mean, standardDeviation, spawnRadius, maxRadius);
|
||||
return getDistributedRadius(mean, standardDeviation, spawnRadius, maxRadius);
|
||||
}
|
||||
return (float) value;
|
||||
}
|
||||
@@ -81,11 +80,10 @@ public class NormalDistributionEngine extends RandomTeleportEngine {
|
||||
*
|
||||
* @return a random angle in the range [0, 360]
|
||||
*/
|
||||
private static float generateRandomAngle() {
|
||||
private static float getRandomAngle() {
|
||||
return (float) (Math.random() * 360);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Optional<Position>> getRandomPosition(@NotNull World world, @NotNull String[] args) {
|
||||
Optional<Location> location = generateSafeLocation(world).join();
|
||||
|
||||
@@ -13,6 +13,9 @@ public abstract class RandomTeleportEngine {
|
||||
@NotNull
|
||||
protected final HuskHomes plugin;
|
||||
|
||||
/**
|
||||
* The name of the random teleport engine
|
||||
*/
|
||||
@NotNull
|
||||
public final String name;
|
||||
|
||||
@@ -45,12 +48,12 @@ public abstract class RandomTeleportEngine {
|
||||
|
||||
/**
|
||||
* Gets a random position in the {@link World}, supplying a future to be completed with the optional position
|
||||
* is found, or empty if the operation times out
|
||||
* is found, or empty if the operation times out after a number of attempts.
|
||||
*
|
||||
* @param world The world to find a random position in
|
||||
* @param args The arguments to pass to the random teleport engine
|
||||
* @return A {@link CompletableFuture} containing the random position, if one was found before the
|
||||
* {@link #randomTimeout operation timed out}
|
||||
* @return A {@link CompletableFuture} containing the random position, if one is found in
|
||||
* {@link #randomTimeout configured number of attempts}
|
||||
*/
|
||||
public abstract CompletableFuture<Optional<Position>> getRandomPosition(@NotNull World world, @NotNull String[] args);
|
||||
|
||||
|
||||
Reference in new issue
Block a user