From ebeebbde72899cd29097879963fafe406b9b57ba Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Sat, 20 Dec 2014 19:11:08 +0100 Subject: [PATCH] Randomize spawn location of Call of the Wild pets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So that when you’re spawning multiple pets at once, they don’t all spawn at the same spot. --- .../nossr50/skills/taming/TamingManager.java | 1 + src/main/java/com/gmail/nossr50/util/Misc.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java index 244fd1682..80d0fc9c6 100644 --- a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java @@ -277,6 +277,7 @@ public class TamingManager extends SkillManager { return; } + location = Misc.getLocationOffset(location, 1); LivingEntity entity = (LivingEntity) player.getWorld().spawnEntity(location, type); FakeEntityTameEvent event = new FakeEntityTameEvent(entity, player); diff --git a/src/main/java/com/gmail/nossr50/util/Misc.java b/src/main/java/com/gmail/nossr50/util/Misc.java index 18f6f8253..d6e3f17fc 100644 --- a/src/main/java/com/gmail/nossr50/util/Misc.java +++ b/src/main/java/com/gmail/nossr50/util/Misc.java @@ -144,6 +144,23 @@ public final class Misc { return "UnknownMods"; } + /** + * Gets a random location near the specified location + */ + public static Location getLocationOffset(Location location, double strength) { + double blockX = location.getBlockX(); + double blockZ = location.getBlockZ(); + + double distance; + distance = strength * random.nextDouble(); + blockX = (random.nextBoolean()) ? blockX + (distance) : blockX - (distance); + + distance = strength * random.nextDouble(); + blockZ = (random.nextBoolean()) ? blockZ + (distance) : blockZ - (distance); + + return new Location(location.getWorld(), blockX, location.getY(), blockZ); + } + public static Random getRandom() { return random; }