From dfe6ecadac3c37b28a95a6c34d9186f8e7fd3e1b Mon Sep 17 00:00:00 2001 From: Electroblob77 <35599699+Electroblob77@users.noreply.github.com> Date: Sat, 20 Jun 2020 13:10:44 +0100 Subject: [PATCH] Generalise isAllied to all living entities --- .../wizardry/util/AllyDesignationSystem.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main/java/electroblob/wizardry/util/AllyDesignationSystem.java b/src/main/java/electroblob/wizardry/util/AllyDesignationSystem.java index 248b3193..1fb082b9 100644 --- a/src/main/java/electroblob/wizardry/util/AllyDesignationSystem.java +++ b/src/main/java/electroblob/wizardry/util/AllyDesignationSystem.java @@ -190,13 +190,23 @@ public final class AllyDesignationSystem { } /** Umbrella method that covers both {@link AllyDesignationSystem#isPlayerAlly(EntityPlayer, EntityPlayer)} and - * {@link AllyDesignationSystem#isOwnerAlly(EntityPlayer, IEntityOwnable)}, returning true if the given - * {@link EntityLivingBase} is either owned by the given player, an ally of the given player or owned by an ally - * of the given player. This is generally used to determine targets for healing or other group buffs. */ - public static boolean isAllied(EntityPlayer allyOf, EntityLivingBase possibleAlly){ - return (possibleAlly instanceof EntityPlayer && isPlayerAlly(allyOf, (EntityPlayer)possibleAlly)) - || (possibleAlly instanceof IEntityOwnable && (((IEntityOwnable)possibleAlly).getOwner() == allyOf - || isOwnerAlly(allyOf, (IEntityOwnable)possibleAlly))); + * {@link AllyDesignationSystem#isOwnerAlly(EntityPlayer, IEntityOwnable)}, returning true if the second entity is + * either owned by the first entity, an ally of the first entity, or owned by an ally of the first entity. This is + * generally used to determine targets for healing or other group buffs. */ + public static boolean isAllied(EntityLivingBase allyOf, EntityLivingBase possibleAlly){ + + if(allyOf instanceof EntityPlayer && possibleAlly instanceof EntityPlayer + && isPlayerAlly((EntityPlayer)allyOf, (EntityPlayer)possibleAlly)){ + return true; + } + + if(possibleAlly instanceof IEntityOwnable){ + IEntityOwnable pet = (IEntityOwnable)possibleAlly; + if(pet.getOwner() == allyOf) return true; + if(allyOf instanceof EntityPlayer && isOwnerAlly((EntityPlayer)allyOf, pet)) return true; + } + + return false; } /** Helper method for testing if the second player is an ally of the first player. Makes the code neater.