mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 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,
|
protected static Location generateLocation(@NotNull Location origin, float mean, float standardDeviation,
|
||||||
float spawnRadius, float maxRadius) {
|
float spawnRadius, float maxRadius) {
|
||||||
// Generate random values
|
// Generate random values
|
||||||
final float radius = generateNormallyDistributedRadius(mean, standardDeviation, spawnRadius, maxRadius);
|
final float radius = getDistributedRadius(mean, standardDeviation, spawnRadius, maxRadius);
|
||||||
final float angle = generateRandomAngle();
|
final float angle = getRandomAngle();
|
||||||
|
|
||||||
// Calculate corresponding x and z
|
// Calculate corresponding x and z
|
||||||
final float z = (float) (radius * Math.cos(angle));
|
final float z = (float) (radius * Math.cos(angle));
|
||||||
final float x = (float) (radius * Math.sin(angle));
|
final float x = (float) (radius * Math.sin(angle));
|
||||||
|
|
||||||
return new Location(origin.x + x, 128, origin.z + z,
|
return new Location(Math.round(origin.x) + x, 128d, Math.round(origin.z) + z, origin.world);
|
||||||
origin.yaw, origin.pitch, origin.world);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,11 +66,11 @@ public class NormalDistributionEngine extends RandomTeleportEngine {
|
|||||||
*
|
*
|
||||||
* @return the generated radius
|
* @return the generated radius
|
||||||
*/
|
*/
|
||||||
private static float generateNormallyDistributedRadius(float mean, float standardDeviation,
|
private static float getDistributedRadius(float mean, float standardDeviation,
|
||||||
float spawnRadius, float maxRadius) {
|
float spawnRadius, float maxRadius) {
|
||||||
double value = (new Random().nextGaussian() * mean + standardDeviation) * maxRadius;
|
double value = (new Random().nextGaussian() * mean + standardDeviation) * maxRadius;
|
||||||
if (value < spawnRadius || value > maxRadius) {
|
if (value < spawnRadius || value > maxRadius) {
|
||||||
return generateNormallyDistributedRadius(mean, standardDeviation, spawnRadius, maxRadius);
|
return getDistributedRadius(mean, standardDeviation, spawnRadius, maxRadius);
|
||||||
}
|
}
|
||||||
return (float) value;
|
return (float) value;
|
||||||
}
|
}
|
||||||
@@ -81,11 +80,10 @@ public class NormalDistributionEngine extends RandomTeleportEngine {
|
|||||||
*
|
*
|
||||||
* @return a random angle in the range [0, 360]
|
* @return a random angle in the range [0, 360]
|
||||||
*/
|
*/
|
||||||
private static float generateRandomAngle() {
|
private static float getRandomAngle() {
|
||||||
return (float) (Math.random() * 360);
|
return (float) (Math.random() * 360);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Optional<Position>> getRandomPosition(@NotNull World world, @NotNull String[] args) {
|
public CompletableFuture<Optional<Position>> getRandomPosition(@NotNull World world, @NotNull String[] args) {
|
||||||
Optional<Location> location = generateSafeLocation(world).join();
|
Optional<Location> location = generateSafeLocation(world).join();
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ public abstract class RandomTeleportEngine {
|
|||||||
@NotNull
|
@NotNull
|
||||||
protected final HuskHomes plugin;
|
protected final HuskHomes plugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the random teleport engine
|
||||||
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public final String name;
|
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
|
* 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 world The world to find a random position in
|
||||||
* @param args The arguments to pass to the random teleport engine
|
* @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
|
* @return A {@link CompletableFuture} containing the random position, if one is found in
|
||||||
* {@link #randomTimeout operation timed out}
|
* {@link #randomTimeout configured number of attempts}
|
||||||
*/
|
*/
|
||||||
public abstract CompletableFuture<Optional<Position>> getRandomPosition(@NotNull World world, @NotNull String[] args);
|
public abstract CompletableFuture<Optional<Position>> getRandomPosition(@NotNull World world, @NotNull String[] args);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user