Java Code Examples for net.minecraft.entity.EntityLivingBase#getDistanceSq()

The following examples show how to use net.minecraft.entity.EntityLivingBase#getDistanceSq() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegisteredFamiliarAI_Old.java    From Gadomancy with GNU Lesser General Public License v3.0 6 votes vote down vote up
private List<EntityLivingBase> getPotentialTargets(World world, EntityPlayer player, int rangeInc) {
    List<EntityLivingBase> validTargets = getCloseEnoughTargetters(world, player, rangeInc);

    EntityLivingBase attacker = player.getLastAttacker();
    int range = 8 + rangeInc;
    if(attacker != null && !validTargets.contains(attacker) && !attacker.isDead && attacker.getDistanceSq(player.posX, player.posY, player.posZ) <= range * range) {
        validTargets.add(attacker);
    }

    Iterator<EntityLivingBase> it = validTargets.iterator();
    while(it.hasNext()) {
        EntityLivingBase e = it.next();
        if(e.isDead || e instanceof EntityPlayer) it.remove();
    }
    return validTargets;
}
 
Example 2
Source File: EntityMonolithEye.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
public boolean apply(@Nullable EntityLivingBase p_apply_1_) {
	return (p_apply_1_ instanceof EntityPlayer || p_apply_1_ instanceof EntitySquid)
			&& p_apply_1_.getDistanceSq(this.parentEntity) > 9.0D;
}
 
Example 3
Source File: EntityAIMountedAttackOnCollide.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
/**
 * Updates the task
 */
public void updateTask() {

  EntityLivingBase target = attacker.getAttackTarget();
  attacker.getLookHelper().setLookPositionWithEntity(target, 30.0F, 30.0F);        
  --pathUpdateTimer;

  double distanceFromAttackerSq = attacker.getDistanceSq(target.posX, target.getEntityBoundingBox().minY, target.posZ);
  if((longMemory || attacker.getEntitySenses().canSee(target))
      && pathUpdateTimer <= 0
      && (targetPosX == 0.0D && targetPosY == 0.0D && targetPosZ == 0.0D
          || target.getDistanceSq(targetPosX, targetPosY, targetPosZ) >= 1.0D || attacker.getRNG().nextFloat() < 0.05F)) {
    
    targetPosX = target.posX;
    targetPosY = target.getEntityBoundingBox().minY;
    targetPosZ = target.posZ;
    pathUpdateTimer = failedPathFindingPenalty + 4 + attacker.getRNG().nextInt(7);

    if(getNavigator().getPath() != null) {
      PathPoint finalPathPoint = getNavigator().getPath().getFinalPathPoint();
      if(finalPathPoint != null && target.getDistanceSq(finalPathPoint.x, finalPathPoint.y, finalPathPoint.z) < 1) {
        failedPathFindingPenalty = 0;
      } else {
        failedPathFindingPenalty += 10;
      }
    } else {
      failedPathFindingPenalty += 10;
    }
    
    if(distanceFromAttackerSq > 1024.0D) {
      pathUpdateTimer += 10;
    } else if(distanceFromAttackerSq > 256.0D) {
      pathUpdateTimer += 5;
    }

    if(!getNavigator().tryMoveToEntityLiving(target, getAttackSpeed())) {
      pathUpdateTimer += 15;
    }
  }

  attackPause = Math.max(attackPause - 1, 0);
  double d1 = getAttackReach(target);
  if(distanceFromAttackerSq <= d1 && attackPause <= 20) {
    attackPause = 20;
    if(attacker.getHeldItem(EnumHand.MAIN_HAND) != null) {
      attacker.swingArm(EnumHand.MAIN_HAND);
    }
    attacker.attackEntityAsMob(target);
  }
}
 
