mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 07:48:53 +01:00
32 lines
1.3 KiB
Diff
32 lines
1.3 KiB
Diff
--- a/net/minecraft/server/BehaviorAttackTargetForget.java
|
|
+++ b/net/minecraft/server/BehaviorAttackTargetForget.java
|
|
@@ -3,6 +3,11 @@
|
|
import com.google.common.collect.ImmutableMap;
|
|
import java.util.Optional;
|
|
import java.util.function.Predicate;
|
|
+// CraftBukkit start
|
|
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
|
|
+import org.bukkit.craftbukkit.event.CraftEventFactory;
|
|
+import org.bukkit.event.entity.EntityTargetEvent;
|
|
+// CraftBukkit end
|
|
|
|
public class BehaviorAttackTargetForget<E extends EntityInsentient> extends Behavior<E> {
|
|
|
|
@@ -54,6 +59,17 @@
|
|
}
|
|
|
|
private void d(E e0) {
|
|
+ // CraftBukkit start
|
|
+ EntityLiving old = e0.getBehaviorController().getMemory(MemoryModuleType.ATTACK_TARGET).orElse(null);
|
|
+ EntityTargetEvent event = CraftEventFactory.callEntityTargetLivingEvent(e0, null, (old != null && !old.isAlive()) ? EntityTargetEvent.TargetReason.TARGET_DIED : EntityTargetEvent.TargetReason.FORGOT_TARGET);
|
|
+ if (event.isCancelled()) {
|
|
+ return;
|
|
+ }
|
|
+ if (event.getTarget() != null) {
|
|
+ e0.getBehaviorController().setMemory(MemoryModuleType.ATTACK_TARGET, ((CraftLivingEntity) event.getTarget()).getHandle());
|
|
+ return;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
e0.getBehaviorController().removeMemory(MemoryModuleType.ATTACK_TARGET);
|
|
}
|
|
}
|