From a4695bcce1c62b4bfb1b2dee0759c84d30493ba2 Mon Sep 17 00:00:00 2001 From: Electroblob <35599699+Electroblob77@users.noreply.github.com> Date: Sun, 18 Feb 2018 23:32:54 +0000 Subject: [PATCH] Fix curseforge issue #30, where the game would crash when casting mind control on a mob that already had the mind trick status effect --- src/main/java/electroblob/wizardry/spell/MindControl.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/electroblob/wizardry/spell/MindControl.java b/src/main/java/electroblob/wizardry/spell/MindControl.java index 356d58e2..82e99605 100644 --- a/src/main/java/electroblob/wizardry/spell/MindControl.java +++ b/src/main/java/electroblob/wizardry/spell/MindControl.java @@ -187,6 +187,8 @@ public class MindControl extends Spell { @SubscribeEvent public static void onLivingSetAttackTargetEvent(LivingSetAttackTargetEvent event){ + + if(event.getTarget() == null) return; // Prevents infinite loops with mind trick if(event.getEntityLiving().isPotionActive(WizardryPotions.mind_control) && MindControl.canControl(event.getEntityLiving())){ @@ -197,7 +199,7 @@ public class MindControl extends Spell { Entity caster = WizardryUtilities.getEntityByUUID(event.getEntity().worldObj, entityNBT.getUniqueId(MindControl.NBT_KEY)); // If the target that the event tried to set is already a valid mind control target, nothing happens. - if(event.getTarget() != null && WizardryUtilities.isValidTarget(caster, event.getTarget())) return; + if(WizardryUtilities.isValidTarget(caster, event.getTarget())) return; if(caster instanceof EntityLivingBase){ @@ -208,8 +210,7 @@ public class MindControl extends Spell { } } // If the caster couldn't be found or no valid target was found, this just acts like mind trick. - // If the target is null already, no need to set it to null, or infinite loops will occur. - if(event.getTarget() != null) ((EntityLiving)event.getEntityLiving()).setAttackTarget(null); + ((EntityLiving)event.getEntityLiving()).setAttackTarget(null); } }