Turn on hitboxes with F3+B and keep a spear anywhere in your hotbar. Aim at a living target. Its outline turns orange when your spear can reach it and red when it is close enough for ordinary melee. You can keep another item selected.
Customize both colors and the line widths in the Spear settings. Enable the optional accurate hitbox overlay to see the extra targeting margin around the original white hitbox. The overlay starts disabled.
Works standalone on Fabric and NeoForge. On Fabric, Combat Hitboxes and Combat Hitboxes+ are optional alternatives that integrate the Spear settings into their own menus. Install Cloth Config for the settings screen and Mod Menu on Fabric.