From d947c62c6a188f62a174d15f24fdad9dcae5724e Mon Sep 17 00:00:00 2001 From: Charlie Wang Date: Fri, 12 Jul 2013 13:02:42 -0400 Subject: [PATCH] properly randomized the sheep spawn coordinates --- src/gibstick/bukkit/discosheep/DiscoParty.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/gibstick/bukkit/discosheep/DiscoParty.java b/src/gibstick/bukkit/discosheep/DiscoParty.java index f804ae5..95342c9 100644 --- a/src/gibstick/bukkit/discosheep/DiscoParty.java +++ b/src/gibstick/bukkit/discosheep/DiscoParty.java @@ -77,12 +77,16 @@ public class DiscoParty { World world = player.getWorld(); for (int i = 0; i < num; i++) { - double x, y, z; + double x = player.getLocation().getX(); + double z = player.getLocation().getZ(); + double y; + + // random point on circle with polar coordinates + double r = Math.sqrt(Math.random()) * sheepSpawnRadius; // sqrt for uniform distribution + double azimuth = Math.random() * 2 * Math.PI; // radians + x += r * Math.cos(azimuth); + z += r * Math.sin(azimuth); - // random x, z, and yaw - // safe y-coordinate - x = -sheepSpawnRadius + (Math.random() * ((sheepSpawnRadius * 2) + 1)) + player.getLocation().getX(); - z = -sheepSpawnRadius + (Math.random() * ((sheepSpawnRadius * 2) + 1)) + player.getLocation().getZ(); y = world.getHighestBlockYAt((int) x, (int) z); loc = new Location(world, x, y, z); //loc.setYaw(0);