From 8088e21ba4a8ff201286c5c0a9b50e63a16ee8a1 Mon Sep 17 00:00:00 2001 From: Electroblob77 <35599699+Electroblob77@users.noreply.github.com> Date: Mon, 29 Jun 2020 21:22:01 +0100 Subject: [PATCH] Remove attack target as soon as mind control wears off, fixes mind controlled entities continuing to attack a target that dies after the mind control wears off --- .../java/electroblob/wizardry/spell/MindControl.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/electroblob/wizardry/spell/MindControl.java b/src/main/java/electroblob/wizardry/spell/MindControl.java index 4fff4f6f..e5ed36c5 100644 --- a/src/main/java/electroblob/wizardry/spell/MindControl.java +++ b/src/main/java/electroblob/wizardry/spell/MindControl.java @@ -24,6 +24,7 @@ import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent; +import net.minecraftforge.event.entity.living.PotionEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @@ -214,4 +215,12 @@ public class MindControl extends SpellRay { processTargeting(event.getEntity().world, (EntityLiving)event.getEntityLiving(), event.getTarget()); } + @SubscribeEvent + public static void onPotionExpiryEvent(PotionEvent.PotionExpiryEvent event){ + if(event.getPotionEffect() != null && event.getPotionEffect().getPotion() == WizardryPotions.mind_control + && event.getEntity() instanceof EntityLiving){ + ((EntityLiving)event.getEntity()).setAttackTarget(null); // End effect + } + } + } \ No newline at end of file