From 39b491b5ed0a234d9a3b308e69c9f47cd3a42a73 Mon Sep 17 00:00:00 2001 From: Sollace Date: Tue, 23 Oct 2018 10:05:29 +0200 Subject: [PATCH] Accidentally made this public, but let's make intentional because why not? --- src/main/java/com/minelittlepony/PonyManager.java | 13 ++++++++++--- .../java/com/minelittlepony/util/math/MathUtil.java | 8 ++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/minelittlepony/PonyManager.java b/src/main/java/com/minelittlepony/PonyManager.java index 75bdd237..a2157af6 100644 --- a/src/main/java/com/minelittlepony/PonyManager.java +++ b/src/main/java/com/minelittlepony/PonyManager.java @@ -7,6 +7,7 @@ import com.google.gson.JsonParseException; import com.minelittlepony.pony.data.IPony; import com.minelittlepony.pony.data.Pony; import com.minelittlepony.pony.data.PonyLevel; +import com.minelittlepony.util.math.MathUtil; import com.voxelmodpack.hdskins.ISkinCacheClearListener; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; @@ -121,13 +122,19 @@ public class PonyManager implements IResourceManagerReloadListener, ISkinCacheCl return getBackgroundPony(uuid); } - private IPony getBackgroundPony(UUID uuid) { + /** + * Gets a random background pony determined by the given uuid. + * + * Useful for mods that offer customisation, especially ones that have a whole lot of NPCs. + * + * @param uuid A UUID. Either a user or an entity. + */ + public IPony getBackgroundPony(UUID uuid) { if (getNumberOfPonies() == 0 || isUser(uuid)) { return getPony(getDefaultSkin(uuid)); } - int bgi = uuid.hashCode() % getNumberOfPonies(); - while (bgi < 0) bgi += getNumberOfPonies(); + int bgi = MathUtil.mod(uuid.hashCode(), getNumberOfPonies()); return getPony(backgroundPonyList.get(bgi)); } diff --git a/src/main/java/com/minelittlepony/util/math/MathUtil.java b/src/main/java/com/minelittlepony/util/math/MathUtil.java index 83824908..dd34b543 100644 --- a/src/main/java/com/minelittlepony/util/math/MathUtil.java +++ b/src/main/java/com/minelittlepony/util/math/MathUtil.java @@ -8,6 +8,14 @@ public class MathUtil { return MathHelper.clamp(num, -limit, limit); } + public static int mod(int value, int mod) { + value %= mod; + + while (value < 0) value += mod; + + return value; + } + public static float sensibleAngle(float angle) { angle %= 360;