mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-09 19:49:35 +01:00
b2efd58164
By: md_5 <git@md-5.net>
33 lines
1.3 KiB
Diff
33 lines
1.3 KiB
Diff
--- a/net/minecraft/server/BehaviorAttackTargetForget.java
|
|
+++ b/net/minecraft/server/BehaviorAttackTargetForget.java
|
|
@@ -4,6 +4,12 @@
|
|
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> {
|
|
|
|
private final Predicate<EntityLiving> b;
|
|
@@ -54,6 +60,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);
|
|
}
|
|
}
|