Fix NPE in HurtByTargetGoal when mods set targets to null. Closes #7853

This commit is contained in:
LexManos committed 2024-05-20 16:21:17 -07:00
1 parent c037e6aca1
commit 7c36115e3d
1 file changed
+13
@@ -0,0 +1,13 @@
--- a/net/minecraft/world/entity/ai/goal/target/HurtByTargetGoal.java
+++ b/net/minecraft/world/entity/ai/goal/target/HurtByTargetGoal.java
@@ -84,6 +_,10 @@
}
mob = (Mob)iterator.next();
+ // Fix NPE if modders do things vanilla doesn't expect. https://github.com/MinecraftForge/MinecraftForge/issues/7853
+ if (this.mob.getLastHurtByMob() == null)
+ return;
+
if (this.mob != mob
&& mob.getTarget() == null
&& (!(this.mob instanceof TamableAnimal) || ((TamableAnimal)this.mob).getOwner() == ((TamableAnimal)mob).getOwner())