The Chinese invented technologies involving mechanics , hydraulics , and mathematics applied to horology , metallurgy , astronomy , agriculture , engineering , music theory , craftsmanship , nautics , and warfare .