From 3e7ce7c1a0bece6a9c12a08806a48fa1ada04b1f Mon Sep 17 00:00:00 2001 From: Felix Cravic Date: Sun, 9 Aug 2020 08:20:38 +0200 Subject: [PATCH] Improved MeleeAttackGoal --- .../minestom/server/entity/ai/goal/MeleeAttackGoal.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/minestom/server/entity/ai/goal/MeleeAttackGoal.java b/src/main/java/net/minestom/server/entity/ai/goal/MeleeAttackGoal.java index 547a921fc..f963b258d 100644 --- a/src/main/java/net/minestom/server/entity/ai/goal/MeleeAttackGoal.java +++ b/src/main/java/net/minestom/server/entity/ai/goal/MeleeAttackGoal.java @@ -18,6 +18,8 @@ public class MeleeAttackGoal extends GoalSelector { private int delay; private TimeUnit timeUnit; + private boolean stop; + /** * @param entityCreature the entity to add the goal to * @param delay the delay between each attacks @@ -43,7 +45,10 @@ public class MeleeAttackGoal extends GoalSelector { @Override public void tick(long time) { final Entity target = getTarget(); - if (target != null) { + + this.stop = target == null; + + if (!stop) { // Attack the target entity if (entityCreature.getBoundingBox().intersect(target)) { @@ -65,7 +70,7 @@ public class MeleeAttackGoal extends GoalSelector { @Override public boolean shouldEnd() { - return entityCreature.getTarget() == null; + return stop; } @Override