Example 4
Source File: EntityAIFlyingAttackOnCollide.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
@Override
public void updateTask() {
  EntityLivingBase entitylivingbase = this.attacker.getAttackTarget();
  attacker.getLookHelper().setLookPositionWithEntity(entitylivingbase, 30.0F, 30.0F);
  double distToTargSq = attacker.getDistanceSq(entitylivingbase.posX, entitylivingbase.getEntityBoundingBox().minY, entitylivingbase.posZ);
  double attackRangSq = getAttackRangeSq(entitylivingbase);
  --delayCounter;

  if ((longMemory || attacker.getEntitySenses().canSee(entitylivingbase)) && delayCounter <= 0
      && (targetX == 0.0D && targetY == 0.0D && targetZ == 0.0D
          || entitylivingbase.getDistanceSq(targetX, targetY, targetZ) >= 1.0D || attacker.getRNG().nextFloat() < 0.05F)) {
    targetX = entitylivingbase.posX;
    targetY = entitylivingbase.getEntityBoundingBox().minY;
    targetZ = entitylivingbase.posZ;
    delayCounter = 4 + attacker.getRNG().nextInt(7);

    if (canPenalize) {
      targetX += failedPathFindingPenalty;
      if (attacker.getNavigator().getPath() != null) {
        PathPoint finalPathPoint = attacker.getNavigator().getPath().getFinalPathPoint();
        if (finalPathPoint != null && entitylivingbase.getDistanceSq(finalPathPoint.x, finalPathPoint.y, finalPathPoint.z) < 1)
          failedPathFindingPenalty = 0;
        else
          failedPathFindingPenalty += 10;
      } else {
        failedPathFindingPenalty += 10;
      }
    }

    if (distToTargSq > 1024) {
      delayCounter += 10;
    } else if (distToTargSq > 256) {
      delayCounter += 5;
    }

    if (!flyToAttacker(entitylivingbase)) {
      delayCounter += 15;
    }
  }

  attackTick = Math.max(attackTick - 1, 0);

  if (distToTargSq <= attackRangSq && attackTick <= 0) {
    attackTick = 20;
    if (attacker.getHeldItem(EnumHand.MAIN_HAND) != null) {
      attacker.swingArm(EnumHand.MAIN_HAND);
    }
    attacker.attackEntityAsMob(entitylivingbase);
  }
}
 
Example 5
Source File: EntityAIAttackOnCollideAggressive.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
/**
   * Updates the task
   */
  @Override
  public void updateTask() {

    EntityLivingBase entitylivingbase = attacker.getAttackTarget();
    attacker.getLookHelper().setLookPositionWithEntity(entitylivingbase, 30.0F, 30.0F);
    double distToTargetSq = attacker.getDistanceSq(entitylivingbase.posX, entitylivingbase.getEntityBoundingBox().minY, entitylivingbase.posZ);
    double attachRange = attacker.width * 2.0F * attacker.width * 2.0F + entitylivingbase.width;
    --ticksUntilNextPathingAttempt;

    if ((longMemory || attacker.getEntitySenses().canSee(entitylivingbase))
        && ticksUntilNextPathingAttempt <= 0
        && (targetX == 0.0D && targetY == 0.0D && targetZ == 0.0D || entitylivingbase.getDistanceSq(targetX, targetY, targetZ) >= 1.0D || attacker.getRNG()
            .nextFloat() < 0.05F)) {

      targetX = entitylivingbase.posX;
      targetY = entitylivingbase.getEntityBoundingBox().minY;
      targetZ = entitylivingbase.posZ;

      //ticksUntilNextPathingAttempt = failedPathFindingPenalty + 4 + attacker.getRNG().nextInt(7);

//      if (attacker.getNavigator().getPath() != null) {
//        PathPoint finalPathPoint = attacker.getNavigator().getPath().getFinalPathPoint();
//        if (finalPathPoint != null && entitylivingbase.getDistanceSq(finalPathPoint.xCoord, finalPathPoint.yCoord, finalPathPoint.zCoord) < 1) {
//          failedPathFindingPenalty = 0;
//        } else {
//          failedPathFindingPenalty += 10;
//        }
//      } else {
//        failedPathFindingPenalty += 10;
//      }

      if (distToTargetSq > 1024.0D) {
        ticksUntilNextPathingAttempt += 10;
      } else if (distToTargetSq > 256.0D) {
        ticksUntilNextPathingAttempt += 5;
      }

      if (!attacker.getNavigator().tryMoveToEntityLiving(entitylivingbase, speedTowardsTarget)) {
        ticksUntilNextPathingAttempt += 15;
      }
    }

    ticksToNextAttack = Math.max(ticksToNextAttack - 1, 0);

    if (distToTargetSq <= attachRange && ticksToNextAttack <= 20) {
      ticksToNextAttack = attackFrequency;
      if (attacker.getHeldItem(EnumHand.MAIN_HAND) != null) {        
        attacker.swingArm(EnumHand.MAIN_HAND);
      }
      attacker.attackEntityAsMob(entitylivingbase);
    }
  }