Example #1
0
  /** Applies a velocity to each of the entities pushing them away from each other. Args: entity */
  public void applyEntityCollision(Entity par1Entity) {
    if (par1Entity.riddenByEntity == this || par1Entity.ridingEntity == this) {
      return;
    }

    double d = par1Entity.posX - posX;
    double d1 = par1Entity.posZ - posZ;
    double d2 = MathHelper.abs_max(d, d1);

    if (d2 >= 0.01D) {
      d2 = MathHelper.sqrt_double(d2);
      d /= d2;
      d1 /= d2;
      double d3 = 1.0D / d2;

      if (d3 > 1.0D) {
        d3 = 1.0D;
      }

      d *= d3;
      d1 *= d3;
      d *= 0.05D;
      d1 *= 0.05D;
      d *= 1.0F - entityCollisionReduction;
      d1 *= 1.0F - entityCollisionReduction;
      addVelocity(-d, 0.0D, -d1);
      par1Entity.addVelocity(d, 0.0D, d1);
    }
  }