3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-23 23:00:08 +01:00
Paper/nms-patches/BehaviorAttackTargetForget.patch

33 Zeilen
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, old, (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);
}
}