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

The following examples show how to use net.minecraft.entity.EntityLivingBase#getEntityBoundingBox() . These examples are extracted from open source projects. 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
protected void attackWithArrow(EntityLivingBase target) {

		int charge = 2 + rand.nextInt(10);

		EntityArrow entityarrow = new EntityTippedArrow(this.world, this);
		double d0 = target.posX - this.posX;
		double d1 = target.getEntityBoundingBox().minY + (double) (target.height / 3.0F) - entityarrow.posY;
		double d2 = target.posZ - this.posZ;
		double d3 = (double) MathHelper.sqrt(d0 * d0 + d2 * d2);
		entityarrow.shoot(d0, d1 + d3 * 0.20000000298023224D, d2, 1.6F,
				(float) (14 - this.world.getDifficulty().getDifficultyId() * 4));
		int i = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.POWER, this);
		int j = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.PUNCH, this);
		entityarrow.setDamage((double) (charge * 2.0F) + this.rand.nextGaussian() * 0.25D
				+ (double) ((float) this.world.getDifficulty().getDifficultyId() * 0.11F));

		if (i > 0) {
			entityarrow.setDamage(entityarrow.getDamage() + (double) i * 0.5D + 0.5D);
		}

		if (j > 0) {
			entityarrow.setKnockbackStrength(j);
		}

		if (rand.nextBoolean()) {
			entityarrow.setFire(100);
		}

		this.playSound(SoundEvents.ENTITY_SKELETON_SHOOT, 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
		this.world.spawnEntity(entityarrow);
	}
 
Example 2
protected void attackWithArrow(EntityLivingBase target) {

		int charge = 2 + rand.nextInt(10);

		EntityArrow entityarrow = new EntityTippedArrow(this.world, this);
		double d0 = target.posX - this.posX;
		double d1 = target.getEntityBoundingBox().minY + (double) (target.height / 3.0F) - entityarrow.posY;
		double d2 = target.posZ - this.posZ;
		double d3 = (double) MathHelper.sqrt(d0 * d0 + d2 * d2);
		entityarrow.shoot(d0, d1 + d3 * 0.20000000298023224D, d2, 1.6F,
				(float) (14 - this.world.getDifficulty().getDifficultyId() * 4));
		int i = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.POWER, this);
		int j = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.PUNCH, this);
		entityarrow.setDamage((double) (charge * 2.0F) + this.rand.nextGaussian() * 0.25D
				+ (double) ((float) this.world.getDifficulty().getDifficultyId() * 0.11F));

		if (i > 0) {
			entityarrow.setDamage(entityarrow.getDamage() + (double) i * 0.5D + 0.5D);
		}

		if (j > 0) {
			entityarrow.setKnockbackStrength(j);
		}

		if (rand.nextBoolean()) {
			entityarrow.setFire(100);
		}

		this.playSound(SoundEvents.ENTITY_SKELETON_SHOOT, 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
		this.world.spawnEntity(entityarrow);
	}
 
Example 3
public EntityEnderArrow(World worldIn, EntityLivingBase shooter, EntityLivingBase par3EntityLivingBase, float par4, float par5)
{
    super(worldIn);
    this.shootingEntity = shooter;
    this.shooterUUID = shooter.getUniqueID();

    if (shooter instanceof EntityPlayer)
    {
        this.canBePickedUp = 1;

        if (((EntityPlayer)shooter).capabilities.isCreativeMode)
        {
            this.canBePickedUp = 2;
        }
    }

    this.posY = shooter.posY + (double)shooter.getEyeHeight() - 0.10000000149011612D;
    double d0 = par3EntityLivingBase.posX - shooter.posX;
    double d1 = par3EntityLivingBase.getEntityBoundingBox().minY + (double)(par3EntityLivingBase.height / 3.0F) - this.posY;
    double d2 = par3EntityLivingBase.posZ - shooter.posZ;
    double d3 = (double)MathHelper.sqrt(d0 * d0 + d2 * d2);

    if (d3 >= 1.0E-7D)
    {
        float f2 = (float)(Math.atan2(d2, d0) * 180.0D / Math.PI) - 90.0F;
        float f3 = (float)(-(Math.atan2(d1, d3) * 180.0D / Math.PI));
        double d4 = d0 / d3;
        double d5 = d2 / d3;
        this.setLocationAndAngles(shooter.posX + d4, this.posY, shooter.posZ + d5, f2, f3);
        float f4 = (float)d3 * 0.2F;
        this.shoot(d0, d1 + (double)f4, d2, par4, par5);
    }
}
 
Example 4
public static boolean teleportToEntity(EntityLivingBase entity, Entity toEntity) {
  Vec3d vec3 = new Vec3d(entity.posX - toEntity.posX,
      entity.getEntityBoundingBox().minY + entity.height / 2.0F - toEntity.posY + toEntity.getEyeHeight(), entity.posZ - toEntity.posZ);
  vec3 = vec3.normalize();
  double d0 = 16.0D;
  double d1 = entity.posX + (rand.nextDouble() - 0.5D) * 8.0D - vec3.x * d0;
  double d2 = entity.posY + (rand.nextInt(16) - 8) - vec3.y * d0;
  double d3 = entity.posZ + (rand.nextDouble() - 0.5D) * 8.0D - vec3.z * d0;
  return teleportTo(entity, d1, d2, d3, false);
}
 
Example 5
/**
 * 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 6
private void setPathTo(EntityLivingBase target) {
  Vec3d targPos = target.getPositionVector();
  AxisAlignedBB targBB = target.getEntityBoundingBox();
  entityPathEntity = attacker.getNavigator().getPathToPos(new BlockPos(targPos.x, targBB.maxY + 1, targPos.z));    
}
 
Example 7
@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 8
private boolean flyToAttacker(EntityLivingBase targetEnt) {        
  AxisAlignedBB targBB = targetEnt.getEntityBoundingBox();    
  return flyingMob.getFlyingNavigator().tryFlyToPos(targetEnt.posX, targBB.maxY + 0.5, targetEnt.posZ, speedTowardsTarget);
}
 
Example 9
/**
   * 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);
    }
  }