diff --git a/common/src/main/java/net/william278/huskhomes/random/NormalDistributionEngine.java b/common/src/main/java/net/william278/huskhomes/random/NormalDistributionEngine.java index a33f4441..c85cfe7d 100644 --- a/common/src/main/java/net/william278/huskhomes/random/NormalDistributionEngine.java +++ b/common/src/main/java/net/william278/huskhomes/random/NormalDistributionEngine.java @@ -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> getRandomPosition(@NotNull World world, @NotNull String[] args) { Optional location = generateSafeLocation(world).join(); diff --git a/common/src/main/java/net/william278/huskhomes/random/RandomTeleportEngine.java b/common/src/main/java/net/william278/huskhomes/random/RandomTeleportEngine.java index 575e5542..cf2165a8 100644 --- a/common/src/main/java/net/william278/huskhomes/random/RandomTeleportEngine.java +++ b/common/src/main/java/net/william278/huskhomes/random/RandomTeleportEngine.java @@ -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> getRandomPosition(@NotNull World world, @NotNull String[] args);