A lattice Boltzmann method for thermal nonideal fluids