We present a generator-coordinate method for realistic shell-model Hamiltonians that closely approximates the full shell model calculations of the matrix elements for the neutrinoless double-beta decay of 124Sn, 130Te, and 136Xe. We treat axial quadrupole deformations and also triaxial quadrupole deformations, including the proton-neutron pairing amplitudes as generator coordinates. We validate this method by calculating and comparing spectroscopic quantities with the exact shell model results. A detailed analysis of the 0νββ decay nuclear matrix elements for 124Sn, 130Te, and 136Xe is presented. Our Hamiltonian-based generator-coordinate method produces 0νββ matrix elements much closer to the shell model ones, when compared to the existing energy density functional-based approaches. The remaining overestimation of 0νββ nuclear matrix element suggests that additional correlations may be needed to be taken into account for 124Sn, 130Te, and 136Xe when calculating with the Hamiltonian-based generator-coordinate method.