From 0e027bc62f5f249364aeb53efffa702b6a24e509 Mon Sep 17 00:00:00 2001 From: Konstantin Shandurenko Date: Tue, 2 Mar 2021 14:58:32 +0300 Subject: [PATCH] Comments for CombinedAttackGoal --- .../minestom/server/entity/ai/goal/CombinedAttackGoal.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/net/minestom/server/entity/ai/goal/CombinedAttackGoal.java b/src/main/java/net/minestom/server/entity/ai/goal/CombinedAttackGoal.java index d057c1dd8..9ea4083d4 100644 --- a/src/main/java/net/minestom/server/entity/ai/goal/CombinedAttackGoal.java +++ b/src/main/java/net/minestom/server/entity/ai/goal/CombinedAttackGoal.java @@ -120,6 +120,7 @@ public class CombinedAttackGoal extends GoalSelector { } double distanceSquared = this.entityCreature.getDistanceSquared(target); boolean comeClose = false; + // First of all, checking if to perform melee or ranged attack depending on the distance to target. if (distanceSquared <= this.meleeRangeSquared) { if (!CooldownUtils.hasCooldown(time, this.lastAttack, this.meleeTimeUnit, this.meleeDelay)) { this.entityCreature.attack(target, true); @@ -128,6 +129,7 @@ public class CombinedAttackGoal extends GoalSelector { } else if (distanceSquared <= this.rangedRangeSquared) { if (!CooldownUtils.hasCooldown(time, this.lastAttack, this.rangedTimeUnit, this.rangedDelay)) { if (this.entityCreature.hasLineOfSight(target)) { + // If target is on line of entity sight, ranged attack can be performed Position to = target.getPosition().clone().add(0D, target.getEyeHeight(), 0D); Function projectileGenerator = this.projectileGenerator; @@ -140,18 +142,21 @@ public class CombinedAttackGoal extends GoalSelector { projectile.shoot(to, this.rangedPower, this.rangedSpread); this.lastAttack = time; } else { + // Otherwise deciding whether to go to the enemy. comeClose = this.comeClose; } } } Navigator navigator = this.entityCreature.getNavigator(); Position pathPosition = navigator.getPathPosition(); + // If we don't want to come close and we're already within desirable range, no movement is needed. if (!comeClose && distanceSquared <= this.desirableRangeSquared) { if (pathPosition != null) { navigator.setPathTo(null); } return; } + // Otherwise going to the target. Position targetPosition = target.getPosition(); if (pathPosition == null || !pathPosition.isSimilar(targetPosition)) { navigator.setPathTo(targetPosition);