Class TargetAI<T extends net.minecraft.world.entity.Mob & IThreatTableEntity>

java.lang.Object
com.minecolonies.core.entity.ai.combat.TargetAI<T>
All Implemented Interfaces:
IStateAI
Direct Known Subclasses:
AttackMoveAI

public class TargetAI<T extends net.minecraft.world.entity.Mob & IThreatTableEntity> extends Object implements IStateAI
Target search AI
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected net.minecraft.world.entity.LivingEntity
    Current target reference
    protected final T
    The entity this AI runs for
  • Constructor Summary

    Constructors
    Constructor
    Description
    TargetAI(T user, int targetFrequency, ITickRateStateMachine stateMachine)
    Constructor method for AI
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
    Checks if the current targets is still valid, if not searches a new target.
    protected net.minecraft.world.phys.AABB
    Get the AABB we're searching for targets in.
    protected int
    The search range in blocks, used for determining a shaped aabb entity lookup
    protected int
    Get the Y search range
    protected boolean
    isAttackableTarget(net.minecraft.world.entity.LivingEntity target)
    Whether the target is attackable
    boolean
    isEntityValidTarget(net.minecraft.world.entity.LivingEntity target)
    Checks whether the given entity is a valid target to attack.
    protected boolean
    isWithinPersecutionDistance(net.minecraft.world.entity.LivingEntity target)
    Check if the target is within chasing distance
    protected void
    onTargetChange(net.minecraft.world.entity.LivingEntity newTarget)
    Actions on changing to a new target entity
    protected void
    onTargetDied(net.minecraft.world.entity.LivingEntity target)
    When our previous target has died
    void
    Resets the current target and removes it from all saved targets.
    protected boolean
    Get a target for the guard.
    protected boolean
    skipSearch(net.minecraft.world.entity.LivingEntity entity)
    Skips the search if true

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • user

      protected final T extends net.minecraft.world.entity.Mob & IThreatTableEntity user
      The entity this AI runs for
    • target

      protected net.minecraft.world.entity.LivingEntity target
      Current target reference
  • Constructor Details

    • TargetAI

      public TargetAI(T user, int targetFrequency, ITickRateStateMachine stateMachine)
      Constructor method for AI
      Parameters:
      user - The creature which is using the AI
  • Method Details

    • checkForTarget

      protected boolean checkForTarget()
      Checks if the current targets is still valid, if not searches a new target. Adds experience if the current target died.
      Returns:
      true if we found a target, false if no target.
    • isEntityValidTarget

      public boolean isEntityValidTarget(net.minecraft.world.entity.LivingEntity target)
      Checks whether the given entity is a valid target to attack.
      Parameters:
      target - Entity to check
      Returns:
      true if should attack
    • resetTarget

      public void resetTarget()
      Resets the current target and removes it from all saved targets.
    • searchNearbyTarget

      protected boolean searchNearbyTarget()
      Get a target for the guard. First check if we're under attack by anything and switch target if necessary.
      Returns:
      The next IAIState to go to.
    • skipSearch

      protected boolean skipSearch(net.minecraft.world.entity.LivingEntity entity)
      Skips the search if true
      Parameters:
      entity - checked entity
      Returns:
      true if skip
    • getSearchArea

      protected net.minecraft.world.phys.AABB getSearchArea()
      Get the AABB we're searching for targets in.
      Returns:
      the AABB
    • getYSearchRange

      protected int getYSearchRange()
      Get the Y search range
      Returns:
    • getSearchRange

      protected int getSearchRange()
      The search range in blocks, used for determining a shaped aabb entity lookup
      Returns:
    • isAttackableTarget

      protected boolean isAttackableTarget(net.minecraft.world.entity.LivingEntity target)
      Whether the target is attackable
      Parameters:
      target -
      Returns:
    • isWithinPersecutionDistance

      protected boolean isWithinPersecutionDistance(net.minecraft.world.entity.LivingEntity target)
      Check if the target is within chasing distance
      Parameters:
      target -
      Returns:
    • onTargetDied

      protected void onTargetDied(net.minecraft.world.entity.LivingEntity target)
      When our previous target has died
      Parameters:
      target -
    • onTargetChange

      protected void onTargetChange(net.minecraft.world.entity.LivingEntity newTarget)
      Actions on changing to a new target entity