Tuning the magnetocaloric effect by optimizing thickness-induced three-dimensional strain states