A teenager who used a 3D printer to build a deadly assault gun in his bedroom has been spared jail.